Skip to content

Commit fcce9f1

Browse files
committed
Simplify prompt handling by retrieving current instructions directly from the provider
- do we always refer to [Fragment] as 'current instructions'? we should - 'copy prompt' should take instructions directly from the provider - on prompt copying, 'web configuration name' is no longer relevant └── apps └── editor └── src └── views └── prompt ├── backend │ ├── message-handlers │ │ ├── handle-autofill.ts │ │ ├── handle-copy-prompt.ts │ │ ├── handle-make-api-call.ts │ │ ├── handle-preview-web-configuration.ts │ │ └── index.ts │ └── prompt-view-provider.ts ├── frontend │ ├── Main │ │ ├── Main.tsx │ │ └── MainView │ │ └── MainView.tsx │ ├── Prompt.tsx │ └── hooks │ └── use-prompt │ └── use-prompt.ts └── types └── messages.ts
1 parent 820a380 commit fcce9f1

7 files changed

Lines changed: 17 additions & 41 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-autofill.ts‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export const handle_autofill = async (params: {
3333
return
3434
}
3535

36-
const current_instructions = params.prompt_view_provider.current_instructions
37-
3836
const resolution = await resolve_web_configuration({
3937
prompt_view_provider: params.prompt_view_provider,
4038
web_configuration_name: params.web_configuration_name,
@@ -67,6 +65,8 @@ export const handle_autofill = async (params: {
6765
})
6866
const context_text = collected.other_files + collected.recent_files
6967

68+
const current_instructions = params.prompt_view_provider.current_instructions
69+
7070
const { instructions: processed_instructions, skill_definitions } =
7171
await replace_symbols({
7272
instructions: current_instructions,
@@ -131,7 +131,6 @@ const show_web_configuration_quick_pick = async (params: {
131131
get_is_web_configuration_disabled: (
132132
web_configuration: ConfigWebConfigurationFormat
133133
) => boolean
134-
current_instructions: string
135134
}): Promise<{ web_configuration_name: string | undefined } | null> => {
136135
const {
137136
web_configurations,
@@ -226,19 +225,6 @@ const resolve_web_configuration = async (params: {
226225
'webConfigurations',
227226
[]
228227
)
229-
let current_instructions = ''
230-
if (params.prompt_view_provider.web_prompt_type == 'ask-about-files') {
231-
current_instructions =
232-
params.prompt_view_provider.ask_about_context_instructions.instructions[
233-
params.prompt_view_provider.ask_about_context_instructions.active_index
234-
] || ''
235-
} else if (params.prompt_view_provider.web_prompt_type == 'edit-files') {
236-
current_instructions =
237-
params.prompt_view_provider.edit_files_instructions.instructions[
238-
params.prompt_view_provider.edit_files_instructions.active_index
239-
] || ''
240-
}
241-
242228
const get_is_web_configuration_disabled = (
243229
web_configuration: ConfigWebConfigurationFormat
244230
) =>
@@ -285,8 +271,7 @@ const resolve_web_configuration = async (params: {
285271
extension_context: params.extension_context,
286272
prompt_type: params.prompt_view_provider.web_prompt_type,
287273
prompt_view_provider: params.prompt_view_provider,
288-
get_is_web_configuration_disabled,
289-
current_instructions
274+
get_is_web_configuration_disabled
290275
})
291276

292277
return resolution ?? { web_configuration_name: undefined }

‎apps/editor/src/views/prompt/backend/message-handlers/handle-copy-prompt.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import { t } from '@/i18n'
1313

1414
export const handle_copy_prompt = async (params: {
1515
prompt_view_provider: PromptViewProvider
16-
instructions: string
17-
web_configuration_name?: string
1816
}): Promise<void> => {
1917
const collected = await FilesCollector.collect_files({
2018
workspace_provider: params.prompt_view_provider.workspace_provider,
2119
open_editors_provider: params.prompt_view_provider.open_editors_provider
2220
})
2321
const context_text = collected.other_files + collected.recent_files
2422

23+
const current_instructions = params.prompt_view_provider.current_instructions
24+
2525
const { instructions: processed_instructions, skill_definitions } =
2626
await replace_symbols({
27-
instructions: params.instructions,
27+
instructions: current_instructions,
2828
extension_context: params.prompt_view_provider.extension_context,
2929
workspace_provider: params.prompt_view_provider.workspace_provider,
3030
remove_images: true

‎apps/editor/src/views/prompt/backend/message-handlers/handle-make-api-call.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,9 @@ export const handle_make_api_call = async (
153153
prompt_view_provider.extension_context
154154
)
155155

156-
let instructions = ''
157-
if (prompt_type == 'edit-files') {
158-
instructions = prompt_view_provider.current_edit_files_instruction
159-
}
156+
const current_instructions = prompt_view_provider.current_instructions
160157

161-
if (!instructions) {
158+
if (!current_instructions) {
162159
prompt_view_provider.send_message({
163160
command: 'SHOW_AUTO_CLOSING_MODAL',
164161
title: t(
@@ -171,7 +168,7 @@ export const handle_make_api_call = async (
171168

172169
const { instructions: processed_instructions, skill_definitions } =
173170
await replace_symbols({
174-
instructions,
171+
instructions: current_instructions,
175172
extension_context: prompt_view_provider.extension_context,
176173
workspace_provider: prompt_view_provider.workspace_provider
177174
})
@@ -279,7 +276,7 @@ export const handle_make_api_call = async (
279276
provider_name: api_configuration.model_provider_name,
280277
model: api_configuration.model,
281278
reasoning_effort: api_configuration.reasoning_effort,
282-
raw_instructions: instructions
279+
raw_instructions: current_instructions
283280
}
284281
)
285282

@@ -293,7 +290,7 @@ export const handle_make_api_call = async (
293290
if (prompt_type == 'edit-files') {
294291
vscode.commands.executeCommand('codeWebChat.applyResponse', {
295292
response: result.response,
296-
raw_instructions: instructions,
293+
raw_instructions: current_instructions,
297294
edit_format,
298295
recent_api_configuration
299296
})

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,7 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
655655
await handle_preview_web_configuration(this, message)
656656
} else if (message.command == 'COPY_PROMPT') {
657657
await handle_copy_prompt({
658-
prompt_view_provider: this,
659-
instructions: message.instructions,
660-
web_configuration_name: message.web_configuration_name
658+
prompt_view_provider: this
661659
})
662660
} else if (message.command == 'REQUEST_EDITOR_STATE') {
663661
handle_request_editor_state(this)

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,9 @@ export const Main: React.FC<Props> = (props) => {
226226
update_chat_history(instructions)
227227
}
228228

229-
const handle_copy_to_clipboard = (web_configuration_name?: string) => {
229+
const handle_copy = () => {
230230
post_message(props.vscode, {
231-
command: 'COPY_PROMPT',
232-
instructions,
233-
web_configuration_name
231+
command: 'COPY_PROMPT'
234232
})
235233

236234
if (instructions.trim()) {
@@ -469,7 +467,7 @@ export const Main: React.FC<Props> = (props) => {
469467
scroll_reset_key={props.scroll_reset_key}
470468
on_show_home={props.on_show_home}
471469
initialize_chats={handle_initialize_chats}
472-
copy_to_clipboard={handle_copy_to_clipboard}
470+
on_copy={handle_copy}
473471
api_configurations={api_configurations}
474472
on_api_configuration_click={handle_api_configuration_click}
475473
on_api_configurations_reorder={handle_api_configurations_reorder}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type Props = {
3232
web_configuration_name?: string
3333
show_quick_pick?: boolean
3434
}) => void
35-
copy_to_clipboard: (web_configuration_name?: string) => void
35+
on_copy: () => void
3636
on_show_home: () => void
3737
on_create_web_configuration: (params?: {
3838
insertion_index?: number
@@ -311,7 +311,7 @@ export const MainView: React.FC<Props> = (props) => {
311311
on_change={handle_input_change}
312312
on_submit={handle_submit}
313313
on_submit_with_control={handle_submit_with_control}
314-
on_copy={props.copy_to_clipboard}
314+
on_copy={props.on_copy}
315315
on_at_sign_click={props.on_at_sign_click}
316316
on_hash_sign_click={props.on_hash_sign_click}
317317
on_slash_click={props.on_slash_click}

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ export interface AutofillMessage extends BaseMessage {
120120

121121
export interface CopyPromptMessage extends BaseMessage {
122122
command: 'COPY_PROMPT'
123-
instructions: string
124-
web_configuration_name?: string
125123
}
126124

127125
export interface RequestEditorStateMessage extends BaseMessage {

0 commit comments

Comments
 (0)