Skip to content

Commit 401fc4b

Browse files
committed
Add empty context validation for CLI edit-files mode and rename error symbols to warning symbols
- sometimes symbols are red - they should be yellow instead - use warning modifiers [Pasted text], not errors - require attaching files in cli/'edit' prompt type - require context in cli/edit files ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ ├── backend │ │ └── message-handlers │ │ ├── handle-autofill.ts │ │ ├── handle-invoke-agentic-cli.ts │ │ └── utils │ │ └── build-cli-prompt.ts │ └── frontend │ └── Main │ └── MainView │ └── MainView.tsx └── packages └── ui └── src ├── components │ └── editor │ └── common │ └── prompts │ ├── PromptField │ │ ├── PromptField.module.scss │ │ ├── PromptField.stories.tsx │ │ ├── PromptField.tsx │ │ ├── hooks │ │ │ ├── use-drag-drop.ts │ │ │ ├── use-dropdown.ts │ │ │ ├── use-ghost-text.ts │ │ │ ├── use-handlers │ │ │ │ ├── handle-copy.ts │ │ │ │ ├── handle-cut.ts │ │ │ │ ├── handle-input-change.ts │ │ │ │ ├── handle-input-click.ts │ │ │ │ ├── handle-key-down.ts │ │ │ │ ├── handle-paste.ts │ │ │ │ ├── handle-submit.ts │ │ │ │ ├── index.ts │ │ │ │ ├── types.ts │ │ │ │ ├── use-handlers.ts │ │ │ │ └── utils.ts │ │ │ └── use-keyboard-shortcuts.ts │ │ └── index.ts │ ├── Template │ │ ├── Template.module.scss │ │ ├── Template.tsx │ │ └── index.ts │ └── shared │ └── symbols │ ├── caret.ts │ ├── get-highlighted-text.tsx │ ├── index.ts │ ├── position-mapping.ts │ ├── prompt-symbols.module.scss │ ├── reconstruct-raw-value.ts │ └── use-symbol-deletion.ts └── styles └── foundation └── _colors.scss
1 parent 4b03d5b commit 401fc4b

4 files changed

Lines changed: 32 additions & 22 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-invoke-agentic-cli.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ export const handle_invoke_agentic_cli = async (
2222
return
2323
}
2424

