diff --git a/core/autocomplete/templating/AutocompleteTemplate.ts b/core/autocomplete/templating/AutocompleteTemplate.ts index 8f7bbd66d..92dbf76fa 100644 --- a/core/autocomplete/templating/AutocompleteTemplate.ts +++ b/core/autocomplete/templating/AutocompleteTemplate.ts @@ -21,16 +21,16 @@ export interface AutocompleteTemplate { workspaceUris: string[], ) => [string, string]; template: - | string - | (( - prefix: string, - suffix: string, - filepath: string, - reponame: string, - language: string, - snippets: AutocompleteSnippet[], - workspaceUris: string[], - ) => string); + | string + | (( + prefix: string, + suffix: string, + filepath: string, + reponame: string, + language: string, + snippets: AutocompleteSnippet[], + workspaceUris: string[], + ) => string); completionOptions?: Partial; } @@ -87,14 +87,16 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = { ): [string, string] => { if (snippets.length === 0) { if (suffix.trim().length === 0 && prefix.trim().length === 0) { - return [ - `+++++ ${getLastNUriRelativePathParts(workspaceUris, filepath, 2)}\n${prefix}`, - suffix, - ]; + return [`${getLastNUriRelativePathParts(workspaceUris, filepath, 2)}\n\n[PREFIX]\n${prefix}`, suffix]; } return [prefix, suffix]; } + //snippets = snippets.filter((snippet) => "filepath" in snippet); + + // reverse the snippets so that the most recent snippet is last + snippets = [...snippets].reverse(); + const relativePaths = getShortestUniqueRelativeUriPaths( [ ...snippets.map((snippet) => @@ -111,19 +113,17 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = { return snippet.content; } - return `+++++ ${relativePaths[i].uri} \n${snippet.content}`; + return `// ${relativePaths[i].uri} \n${snippet.content}`; }) .join("\n\n"); return [ - `${otherFiles}\n\n+++++ ${ - relativePaths[relativePaths.length - 1].uri - }\n${prefix}`, - suffix, + `${otherFiles}[PREFIX]${prefix}`, + `${suffix}`, ]; }, template: (prefix: string, suffix: string): string => { - return `[SUFFIX]${suffix}[PREFIX]${prefix}`; + return "NOT USED!"; //`[SUFFIX]${suffix}[PREFIX]${prefix}`; }, completionOptions: { stop: ["[PREFIX]", "[SUFFIX]"], @@ -160,10 +160,10 @@ const starcoder2FimTemplate: AutocompleteTemplate = { snippets.length === 0 ? "" : `${snippets - .map((snippet) => { - return snippet.content; - }) - .join("")}`; + .map((snippet) => { + return snippet.content; + }) + .join("")}`; const prompt = `${otherFiles}${prefix}${suffix}`; return prompt; @@ -218,9 +218,8 @@ const codegeexFimTemplate: AutocompleteTemplate = { [...snippets.map((snippet) => snippet.filepath), filepath], workspaceUris, ); - const baseTemplate = `###PATH:${ - relativePaths[relativePaths.length - 1] - }\n###LANGUAGE:${language}\n###MODE:BLOCK\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`; + const baseTemplate = `###PATH:${relativePaths[relativePaths.length - 1] + }\n###LANGUAGE:${language}\n###MODE:BLOCK\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`; if (snippets.length === 0) { return `<|user|>\n${baseTemplate}<|assistant|>\n`; } diff --git a/core/autocomplete/templating/filtering.ts b/core/autocomplete/templating/filtering.ts index c741dedc8..7dc16c9d0 100644 --- a/core/autocomplete/templating/filtering.ts +++ b/core/autocomplete/templating/filtering.ts @@ -43,9 +43,10 @@ export const getSnippets = ( payload: SnippetPayload, ): AutocompleteSnippet[] => { const snippets = [ - ...payload.diffSnippets, ...payload.clipboardSnippets, ...payload.recentlyVisitedRangesSnippets, + ...payload.recentlyEditedRangeSnippets, + //...payload.diffSnippets, ...shuffleArray( filterSnippetsAlreadyInCaretWindow( [...payload.rootPathSnippets, ...payload.importDefinitionSnippets], diff --git a/extensions/vscode/src/autocomplete/RecentlyVisitedRangesService.ts b/extensions/vscode/src/autocomplete/RecentlyVisitedRangesService.ts index 2dba327ef..6f850d0ce 100644 --- a/extensions/vscode/src/autocomplete/RecentlyVisitedRangesService.ts +++ b/extensions/vscode/src/autocomplete/RecentlyVisitedRangesService.ts @@ -16,10 +16,10 @@ export class RecentlyVisitedRangesService { Array >; // Default value, we override in initWithPostHog - private numSurroundingLines = 5; + private numSurroundingLines = 20; private maxRecentFiles = 3; private maxSnippetsPerFile = 3; - private isEnabled = false; + private isEnabled = true; constructor(private readonly ide: IDE) { this.cache = new LRUCache< @@ -38,12 +38,11 @@ export class RecentlyVisitedRangesService { PosthogFeatureFlag.RecentlyVisitedRangesNumSurroundingLines, ); - if (!recentlyVisitedRangesNumSurroundingLines) { - return; + if (recentlyVisitedRangesNumSurroundingLines) { + this.isEnabled = true; + this.numSurroundingLines = recentlyVisitedRangesNumSurroundingLines; } - this.isEnabled = true; - this.numSurroundingLines = recentlyVisitedRangesNumSurroundingLines; vscode.window.onDidChangeTextEditorSelection( this.cacheCurrentSelectionContext, );