From 50515b7fd8ddf5a4acc58bc8e5b118b4ebf4c540 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Fri, 18 Oct 2024 17:35:21 +0700 Subject: [PATCH] improv: preserve punctuation completions --- core/autocomplete/completionProvider.ts | 10 +++++++--- core/autocomplete/filter.ts | 6 +++--- manual-testing-sandbox/Button.tsx | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 manual-testing-sandbox/Button.tsx diff --git a/core/autocomplete/completionProvider.ts b/core/autocomplete/completionProvider.ts index d954c3f31..bc826f934 100644 --- a/core/autocomplete/completionProvider.ts +++ b/core/autocomplete/completionProvider.ts @@ -28,7 +28,7 @@ import { constructAutocompletePrompt, languageForFilepath, } from "./constructPrompt.js"; -import { isOnlyPunctuationAndWhitespace } from "./filter.js"; +import { isOnlyWhitespace } from "./filter.js"; import { AutocompleteLanguageInfo } from "./languages.js"; import { postprocessCompletion } from "./postprocessing.js"; import { AutocompleteSnippet } from "./ranking.js"; @@ -355,8 +355,12 @@ export class CompletionProvider { return undefined; } - // Filter out unwanted results - if (isOnlyPunctuationAndWhitespace(outcome.completion)) { + /** + * This check is most likely not needed because we do trim the LLM output + * elsewhere in the code. That said, I'm not yet confident enough to + * remove this. + */ + if (isOnlyWhitespace(outcome.completion)) { return undefined; } diff --git a/core/autocomplete/filter.ts b/core/autocomplete/filter.ts index 9fb9b7d0b..5b2b66df0 100644 --- a/core/autocomplete/filter.ts +++ b/core/autocomplete/filter.ts @@ -1,4 +1,4 @@ -export function isOnlyPunctuationAndWhitespace(completion: string): boolean { - const punctuationAndWhitespaceRegex = /^[^\w\d\}\)\]]+$/; - return punctuationAndWhitespaceRegex.test(completion); +export function isOnlyWhitespace(completion: string): boolean { + const whitespaceRegex = /^[\s]+$/; + return whitespaceRegex.test(completion); } diff --git a/manual-testing-sandbox/Button.tsx b/manual-testing-sandbox/Button.tsx new file mode 100644 index 000000000..4d6f8f91b --- /dev/null +++ b/manual-testing-sandbox/Button.tsx @@ -0,0 +1,15 @@ +import React from "react"; + +export const Button = ({ + onClick, + children, +}: { + children: React.ReactNode; + onClick: () => void; +}) => { + return ( + + ); +};