From c4598b7685490b018a9bda5ff04d2a49e074d5eb Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 29 Feb 2024 11:30:46 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20stop=20autocomplete=20mode?= =?UTF-8?q?l=20from=20outputting=20//=20Path:=20...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/autocomplete/lineStream.ts | 11 +++++++++++ .../vscode/src/autocomplete/getTabCompletion.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) 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;