Skip to content

Commit 3d86fa5

Browse files
committed
Refactor to accept a single parameters object
1 parent 033bac5 commit 3d86fa5

2 files changed

Lines changed: 32 additions & 32 deletions

File tree

packages/vscode/src/view/backend/message-handlers/handle-copy-prompt.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ import { chat_code_completion_instructions } from '@/constants/instructions'
88
import { apply_preset_affixes_to_instruction } from '@/utils/apply-preset-affixes'
99
import { HOME_VIEW_TYPES } from '@/view/types/home-view-type'
1010

11-
export const handle_copy_prompt = async (
12-
provider: ViewProvider,
13-
instructions: string,
11+
export const handle_copy_prompt = async (params: {
12+
provider: ViewProvider
13+
instructions: string
1414
preset_name?: string
15-
): Promise<void> => {
15+
}): Promise<void> => {
1616
const files_collector = new FilesCollector(
17-
provider.workspace_provider,
18-
provider.open_editors_provider,
19-
provider.websites_provider
17+
params.provider.workspace_provider,
18+
params.provider.open_editors_provider,
19+
params.provider.websites_provider
2020
)
2121

2222
const active_editor = vscode.window.activeTextEditor
2323

24-
let final_instruction = instructions
25-
if (preset_name !== undefined) {
24+
let final_instruction = params.instructions
25+
if (params.preset_name !== undefined) {
2626
final_instruction = apply_preset_affixes_to_instruction(
27-
instructions,
28-
preset_name,
29-
provider.get_presets_config_key()
27+
params.instructions,
28+
params.preset_name,
29+
params.provider.get_presets_config_key()
3030
)
3131
}
3232

3333
const is_in_code_completions_mode =
34-
(provider.home_view_type == HOME_VIEW_TYPES.WEB &&
35-
provider.web_mode == 'code-completions') ||
36-
(provider.home_view_type == HOME_VIEW_TYPES.API &&
37-
provider.api_mode == 'code-completions')
34+
(params.provider.home_view_type == HOME_VIEW_TYPES.WEB &&
35+
params.provider.web_mode == 'code-completions') ||
36+
(params.provider.home_view_type == HOME_VIEW_TYPES.API &&
37+
params.provider.api_mode == 'code-completions')
3838

3939
if (is_in_code_completions_mode && active_editor) {
4040
const document = active_editor.document
@@ -71,7 +71,7 @@ export const handle_copy_prompt = async (
7171

7272
const context_text = await files_collector.collect_files({
7373
additional_paths,
74-
no_context: provider.web_mode == 'no-context'
74+
no_context: params.provider.web_mode == 'no-context'
7575
})
7676

7777
const instructions = replace_selection_placeholder(final_instruction)
@@ -86,22 +86,22 @@ export const handle_copy_prompt = async (
8686
if (instructions.includes('@SavedContext:')) {
8787
pre_context_instructions = await replace_saved_context_placeholder(
8888
pre_context_instructions,
89-
provider.context,
90-
provider.workspace_provider
89+
params.provider.context,
90+
params.provider.workspace_provider
9191
)
9292
post_context_instructions = await replace_saved_context_placeholder(
9393
post_context_instructions,
94-
provider.context,
95-
provider.workspace_provider,
94+
params.provider.context,
95+
params.provider.workspace_provider,
9696
true
9797
)
9898
}
9999

100-
if (provider.web_mode == 'edit-context') {
100+
if (params.provider.web_mode == 'edit-context') {
101101
const edit_format =
102-
provider.home_view_type == HOME_VIEW_TYPES.WEB
103-
? provider.chat_edit_format
104-
: provider.api_edit_format
102+
params.provider.home_view_type == HOME_VIEW_TYPES.WEB
103+
? params.provider.chat_edit_format
104+
: params.provider.api_edit_format
105105
const all_instructions = vscode.workspace
106106
.getConfiguration('codeWebChat')
107107
.get<{ [key: string]: string }>('editFormatInstructions')
@@ -126,7 +126,7 @@ export const handle_copy_prompt = async (
126126

127127
vscode.window.showInformationMessage(
128128
`Prompt${
129-
preset_name ? ` with preset "${preset_name}"` : ''
129+
params.preset_name ? ` with preset "${params.preset_name}"` : ''
130130
} copied to clipboard!`
131131
)
132132
}

packages/vscode/src/view/backend/view-provider.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,16 @@ export class ViewProvider implements vscode.WebviewViewProvider {
273273
} else if (message.command == 'SEND_PROMPT') {
274274
await handle_send_prompt({
275275
provider: this,
276-
preset_names: message.preset_names,
276+
preset_names: message.preset_names
277277
})
278278
} else if (message.command == 'PREVIEW_PRESET') {
279279
await handle_preview_preset(this, message)
280280
} else if (message.command == 'COPY_PROMPT') {
281-
await handle_copy_prompt(
282-
this,
283-
message.instructions,
284-
message.preset_name
285-
)
281+
await handle_copy_prompt({
282+
provider: this,
283+
instructions: message.instructions,
284+
preset_name: message.preset_name
285+
})
286286
} else if (message.command == 'REQUEST_EDITOR_STATE') {
287287
handle_request_editor_state(this)
288288
} else if (message.command == 'REQUEST_EDITOR_SELECTION_STATE') {

0 commit comments

Comments
 (0)