1- import { PanelProvider } from '@/views/panel/backend/panel-provider'
2- import * as vscode from 'vscode'
3- import { FilesCollector } from '@/utils/files-collector'
4- import { replace_selection_placeholder } from '@/views/panel/backend/utils/replace-selection-placeholder'
1+ import { PanelProvider } from '@/views/panel/backend/panel-provider' ;
2+ import * as vscode from 'vscode' ;
3+ import { FilesCollector } from '@/utils/files-collector' ;
4+ import { replace_selection_placeholder } from '@/views/panel/backend/utils/replace-selection-placeholder' ;
55import {
66 replace_changes_placeholder ,
77 replace_commit_placeholder
8- } from '@/views/panel/backend/utils/replace-git-placeholders'
9- import { replace_saved_context_placeholder } from '@/utils/replace-saved-context-placeholder'
10- import { code_completion_instructions_for_panel } from '@/constants/instructions'
11- import { apply_preset_affixes_to_instruction } from '@/utils/apply-preset-affixes'
12- import { MAIN_VIEW_TYPES } from '@/views/panel/types/home-view-type'
13- import { dictionary } from '@shared/constants/dictionary'
8+ } from '@/views/panel/backend/utils/replace-git-placeholders' ;
9+ import { replace_saved_context_placeholder } from '@/utils/replace-saved-context-placeholder' ;
10+ import { code_completion_instructions_for_panel } from '@/constants/instructions' ;
11+ import { apply_preset_affixes_to_instruction } from '@/utils/apply-preset-affixes' ;
12+ import { MAIN_VIEW_TYPES } from '@/views/panel/types/home-view-type' ;
13+ import { dictionary } from '@shared/constants/dictionary' ;
1414
1515export const handle_copy_prompt = async ( params : {
16- panel_provider : PanelProvider
17- instructions : string
18- preset_name ?: string
16+ panel_provider : PanelProvider ;
17+ instructions : string ;
18+ preset_name ?: string ;
1919} ) : Promise < void > => {
2020 const files_collector = new FilesCollector (
2121 params . panel_provider . workspace_provider ,
2222 params . panel_provider . open_editors_provider ,
2323 params . panel_provider . websites_provider
24- )
24+ ) ;
2525
26- const active_editor = vscode . window . activeTextEditor
26+ const active_editor = vscode . window . activeTextEditor ;
2727
28- let final_instruction = params . instructions
28+ let final_instruction = params . instructions ;
2929 if ( params . preset_name !== undefined ) {
3030 final_instruction = apply_preset_affixes_to_instruction ( {
3131 instruction : params . instructions ,
3232 preset_name : params . preset_name ,
3333 presets_config_key : params . panel_provider . get_presets_config_key ( )
34- } )
34+ } ) ;
3535 }
3636
3737 const is_in_code_completions_mode =
3838 ( params . panel_provider . main_view_type == MAIN_VIEW_TYPES . WEB &&
3939 params . panel_provider . web_mode == 'code-completions' ) ||
4040 ( params . panel_provider . main_view_type == MAIN_VIEW_TYPES . API &&
41- params . panel_provider . api_mode == 'code-completions' )
41+ params . panel_provider . api_mode == 'code-completions' ) ;
4242
4343 if (
4444 is_in_code_completions_mode &&
@@ -48,118 +48,120 @@ export const handle_copy_prompt = async (params: {
4848 vscode . window . showWarningMessage (
4949 dictionary . warning_message
5050 . CANNOT_COPY_PROMPT_IN_CODE_COMPLETION_WITH_SELECTION
51- )
52- return
51+ ) ;
52+ return ;
5353 }
5454
5555 if ( is_in_code_completions_mode && active_editor ) {
56- const document = active_editor . document
57- const position = active_editor . selection . active
58- const active_path = document . uri . fsPath
56+ const document = active_editor . document ;
57+ const position = active_editor . selection . active ;
58+ const active_path = document . uri . fsPath ;
5959
6060 const text_before_cursor = document . getText (
6161 new vscode . Range ( new vscode . Position ( 0 , 0 ) , position )
62- )
62+ ) ;
6363 const text_after_cursor = document . getText (
6464 new vscode . Range ( position , document . positionAt ( document . getText ( ) . length ) )
65- )
65+ ) ;
6666
6767 const context_text = await files_collector . collect_files ( {
6868 exclude_path : active_path
69- } )
69+ } ) ;
7070
71- const workspace_folder = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath
72- const relative_path = active_path . replace ( workspace_folder + '/' , '' )
71+ const workspace_folder = vscode . workspace . workspaceFolders ?. [ 0 ] . uri . fsPath ;
72+ const relative_path = active_path . replace ( workspace_folder + '/' , '' ) ;
7373
7474 const instructions = `${ code_completion_instructions_for_panel (
7575 relative_path ,
7676 position . line ,
7777 position . character
78- ) } ${ final_instruction ? ` Follow instructions: ${ final_instruction } ` : '' } `
78+ ) } ${ final_instruction ? ` Follow instructions: ${ final_instruction } ` : '' } `;
7979
80- const text = `${ instructions } \n<files>\n${ context_text } <file path="${ relative_path } ">\n<![CDATA[\n${ text_before_cursor } <missing_text>${ text_after_cursor } \n]]>\n</file>\n</files>\n${ instructions } `
80+ const text = `${ instructions } \n<files>\n${ context_text } <file path="${ relative_path } ">\n<![CDATA[\n${ text_before_cursor } <missing_text>${ text_after_cursor } \n]]>\n</file>\n</files>\n${ instructions } ` ;
8181
82- vscode . env . clipboard . writeText ( text . trim ( ) )
82+ vscode . env . clipboard . writeText ( text . trim ( ) ) ;
8383 } else if ( ! is_in_code_completions_mode ) {
8484 const context_text = await files_collector . collect_files ( {
8585 no_context : params . panel_provider . web_mode == 'no-context'
86- } )
86+ } ) ;
8787
8888 if ( params . panel_provider . web_mode == 'edit-context' && ! context_text ) {
8989 vscode . window . showWarningMessage (
9090 dictionary . warning_message
9191 . CANNOT_COPY_PROMPT_IN_EDIT_CONTEXT_WITHOUT_CONTEXT
92- )
93- return
92+ ) ;
93+ return ;
9494 }
9595
96- const instructions = replace_selection_placeholder ( final_instruction )
96+ const instructions = replace_selection_placeholder ( final_instruction ) ;
9797
98- let pre_context_instructions = instructions
99- let post_context_instructions = instructions
98+ let pre_context_instructions = instructions ;
99+ let post_context_instructions = instructions ;
100100
101101 if ( instructions . includes ( '#Changes:' ) ) {
102102 pre_context_instructions = await replace_changes_placeholder ( {
103- instruction : pre_context_instructions
104- } )
103+ instruction : pre_context_instructions ,
104+ workspace_provider : params . panel_provider . workspace_provider
105+ } ) ;
105106 post_context_instructions = await replace_changes_placeholder ( {
106107 instruction : post_context_instructions ,
107- after_context : true
108- } )
108+ after_context : true ,
109+ workspace_provider : params . panel_provider . workspace_provider
110+ } ) ;
109111 }
110112
111113 if ( instructions . includes ( '#Commit:' ) ) {
112114 pre_context_instructions = await replace_commit_placeholder ( {
113115 instruction : pre_context_instructions
114- } )
116+ } ) ;
115117 post_context_instructions = await replace_commit_placeholder ( {
116118 instruction : post_context_instructions ,
117119 after_context : true
118- } )
120+ } ) ;
119121 }
120122
121123 if ( instructions . includes ( '#SavedContext:' ) ) {
122124 pre_context_instructions = await replace_saved_context_placeholder ( {
123125 instruction : pre_context_instructions ,
124126 context : params . panel_provider . context ,
125127 workspace_provider : params . panel_provider . workspace_provider
126- } )
128+ } ) ;
127129 post_context_instructions = await replace_saved_context_placeholder ( {
128130 instruction : post_context_instructions ,
129131 context : params . panel_provider . context ,
130132 workspace_provider : params . panel_provider . workspace_provider ,
131133 just_opening_tag : true
132- } )
134+ } ) ;
133135 }
134136
135137 if ( params . panel_provider . web_mode == 'edit-context' ) {
136138 const edit_format =
137139 params . panel_provider . main_view_type == MAIN_VIEW_TYPES . WEB
138140 ? params . panel_provider . chat_edit_format
139- : params . panel_provider . api_edit_format
141+ : params . panel_provider . api_edit_format ;
140142 const all_instructions = vscode . workspace
141143 . getConfiguration ( 'codeWebChat' )
142- . get < { [ key : string ] : string } > ( 'editFormatInstructions' )
143- const edit_format_instructions = all_instructions ?. [ edit_format ]
144+ . get < { [ key : string ] : string } > ( 'editFormatInstructions' ) ;
145+ const edit_format_instructions = all_instructions ?. [ edit_format ] ;
144146
145147 if ( edit_format_instructions ) {
146- const system_instructions = `<system>\n${ edit_format_instructions } \n</system>`
147- pre_context_instructions += `\n${ system_instructions } `
148- post_context_instructions += `\n${ system_instructions } `
148+ const system_instructions = `<system>\n${ edit_format_instructions } \n</system>` ;
149+ pre_context_instructions += `\n${ system_instructions } ` ;
150+ post_context_instructions += `\n${ system_instructions } ` ;
149151 }
150152 }
151153
152154 const text = context_text
153155 ? `${ pre_context_instructions } \n<files>\n${ context_text } </files>\n${ post_context_instructions } `
154- : pre_context_instructions
155- vscode . env . clipboard . writeText ( text . trim ( ) )
156+ : pre_context_instructions ;
157+ vscode . env . clipboard . writeText ( text . trim ( ) ) ;
156158 } else {
157159 vscode . window . showWarningMessage (
158160 dictionary . warning_message
159161 . CANNOT_COPY_PROMPT_IN_CODE_COMPLETION_WITHOUT_EDITOR
160- )
161- return
162+ ) ;
163+ return ;
162164 }
163165
164- vscode . window . showInformationMessage ( 'Prompt copied to clipboard!' )
165- }
166+ vscode . window . showInformationMessage ( 'Prompt copied to clipboard!' ) ;
167+ } ;
0 commit comments