11import * as vscode from 'vscode'
22import axios from 'axios'
3- import he from 'he'
43import { make_api_request } from '@/utils/make-api-request'
5- import { code_completion_instructions } from '@/constants/instructions'
4+ import { chat_code_completion_instructions } from '@/constants/instructions'
65import { FilesCollector } from '@/utils/files-collector'
76import {
87 ModelProvidersManager ,
@@ -315,6 +314,13 @@ const perform_code_completion = async (params: {
315314 new vscode . Range ( position , document . positionAt ( document . getText ( ) . length ) )
316315 )
317316
317+ const relative_path = vscode . workspace . asRelativePath ( document . uri )
318+ const main_instructions = chat_code_completion_instructions (
319+ relative_path ,
320+ position . line ,
321+ position . character
322+ )
323+
318324 const files_collector = new FilesCollector (
319325 params . file_tree_provider ,
320326 params . open_editors_provider
@@ -325,17 +331,15 @@ const perform_code_completion = async (params: {
325331 } )
326332
327333 const payload = {
328- before : `<files>\n${ context_text } <file path="${ vscode . workspace . asRelativePath (
329- document . uri
330- ) } ">\n<![CDATA[\n${ text_before_cursor } `,
334+ before : `<files>\n${ context_text } <file path="${ relative_path } ">\n<![CDATA[\n${ text_before_cursor } ` ,
331335 after : `${ text_after_cursor } \n]]>\n</file>\n</files>`
332336 }
333337
334- const content = `${ code_completion_instructions } \n${ payload . before } ${
338+ const content = `${ main_instructions } \n${ payload . before } ${
335339 completion_instructions
336340 ? `<missing_text>${ completion_instructions } </missing_text>`
337341 : '<missing_text>'
338- } ${ payload . after } \n${ code_completion_instructions } `
342+ } ${ payload . after } \n${ main_instructions } `
339343
340344 const messages = [
341345 {
@@ -393,22 +397,7 @@ const perform_code_completion = async (params: {
393397 } )
394398
395399 if ( result ) {
396- const match = result . response . match (
397- / < r e p l a c e m e n t > ( [ \s \S ] * ?) < \/ r e p l a c e m e n t > / i
398- )
399- if ( match && match [ 1 ] ) {
400- let decoded_completion = he . decode ( match [ 1 ] . trim ( ) )
401- decoded_completion = decoded_completion
402- . replace ( / < ! \[ C D A T A \[ / g, '' )
403- . replace ( / \] \] > / g, '' )
404- . trim ( )
405-
406- const new_content =
407- text_before_cursor + decoded_completion + text_after_cursor
408-
409- const relative_path = vscode . workspace . asRelativePath ( document . uri )
410- response_for_apply = `\`\`\`\n// ${ relative_path } \n${ new_content } \n\`\`\``
411- }
400+ response_for_apply = result . response
412401 }
413402 } catch ( err : any ) {
414403 if ( axios . isCancel ( err ) ) {
0 commit comments