11import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
22import * as vscode from 'vscode'
33import { FilesCollector } from '@/utils/files-collector'
4- import { code_at_cursor_instructions_for_prompt_view } from '@/constants/instructions'
54import { get_last_used_web_configuration_key } from '@/constants/state-keys'
65import { ConfigWebConfigurationFormat } from '@/utils/web-configuration-format-converters'
76import { MODE } from '@/views/prompt/types/main-view-mode'
@@ -35,17 +34,8 @@ export const handle_autofill = async (params: {
3534 return
3635 }
3736
38- const is_in_code_at_cursor_mode =
39- params . prompt_view_provider . web_prompt_type == 'code-at-cursor'
4037 const current_instructions = params . prompt_view_provider . current_instruction
4138
42- const active_editor = vscode . window . activeTextEditor
43-
44- if ( is_in_code_at_cursor_mode && ! active_editor ) {
45- vscode . window . showWarningMessage ( dictionary . warning_message . NO_EDITOR_OPEN )
46- return
47- }
48-
4939 const resolution = await resolve_web_configuration ( {
5040 prompt_view_provider : params . prompt_view_provider ,
5141 web_configuration_name : params . web_configuration_name ,
@@ -69,118 +59,58 @@ export const handle_autofill = async (params: {
6959
7060 let sent = false
7161
72- if ( is_in_code_at_cursor_mode ) {
73- const document = active_editor ! . document
74- const position = active_editor ! . selection . active
62+ const additional_paths : string [ ] = [ ]
7563
76- const text_before_cursor = document . getText (
77- new vscode . Range ( new vscode . Position ( 0 , 0 ) , position )
78- )
79- const text_after_cursor = document . getText (
80- new vscode . Range ( position , document . positionAt ( document . getText ( ) . length ) )
81- )
82- const {
83- instruction : processed_completion_instructions ,
84- skill_definitions
85- } = await replace_symbols ( {
64+ const collected = await FilesCollector . collect_files ( {
65+ workspace_provider : params . prompt_view_provider . workspace_provider ,
66+ open_editors_provider : params . prompt_view_provider . open_editors_provider ,
67+ additional_paths ,
68+ no_context : params . prompt_view_provider . web_prompt_type == 'without-files'
69+ } )
70+ const context_text = collected . other_files + collected . recent_files
71+
72+ const { instruction : processed_instructions , skill_definitions } =
73+ await replace_symbols ( {
8674 instruction : current_instructions ,
8775 extension_context : params . prompt_view_provider . extension_context ,
8876 workspace_provider : params . prompt_view_provider . workspace_provider ,
8977 remove_images : true
9078 } )
9179
92- const collected = await FilesCollector . collect_files ( {
93- workspace_provider : params . prompt_view_provider . workspace_provider ,
94- open_editors_provider : params . prompt_view_provider . open_editors_provider
95- } )
96- const context_text = collected . other_files + collected . recent_files
97-
98- const relative_path = vscode . workspace . asRelativePath ( document . uri )
99-
100- const main_instructions = code_at_cursor_instructions_for_prompt_view ( {
101- file_path : relative_path ,
102- row : position . line ,
103- column : position . character
104- } )
105-
106- const { full_prompt : text } = PromptBuilder . build_prompt ( {
107- context_text,
108- active_file : {
109- filepath : relative_path ,
110- content : `${ text_before_cursor } ${
111- processed_completion_instructions
112- ? `<missing_text>${ processed_completion_instructions } </missing_text>`
113- : '<missing_text>'
114- } ${ text_after_cursor } `
115- } ,
116- skill_definitions,
117- system_instructions : main_instructions
118- } )
119-
120- sent =
121- await params . prompt_view_provider . websocket_server_instance . initialize_chat (
122- {
123- text,
124- web_configuration_name : resolved_web_configuration_name ,
125- raw_instructions : processed_completion_instructions ,
126- invocation_count : params . invocation_count ,
127- inject_apply_response_button : true
128- }
129- )
130- } else {
131- const additional_paths : string [ ] = [ ]
132-
133- const collected = await FilesCollector . collect_files ( {
134- workspace_provider : params . prompt_view_provider . workspace_provider ,
135- open_editors_provider : params . prompt_view_provider . open_editors_provider ,
136- additional_paths,
137- no_context : params . prompt_view_provider . web_prompt_type == 'without-files'
138- } )
139- const context_text = collected . other_files + collected . recent_files
140-
141- const { instruction : processed_instructions , skill_definitions } =
142- await replace_symbols ( {
143- instruction : current_instructions ,
144- extension_context : params . prompt_view_provider . extension_context ,
145- workspace_provider : params . prompt_view_provider . workspace_provider ,
146- remove_images : true
147- } )
148-
149- let formatted_system_instructions = ''
150- const user_instructions = processed_instructions
151- if ( params . prompt_view_provider . web_prompt_type == 'edit-files' ) {
152- const edit_format_instructions = {
153- whole : EDIT_FORMAT_INSTRUCTIONS_WHOLE ,
154- truncated : EDIT_FORMAT_INSTRUCTIONS_TRUNCATED ,
155- 'search-replace' : EDIT_FORMAT_INSTRUCTIONS_SEARCH_REPLACE ,
156- diff : EDIT_FORMAT_INSTRUCTIONS_DIFF
157- } [ params . prompt_view_provider . edit_format ]
158- if ( edit_format_instructions ) {
159- formatted_system_instructions = `# Output formatting\n\n${ edit_format_instructions } `
160- }
80+ let formatted_system_instructions = ''
81+ const user_instructions = processed_instructions
82+ if ( params . prompt_view_provider . web_prompt_type == 'edit-files' ) {
83+ const edit_format_instructions = {
84+ whole : EDIT_FORMAT_INSTRUCTIONS_WHOLE ,
85+ truncated : EDIT_FORMAT_INSTRUCTIONS_TRUNCATED ,
86+ 'search-replace' : EDIT_FORMAT_INSTRUCTIONS_SEARCH_REPLACE ,
87+ diff : EDIT_FORMAT_INSTRUCTIONS_DIFF
88+ } [ params . prompt_view_provider . edit_format ]
89+ if ( edit_format_instructions ) {
90+ formatted_system_instructions = `# Output formatting\n\n${ edit_format_instructions } `
16191 }
92+ }
16293
163- const { full_prompt : text } = PromptBuilder . build_prompt ( {
164- context_text,
165- skill_definitions,
166- system_instructions : formatted_system_instructions ,
167- user_instructions
168- } )
94+ const { full_prompt : text } = PromptBuilder . build_prompt ( {
95+ context_text,
96+ skill_definitions,
97+ system_instructions : formatted_system_instructions ,
98+ user_instructions
99+ } )
169100
170- const prompt_type = params . prompt_view_provider . web_prompt_type
171- const inject_apply_response_button = prompt_type == 'edit-files'
172-
173- sent =
174- await params . prompt_view_provider . websocket_server_instance . initialize_chat (
175- {
176- text,
177- web_configuration_name : resolved_web_configuration_name ,
178- raw_instructions : current_instructions ,
179- invocation_count : params . invocation_count ,
180- inject_apply_response_button
181- }
182- )
183- }
101+ const prompt_type = params . prompt_view_provider . web_prompt_type
102+ const inject_apply_response_button = prompt_type == 'edit-files'
103+
104+ sent =
105+ await params . prompt_view_provider . websocket_server_instance . initialize_chat (
106+ {
107+ text,
108+ web_configuration_name : resolved_web_configuration_name ,
109+ raw_instructions : current_instructions ,
110+ invocation_count : params . invocation_count ,
111+ inject_apply_response_button
112+ }
113+ )
184114
185115 if ( sent ) {
186116 params . prompt_view_provider . send_message ( {
@@ -203,7 +133,6 @@ const show_web_configuration_quick_pick = async (params: {
203133 get_is_web_configuration_disabled : (
204134 web_configuration : ConfigWebConfigurationFormat
205135 ) => boolean
206- is_in_code_at_cursor_mode : boolean
207136 current_instructions : string
208137} ) : Promise < { web_configuration_name : string | undefined } | null > => {
209138 const {
@@ -299,16 +228,8 @@ const resolve_web_configuration = async (params: {
299228 'webConfigurations' ,
300229 [ ]
301230 )
302- const is_in_code_at_cursor_mode =
303- params . prompt_view_provider . web_prompt_type == 'code-at-cursor'
304-
305231 let current_instructions = ''
306- if ( params . prompt_view_provider . web_prompt_type == 'code-at-cursor' ) {
307- current_instructions =
308- params . prompt_view_provider . code_at_cursor_instructions . instructions [
309- params . prompt_view_provider . code_at_cursor_instructions . active_index
310- ] || ''
311- } else if ( params . prompt_view_provider . web_prompt_type == 'ask-about-files' ) {
232+ if ( params . prompt_view_provider . web_prompt_type == 'ask-about-files' ) {
312233 current_instructions =
313234 params . prompt_view_provider . ask_about_context_instructions . instructions [
314235 params . prompt_view_provider . ask_about_context_instructions . active_index
@@ -329,10 +250,7 @@ const resolve_web_configuration = async (params: {
329250 web_configuration : ConfigWebConfigurationFormat
330251 ) =>
331252 ( web_configuration . chatbot &&
332- ( ! params . prompt_view_provider . websocket_server_instance . is_connected_with_browser ( ) ||
333- ( is_in_code_at_cursor_mode &&
334- ( ! params . prompt_view_provider . currently_open_file_path ||
335- ! ! params . prompt_view_provider . current_selection ) ) ) ) ||
253+ ! params . prompt_view_provider . websocket_server_instance . is_connected_with_browser ( ) ) ||
336254 false
337255
338256 if ( params . web_configuration_name !== undefined ) {
@@ -375,7 +293,6 @@ const resolve_web_configuration = async (params: {
375293 prompt_type : params . prompt_view_provider . web_prompt_type ,
376294 prompt_view_provider : params . prompt_view_provider ,
377295 get_is_web_configuration_disabled,
378- is_in_code_at_cursor_mode,
379296 current_instructions
380297 } )
381298
0 commit comments