@@ -18,6 +18,13 @@ import { CodeCompletionMessage } from '@/views/panel/types/messages'
1818import { apply_reasoning_effort } from '@/utils/apply-reasoning-effort'
1919import { dictionary } from '@shared/constants/dictionary'
2020import { randomUUID } from 'crypto'
21+ import { replace_selection_placeholder } from '../utils/replace-selection-symbol'
22+ import {
23+ replace_changes_symbol ,
24+ replace_commit_symbol ,
25+ replace_context_at_commit_symbol
26+ } from '../utils/replace-git-symbols'
27+ import { replace_saved_context_placeholder } from '@/utils/replace-saved-context-placeholder'
2128
2229const get_code_completion_config = async (
2330 api_providers_manager : ModelProvidersManager ,
@@ -262,7 +269,7 @@ export const handle_code_completion = async (
262269 const api_providers_manager = new ModelProvidersManager (
263270 panel_provider . context
264271 )
265- const completion_instructions = panel_provider . code_completion_instructions
272+ const completion_instructions = panel_provider . code_at_cursor_instructions
266273
267274 const config_result = await get_code_completion_config (
268275 api_providers_manager ,
@@ -344,6 +351,43 @@ export const handle_code_completion = async (
344351 position . character
345352 )
346353
354+ let processed_completion_instructions = completion_instructions
355+
356+ if ( processed_completion_instructions . includes ( '#Selection' ) ) {
357+ processed_completion_instructions = replace_selection_placeholder (
358+ processed_completion_instructions
359+ )
360+ }
361+
362+ if ( processed_completion_instructions . includes ( '#Changes:' ) ) {
363+ processed_completion_instructions = await replace_changes_symbol ( {
364+ instruction : processed_completion_instructions
365+ } )
366+ }
367+
368+ if ( processed_completion_instructions . includes ( '#Commit:' ) ) {
369+ processed_completion_instructions = await replace_commit_symbol ( {
370+ instruction : processed_completion_instructions
371+ } )
372+ }
373+
374+ if ( processed_completion_instructions . includes ( '#ContextAtCommit:' ) ) {
375+ processed_completion_instructions =
376+ await replace_context_at_commit_symbol ( {
377+ instruction : processed_completion_instructions ,
378+ workspace_provider : panel_provider . workspace_provider
379+ } )
380+ }
381+
382+ if ( processed_completion_instructions . includes ( '#SavedContext:' ) ) {
383+ processed_completion_instructions =
384+ await replace_saved_context_placeholder ( {
385+ instruction : processed_completion_instructions ,
386+ context : panel_provider . context ,
387+ workspace_provider : panel_provider . workspace_provider
388+ } )
389+ }
390+
347391 const files_collector = new FilesCollector (
348392 panel_provider . workspace_provider ,
349393 panel_provider . open_editors_provider
@@ -359,8 +403,8 @@ export const handle_code_completion = async (
359403 }
360404
361405 const content = `${ main_instructions } \n${ payload . before } ${
362- completion_instructions
363- ? `<missing_text>${ completion_instructions } </missing_text>`
406+ processed_completion_instructions
407+ ? `<missing_text>${ processed_completion_instructions } </missing_text>`
364408 : '<missing_text>'
365409 } ${ payload . after } \n${ main_instructions } `
366410
@@ -405,7 +449,7 @@ export const handle_code_completion = async (
405449 'codeWebChat.applyChatResponse' ,
406450 {
407451 response : result . response ,
408- raw_instructions : completion_instructions ,
452+ raw_instructions : processed_completion_instructions ,
409453 original_editor_state : {
410454 file_path : document . uri . fsPath ,
411455 position : {
0 commit comments