From f97573e77ee3f7073142ceca9da30a7de07562d0 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Sun, 16 Jun 2024 19:15:22 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20strip=20=20fro?= =?UTF-8?q?m=20GPT-4=20completion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/autocomplete/completionProvider.ts | 2 ++ core/autocomplete/lineStream.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/core/autocomplete/completionProvider.ts b/core/autocomplete/completionProvider.ts index 3590a2383..873515bf5 100644 --- a/core/autocomplete/completionProvider.ts +++ b/core/autocomplete/completionProvider.ts @@ -38,6 +38,7 @@ import { AutocompleteLanguageInfo } from "./languages.js"; import { avoidPathLine, noTopLevelKeywordsMidline, + skipPrefixes, stopAtLines, stopAtRepeatingLines, stopAtSimilarLine, @@ -407,6 +408,7 @@ export async function getTabCompletion( lineGenerator = stopAtLines(lineGenerator, fullStop); lineGenerator = stopAtRepeatingLines(lineGenerator, fullStop); lineGenerator = avoidPathLine(lineGenerator, lang.singleLineComment); + lineGenerator = skipPrefixes(lineGenerator); lineGenerator = noTopLevelKeywordsMidline( lineGenerator, lang.topLevelKeywords, diff --git a/core/autocomplete/lineStream.ts b/core/autocomplete/lineStream.ts index 3f552e5f5..14d4c4ab7 100644 --- a/core/autocomplete/lineStream.ts +++ b/core/autocomplete/lineStream.ts @@ -121,6 +121,22 @@ export async function* stopAtLines( } } +const PREFIXES_TO_SKIP = [""]; +export async function* skipPrefixes(lines: LineStream): LineStream { + let isFirstLine = true; + for await (const line of lines) { + if (isFirstLine) { + const match = PREFIXES_TO_SKIP.find((prefix) => line.startsWith(prefix)); + if (match) { + yield line.slice(match.length); + continue; + } + isFirstLine = false; + } + yield line; + } +} + const LINES_TO_SKIP = [""]; export async function* skipLines(stream: LineStream): LineStream {