25+
if (
26+
prompt_view_provider.cli_prompt_type == 'edit-files' &&
27+
!prompt_view_provider.workspace_provider.get_checked_files().length
28+
) {
29+
vscode.window.showInformationMessage(
30+
t('views.common.handlers.common.context-cannot-be-empty')
31+
)
32+
return
33+
}
34+
2535
const prompt_type = prompt_view_provider.cli_prompt_type
2636
const last_used_key = get_last_used_cli_configuration_key(prompt_type)
2737
const last_used_agent_config_name =
@@ -76,7 +86,7 @@ export const handle_invoke_agentic_cli = async (
7686
if (agent_output && prompt_view_provider.cli_prompt_type == 'edit-files') {
7787
vscode.commands.executeCommand('codeWebChat.applyResponse', {
7888
response: agent_output,
79-
raw_instructions: current_instructions,
89+
raw_instructions: current_instructions
8090
})
8191
}
8292
}

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ export const MainView: React.FC<Props> = (props) => {
181181
(props.target == 'WEB' && props.web_prompt_type == 'edit-files') ||
182182
(props.target == 'API' && props.api_prompt_type == 'edit-files')
183183

184-
const is_context_empty =
185-
show_edit_format_selector && props.selected_files.length == 0
184+
const is_required_context_empty =
185+
((props.target == 'WEB' && props.web_prompt_type == 'edit-files') ||
186+
(props.target == 'API' && props.api_prompt_type == 'edit-files') ||
187+
(props.target == 'CLI' && props.cli_prompt_type == 'edit-files')) &&
188+
props.selected_files.length == 0
186189

187190
const handle_input_change = (value: string) => {
188191
props.set_instructions(value)
@@ -436,7 +439,7 @@ export const MainView: React.FC<Props> = (props) => {
436439
props.target == 'WEB' &&
437440
(!props.is_connected || !props.web_configurations.length)
438441
}
439-
is_action_disabled={is_context_empty}
442+
is_action_disabled={is_required_context_empty}
440443
value={props.instructions}
441444
chat_history={props.chat_history}
442445
on_change={handle_input_change}
@@ -476,7 +479,7 @@ export const MainView: React.FC<Props> = (props) => {
476479
target={props.target}
477480
on_target_change={(target) => props.on_target_change(target)}
478481
active_border_color={
479-
is_context_empty
482+
is_required_context_empty
480483
? 'yellow'
481484
: props.target == 'WEB'
482485
? props.web_prompt_type == 'edit-files'
@@ -540,11 +543,10 @@ export const MainView: React.FC<Props> = (props) => {
540543
attach_selected_files: t('prompt-field.attach-selected-files'),
541544
more: t('prompt-field.more')
542545
}}
543-
544546
/>
545547
</div>
546548

547-
{is_context_empty ? (
549+
{is_required_context_empty ? (
548550
<UiStatusBar
549551
placement="bottom"
550552
theme="warning"
@@ -752,9 +754,7 @@ export const MainView: React.FC<Props> = (props) => {
752754
on_edit={(id) => props.on_edit_cli_configuration(id)}
753755
on_reorder={(reordered) => {
754756
const new_cli_configurations = reordered.map((c) => {
755-
return props.cli_configurations.find(
756-
(p) => p.name == c.id
757-
)!
757+
return props.cli_configurations.find((p) => p.name == c.id)!
758758
})
759759
props.on_cli_configurations_reorder(new_cli_configurations)
760760
}}

‎packages/ui/src/components/editor/common/prompts/shared/symbols/get-highlighted-text.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ export const get_highlighted_text = (params: {
9292
const line_count = Math.max(1, end_line - start_line + 1)
9393
const lines_text = line_count == 1 ? 'line' : 'lines'
9494

95-
const is_error = !params.context_file_paths.includes(path)
95+
const is_warning = !params.context_file_paths.includes(path)
9696

9797
return `<span class="${cn(
9898
styles['symbol'],
9999
styles['symbol--pasted-lines'],
100-
{ [styles['symbol--error']]: is_error }
100+
{ [styles['symbol--warning']]: is_warning }
101101
)}" data-type="pasted-lines-symbol"${
102-
is_error ? ' title="File with selection is not selected"' : ''
102+
is_warning ? ' title="File with selection is not selected"' : ''
103103
} data-path="${escape_html(path)}" data-start-line="${start_line}" data-start-col="${start_col}" data-end-line="${end_line}" data-end-col="${end_col}"><span class="${
104104
styles['symbol__icon']
105105
}" data-role="symbol-icon"></span><span class="${
@@ -191,11 +191,11 @@ export const get_highlighted_text = (params: {
191191
const image_match = part.match(/^#Image\(([a-fA-F0-9]+)\)$/)
192192
if (part && image_match) {
193193
const hash = image_match[1]
194-
const is_error = params.is_web_target
194+
const is_warning = params.is_web_target
195195
return `<span class="${cn(styles['symbol'], styles['symbol--image'], {
196-
[styles['symbol--error']]: is_error
196+
[styles['symbol--warning']]: is_warning
197197
})}" data-type="image-symbol" data-hash="${hash}"${
198-
is_error
198+
is_warning
199199
? ' title="The prompt autofill feature can\'t handle images.\nUpload in chatbot or use API with a multimodal model."'
200200
: ''
201201
}><span class="${

‎packages/ui/src/components/editor/common/prompts/shared/symbols/prompt-symbols.module.scss‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,26 +188,26 @@
188188
}
189189
}
190190

191-
&--error {
191+
&--warning {
192192
background-color: color-mix(
193193
in srgb,
194-
var(--vscode-charts-red) 30%,
194+
var(--vscode-charts-yellow) 30%,
195195
transparent
196196
);
197197
}
198198

199-
&--error &__icon:hover {
199+
&--warning &__icon:hover {
200200
background-color: color-mix(
201201
in srgb,
202-
var(--vscode-charts-red) 40%,
202+
var(--vscode-charts-yellow) 40%,
203203
transparent
204204
);
205205
}
206206

207-
&--error &__text:hover {
207+
&--warning &__text:hover {
208208
background-color: color-mix(
209209
in srgb,
210-
var(--vscode-charts-red) 40%,
210+
var(--vscode-charts-yellow) 40%,
211211
transparent
212212
);
213213
}

0 commit comments

Comments
 (0)