fix formatting issues

This commit is contained in:
ferenci84 2025-02-08 00:00:06 +01:00
parent be2c9cb92d
commit 4cc1cdd68a
5 changed files with 58 additions and 62 deletions

View file

@ -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 ",
},
});
});

View file

@ -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

View file

@ -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(

View file

@ -1,4 +1,4 @@
import * as Diff from "diff"
import * as Diff from "diff";
interface SingleLineCompletionResult {
completionText: string;

View file

@ -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;