File tree Expand file tree Collapse file tree
utils/replace-selection-placeholder
view/backend/message-handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,5 +20,5 @@ export const replace_selection_placeholder = (instruction: string): string => {
2020
2121 const replacement_text = `\n\`${ current_file_path } \`\n\`\`\`\n${ selected_text } \n\`\`\`\n`
2222
23- return instruction . replace ( / @ s e l e c t i o n / g, replacement_text )
23+ return instruction . replace ( / \s * @ s e l e c t i o n \s * / g, replacement_text )
2424}
Original file line number Diff line number Diff line change @@ -71,13 +71,27 @@ export const handle_send_prompt = async (
7171 } else if ( ! provider . is_code_completions_mode ) {
7272 if ( ! provider . instructions ) return
7373
74+ const editor = vscode . window . activeTextEditor
75+ const document = editor ?. document
76+ const current_file_path = document
77+ ? vscode . workspace . asRelativePath ( document . uri )
78+ : ''
79+
80+ let base_instructions = provider . instructions
81+
82+ if ( editor && ! editor . selection . isEmpty ) {
83+ if ( base_instructions . includes ( '@selection' ) ) {
84+ base_instructions = replace_selection_placeholder ( base_instructions )
85+ } else {
86+ const selected_text = editor . document . getText ( editor . selection )
87+ base_instructions = `\`${ current_file_path } \`\n\`\`\`\n${ selected_text } \n\`\`\`\n${ base_instructions } `
88+ }
89+ }
90+
7491 const context_text = await files_collector . collect_files ( {
7592 active_path
7693 } )
7794
78- let base_instructions = provider . instructions
79- base_instructions = replace_selection_placeholder ( base_instructions )
80-
8195 const config = vscode . workspace . getConfiguration ( 'codeWebChat' )
8296 const edit_format_instructions = config . get < string > (
8397 `editFormatInstructions${
You can’t perform that action at this time.
0 commit comments