diff --git a/core/autocomplete/util/completionTestUtils.test.ts b/core/autocomplete/util/completionTestUtils.test.ts index 7ef76eba0..bdf4e209a 100644 --- a/core/autocomplete/util/completionTestUtils.test.ts +++ b/core/autocomplete/util/completionTestUtils.test.ts @@ -1,61 +1,64 @@ -import { processTestCase, type CompletionTestCase } from './completionTestUtils'; +import { + processTestCase, + type CompletionTestCase, +} from "./completionTestUtils"; -describe('processTestCase utility', () => { - it('processes simple console.log completion', () => { +describe("processTestCase utility", () => { + it("processes simple console.log completion", () => { const testCase: CompletionTestCase = { - original: 'console.log(|cur||till|)', - completion: '"foo,", bar', + original: "console.log(|cur||till|)", + completion: "\"foo,\", bar", }; expect(processTestCase(testCase)).toEqual({ input: { - lastLineOfCompletionText: '"foo,", bar', - currentText: ')', - cursorPosition: 'console.log('.length, + lastLineOfCompletionText: "\"foo,\", bar", + currentText: ")", + cursorPosition: "console.log(".length, }, expectedResult: { - completionText: '"foo,", bar', + completionText: "\"foo,\", bar", }, }); }); - it('processes simple console.log completion with overwriting', () => { + it("processes simple console.log completion with overwriting", () => { const testCase: CompletionTestCase = { - original: 'console.log(|cur|)|till|', - completion: '"foo,", bar);', + original: "console.log(|cur|)|till|", + completion: "\"foo,\", bar);", }; expect(processTestCase(testCase)).toEqual({ input: { - lastLineOfCompletionText: '"foo,", bar);', - currentText: ')', - cursorPosition: 'console.log('.length, + lastLineOfCompletionText: "\"foo,\", bar);", + currentText: ")", + cursorPosition: "console.log(".length, }, expectedResult: { - completionText: '"foo,", bar);', + completionText: "\"foo,\", bar);", range: { - start: 'console.log('.length, - end: 'console.log()'.length + start: "console.log(".length, + end: "console.log()".length, }, }, }); }); - it('partially applying completion', () => { + it("partially applying completion", () => { const testCase: CompletionTestCase = { - original: '|cur||till|fetch("https://example.com");', - completion: 'await fetch("https://example.com");', - appliedCompletion: 'await ' + original: "|cur||till|fetch(\"https://example.com\");", + completion: "await fetch(\"https://example.com\");", + appliedCompletion: "await ", }; expect(processTestCase(testCase)).toEqual({ input: { - lastLineOfCompletionText: 'await fetch("https://example.com");', - currentText: 'fetch("https://example.com");', + lastLineOfCompletionText: "await fetch(\"https://example.com\");", + currentText: "fetch(\"https://example.com\");", cursorPosition: 0, }, expectedResult: { - completionText: 'await ' + completionText: "await ", }, }); }); diff --git a/core/autocomplete/util/completionTestUtils.ts b/core/autocomplete/util/completionTestUtils.ts index 4ca10d739..414b15627 100644 --- a/core/autocomplete/util/completionTestUtils.ts +++ b/core/autocomplete/util/completionTestUtils.ts @@ -25,22 +25,22 @@ export function processTestCase({ original, completion, appliedCompletion = null, - cursorMarker = '|cur|', - tillMarker = '|till|', + cursorMarker = "|cur|", + tillMarker = "|till|", }: CompletionTestCase): ProcessedTestCase { // Validate cursor marker if (!original.includes(cursorMarker)) { - throw new Error('Cursor marker not found in original text'); + throw new Error("Cursor marker not found in original text"); } const cursorPos = original.indexOf(cursorMarker); - original = original.replace(cursorMarker, ''); + original = original.replace(cursorMarker, ""); let tillPos = original.indexOf(tillMarker); if (tillPos < 0) { tillPos = cursorPos; } else { - original = original.replace(tillMarker, '') + original = original.replace(tillMarker, "") } // Calculate currentText based on what's between cursor and till marker diff --git a/core/autocomplete/util/processSingleLineCompletion.test.ts b/core/autocomplete/util/processSingleLineCompletion.test.ts index 7384ab949..8081ac20c 100644 --- a/core/autocomplete/util/processSingleLineCompletion.test.ts +++ b/core/autocomplete/util/processSingleLineCompletion.test.ts @@ -1,12 +1,12 @@ -import { processTestCase } from './completionTestUtils'; -import { processSingleLineCompletion } from './processSingleLineCompletion'; +import { processTestCase } from "./completionTestUtils"; +import { processSingleLineCompletion } from "./processSingleLineCompletion"; -describe('processSingleLineCompletion', () => { +describe("processSingleLineCompletion", () => { - it('should handle simple end of line completion', () => { + it("should handle simple end of line completion", () => { const testCase = processTestCase({ - original: 'console.log(|cur|', - completion: '"Hello, world!")', + original: "console.log(|cur|", + completion: "\"Hello, world!\")", }); const result = processSingleLineCompletion( @@ -18,10 +18,10 @@ describe('processSingleLineCompletion', () => { expect(result).toEqual(testCase.expectedResult); }); - it('should handle midline insert repeating the end of line', () => { + it("should handle midline insert repeating the end of line", () => { const testCase = processTestCase({ - original: 'console.log(|cur|);|till|', - completion: '"Hello, world!");', + original: "console.log(|cur|);|till|", + completion: "\"Hello, world!\");", }); const result = processSingleLineCompletion( @@ -33,10 +33,10 @@ describe('processSingleLineCompletion', () => { expect(result).toEqual(testCase.expectedResult); }); - it('should handle midline insert repeating the end of line plus adding a semicolon', () => { + it("should handle midline insert repeating the end of line plus adding a semicolon", () => { const testCase = processTestCase({ - original: 'console.log(|cur|)|till|', - completion: '"Hello, world!");', + original: "console.log(|cur|)|till|", + completion: "\"Hello, world!\");", }); const result = processSingleLineCompletion( @@ -48,10 +48,10 @@ describe('processSingleLineCompletion', () => { expect(result).toEqual(testCase.expectedResult); }); - it('should handle simple midline insert', () => { + it("should handle simple midline insert", () => { const testCase = processTestCase({ - original: 'console.log(|cur|)', - completion: '"Hello, world!"', + original: "console.log(|cur|)", + completion: "\"Hello, world!\"", }); const result = processSingleLineCompletion( @@ -63,11 +63,11 @@ describe('processSingleLineCompletion', () => { expect(result).toEqual(testCase.expectedResult); }); - it('should handle complex dif with addition in the beginning', () => { + it("should handle complex dif with addition in the beginning", () => { const testCase = processTestCase({ - original: 'console.log(|cur||till|, "param1", )', // TODO - completion: '"Hello world!", "param1", param1);', - appliedCompletion: '"Hello world!"' + original: "console.log(|cur||till|, \"param1\", )", // TODO + completion: "\"Hello world!\", \"param1\", param1);", + appliedCompletion: "\"Hello world!\"" }); const result = processSingleLineCompletion( @@ -79,10 +79,10 @@ describe('processSingleLineCompletion', () => { expect(result).toEqual(testCase.expectedResult); }); - it('should handle simple insertion even with random equality', () => { + it("should handle simple insertion even with random equality", () => { const testCase = processTestCase({ - original: 'print(f"Foobar length: |cur||till|")', - completion: '{len(foobar)}', + original: "print(f\"Foobar length: |cur||till|\")", + completion: "{len(foobar)}", }); const result = processSingleLineCompletion( diff --git a/core/autocomplete/util/processSingleLineCompletion.ts b/core/autocomplete/util/processSingleLineCompletion.ts index cc9da95d0..3dc093411 100644 --- a/core/autocomplete/util/processSingleLineCompletion.ts +++ b/core/autocomplete/util/processSingleLineCompletion.ts @@ -1,4 +1,4 @@ -import * as Diff from "diff" +import * as Diff from "diff"; interface SingleLineCompletionResult { completionText: string; diff --git a/extensions/vscode/src/autocomplete/completionProvider.ts b/extensions/vscode/src/autocomplete/completionProvider.ts index 7a1816256..ded488fff 100644 --- a/extensions/vscode/src/autocomplete/completionProvider.ts +++ b/extensions/vscode/src/autocomplete/completionProvider.ts @@ -1,9 +1,11 @@ import { CompletionProvider } from "core/autocomplete/CompletionProvider"; +import { processSingleLineCompletion } from "core/autocomplete/util/processSingleLineCompletion"; import { type AutocompleteInput, type AutocompleteOutcome, } from "core/autocomplete/util/types"; import { ConfigHandler } from "core/config/ConfigHandler"; +import { startLocalOllama } from "core/util/ollamaHelper"; import * as URI from "uri-js"; import { v4 as uuidv4 } from "uuid"; import * as vscode from "vscode"; @@ -22,16 +24,7 @@ import { } from "./statusBar"; import type { TabAutocompleteModel } from "../util/loadAutocompleteModel"; -import { startLocalOllama } from "core/util/ollamaHelper"; import type { IDE } from "core"; -import { processSingleLineCompletion } from "core/autocomplete/util/processSingleLineCompletion"; - -interface DiffType { - count: number; - added: boolean; - removed: boolean; - value: string; -} interface VsCodeCompletionInput { document: vscode.TextDocument;