From 5f65cca9891469dc695db26f47e655cf99ee9dbf Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 28 Nov 2024 11:28:21 -0800 Subject: [PATCH 1/4] improv: ensure sure at least one non-whitespace line is returned --- .../filtering/streamTransforms/lineStream.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/autocomplete/filtering/streamTransforms/lineStream.ts b/core/autocomplete/filtering/streamTransforms/lineStream.ts index 9cbf190ec..236f0e3bd 100644 --- a/core/autocomplete/filtering/streamTransforms/lineStream.ts +++ b/core/autocomplete/filtering/streamTransforms/lineStream.ts @@ -537,12 +537,17 @@ export async function* showWhateverWeHaveAtXMs( ms: number, ): LineStream { const startTime = Date.now(); + let firstNonWhitespaceLineYielded = false; + for await (const line of lines) { - // Always get at least one line yield line; - // But after that, soft break at X ms - if (Date.now() - startTime > ms) { + if (!firstNonWhitespaceLineYielded && line.trim() !== "") { + firstNonWhitespaceLineYielded = true; + } + + const isTakingTooLong = Date.now() - startTime > ms; + if (isTakingTooLong && firstNonWhitespaceLineYielded) { break; } } From 403eb38b9e3e38c277daed4ac6a2b6ac54353570 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 28 Nov 2024 12:01:09 -0800 Subject: [PATCH 2/4] fix: don't return empty string --- core/autocomplete/postprocessing/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/autocomplete/postprocessing/index.ts b/core/autocomplete/postprocessing/index.ts index 1eb3b37da..8258450d0 100644 --- a/core/autocomplete/postprocessing/index.ts +++ b/core/autocomplete/postprocessing/index.ts @@ -43,11 +43,15 @@ function isExtremeRepetition(completion: string): boolean { } return false; } -export function isOnlyWhitespace(completion: string): boolean { +function isOnlyWhitespace(completion: string): boolean { const whitespaceRegex = /^[\s]+$/; return whitespaceRegex.test(completion); } +function isBlank(completion: string): boolean { + return completion.trim().length === 0; +} + export function postprocessCompletion({ completion, llm, @@ -60,6 +64,11 @@ export function postprocessCompletion({ suffix: string; }): string | undefined { // Don't return empty + if (isBlank(completion)) { + return undefined; + } + + // Don't return whitespace if (isOnlyWhitespace(completion)) { return undefined; } From 4db2637d5b65d427e959b7fd607a65ce4140c355 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 28 Nov 2024 12:07:41 -0800 Subject: [PATCH 3/4] fix: whitespace in new line completions --- core/autocomplete/postprocessing/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/autocomplete/postprocessing/index.ts b/core/autocomplete/postprocessing/index.ts index 8258450d0..ed7c41f05 100644 --- a/core/autocomplete/postprocessing/index.ts +++ b/core/autocomplete/postprocessing/index.ts @@ -121,11 +121,8 @@ export function postprocessCompletion({ // } // If prefix ends with space and so does completion, then remove the space from completion - if ( - prefix.split("\n").pop()?.trim() !== "" && - prefix.endsWith(" ") && - completion.startsWith(" ") - ) { + + if (prefix.endsWith(" ") && completion.startsWith(" ")) { completion = completion.slice(1); } From 8d29d4158d0fe21b0c0c4722e8d23715acf9ebdf Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Thu, 28 Nov 2024 12:14:51 -0800 Subject: [PATCH 4/4] fix: failing tests --- core/autocomplete/filtering/test/testCases.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/autocomplete/filtering/test/testCases.ts b/core/autocomplete/filtering/test/testCases.ts index 33924b1b3..662bf5201 100644 --- a/core/autocomplete/filtering/test/testCases.ts +++ b/core/autocomplete/filtering/test/testCases.ts @@ -333,6 +333,21 @@ export const Timer = () => { llmOutput: ` this;`, expectedCompletion: `this;`, }, + { + description: + "Should autocomplete SQL query with subquery and alias in SELECT clause", + filename: "complex_query.sql", + input: `SELECT u.id, + u.name, + (SELECT COUNT(*) FROM orders o WHERE o.user_id = u.id) AS order_count + FROM users u + WHERE u.active = 1 + <|fim|>`, + llmOutput: + " AND EXISTS (SELECT 1 FROM transactions t WHERE t.user_id = u.id AND t.amount > 100)", + expectedCompletion: + "AND EXISTS (SELECT 1 FROM transactions t WHERE t.user_id = u.id AND t.amount > 100)", + }, ]; export const TEST_CASES_WITHOUT_DIFF: AutocompleteFileringTestInput[] = [ @@ -832,21 +847,6 @@ func main() { llmOutput: " DEFAULT", expectedCompletion: " DEFAULT", }, - { - description: - "Should autocomplete SQL query with subquery and alias in SELECT clause", - filename: "complex_query.sql", - input: `SELECT u.id, - u.name, - (SELECT COUNT(*) FROM orders o WHERE o.user_id = u.id) AS order_count - FROM users u - WHERE u.active = 1 - <|fim|>`, - llmOutput: - " AND EXISTS (SELECT 1 FROM transactions t WHERE t.user_id = u.id AND t.amount > 100)", - expectedCompletion: - " AND EXISTS (SELECT 1 FROM transactions t WHERE t.user_id = u.id AND t.amount > 100)", - }, { description: "Should autocomplete multi-line SQL query with CASE statements",