diff --git a/core/autocomplete/lineStream.ts b/core/autocomplete/lineStream.ts index bc8a238fd..400705387 100644 --- a/core/autocomplete/lineStream.ts +++ b/core/autocomplete/lineStream.ts @@ -2,6 +2,17 @@ import { distance } from "fastest-levenshtein"; import { DiffLine } from ".."; import { LineStream } from "../diff/util"; +export async function* avoidPathLine(stream: LineStream, comment: string): LineStream { + // Snippets are inserted as comments with a line at the start '// Path: '. + // Sometimes the model with copy this pattern, which is unwanted + for await (const line of stream){ + if (line.startsWith(comment + " Path: ")) { + continue; + } + yield line; + } +} + export async function* streamWithNewLines(stream: LineStream): LineStream { let firstLine = true; for await (const nextLine of stream) { diff --git a/extensions/vscode/src/autocomplete/getTabCompletion.ts b/extensions/vscode/src/autocomplete/getTabCompletion.ts index a297819e3..f7e126bb8 100644 --- a/extensions/vscode/src/autocomplete/getTabCompletion.ts +++ b/extensions/vscode/src/autocomplete/getTabCompletion.ts @@ -6,6 +6,7 @@ import { languageForFilepath, } from "core/autocomplete/constructPrompt"; import { + avoidPathLine, stopAtSimilarLine, streamWithNewLines, } from "core/autocomplete/lineStream"; @@ -158,7 +159,7 @@ export async function getTabCompletion( generatorWithCancellation(), lang.endOfLine ); - const lineGenerator = streamWithNewLines(streamLines(gen2)); + const lineGenerator = streamWithNewLines(avoidPathLine(streamLines(gen2), lang.comment)); const finalGenerator = stopAtSimilarLine(lineGenerator, lineBelowCursor); for await (const update of finalGenerator) { completion += update;