Merge branch 'main' into start-ollama
This commit is contained in:
commit
e620a5272a
27 changed files with 420 additions and 99 deletions
|
|
@ -6,6 +6,7 @@
|
|||
},
|
||||
"plugins": ["@typescript-eslint", "import"],
|
||||
"rules": {
|
||||
"@typescript-eslint/naming-convention": "off",
|
||||
"@typescript-eslint/semi": "warn",
|
||||
"curly": "warn",
|
||||
"eqeqeq": "warn",
|
||||
|
|
|
|||
|
|
@ -59,8 +59,8 @@ export async function testAutocompleteFiltering(
|
|||
line,
|
||||
character,
|
||||
},
|
||||
recentlyEditedFiles: [],
|
||||
recentlyEditedRanges: [],
|
||||
recentlyVisitedRanges: [],
|
||||
};
|
||||
|
||||
// Generate a completion
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { findUriInDirs } from "../../util/uri";
|
|||
import { ContextRetrievalService } from "../context/ContextRetrievalService";
|
||||
import { GetLspDefinitionsFunction } from "../types";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
|
||||
import {
|
||||
AutocompleteClipboardSnippet,
|
||||
AutocompleteCodeSnippet,
|
||||
|
|
@ -15,6 +16,7 @@ export interface SnippetPayload {
|
|||
importDefinitionSnippets: AutocompleteCodeSnippet[];
|
||||
ideSnippets: AutocompleteCodeSnippet[];
|
||||
recentlyEditedRangeSnippets: AutocompleteCodeSnippet[];
|
||||
recentlyVisitedRangesSnippets: AutocompleteCodeSnippet[];
|
||||
diffSnippets: AutocompleteDiffSnippet[];
|
||||
clipboardSnippets: AutocompleteClipboardSnippet[];
|
||||
}
|
||||
|
|
@ -135,5 +137,6 @@ export const getAllSnippets = async ({
|
|||
recentlyEditedRangeSnippets,
|
||||
diffSnippets,
|
||||
clipboardSnippets,
|
||||
recentlyVisitedRangesSnippets: helper.input.recentlyVisitedRanges,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -111,13 +111,13 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = {
|
|||
return snippet.content;
|
||||
}
|
||||
|
||||
return `+++++ ${relativePaths[i]}\n${snippet.content}`;
|
||||
return `+++++ ${relativePaths[i].uri} \n${snippet.content}`;
|
||||
})
|
||||
.join("\n\n");
|
||||
|
||||
return [
|
||||
`${otherFiles}\n\n+++++ ${
|
||||
relativePaths[relativePaths.length - 1]
|
||||
relativePaths[relativePaths.length - 1].uri
|
||||
}\n${prefix}`,
|
||||
suffix,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
AutocompleteSnippet,
|
||||
} from "../snippets/types";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
|
||||
import { isValidSnippet } from "./validation";
|
||||
|
||||
const getRemainingTokenCount = (helper: HelperVars): number => {
|
||||
|
|
@ -44,6 +45,7 @@ export const getSnippets = (
|
|||
const snippets = [
|
||||
...payload.diffSnippets,
|
||||
...payload.clipboardSnippets,
|
||||
...payload.recentlyVisitedRangesSnippets,
|
||||
...shuffleArray(
|
||||
filterSnippetsAlreadyInCaretWindow(
|
||||
[...payload.rootPathSnippets, ...payload.importDefinitionSnippets],
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {
|
|||
RangeInFileWithContents,
|
||||
TabAutocompleteOptions,
|
||||
} from "../..";
|
||||
import { AutocompleteCodeSnippet } from "../snippets/types";
|
||||
|
||||
export type RecentlyEditedRange = RangeInFile & {
|
||||
timestamp: number;
|
||||
|
|
@ -17,7 +18,7 @@ export interface AutocompleteInput {
|
|||
completionId: string;
|
||||
filepath: string;
|
||||
pos: Position;
|
||||
recentlyEditedFiles: RangeInFileWithContents[];
|
||||
recentlyVisitedRanges: AutocompleteCodeSnippet[];
|
||||
recentlyEditedRanges: RecentlyEditedRange[];
|
||||
// Used for notebook files
|
||||
manuallyPassFileContents?: string;
|
||||
|
|
|
|||
13
core/core.ts
13
core/core.ts
|
|
@ -2,10 +2,12 @@ import path from "path";
|
|||
|
||||
import { fetchwithRequestOptions } from "@continuedev/fetch";
|
||||
import ignore from "ignore";
|
||||
import * as URI from "uri-js";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { CompletionProvider } from "./autocomplete/CompletionProvider";
|
||||
import { ConfigHandler } from "./config/ConfigHandler";
|
||||
import { SYSTEM_PROMPT_DOT_FILE } from "./config/getSystemPromptDotFile";
|
||||
import {
|
||||
setupBestConfig,
|
||||
setupLocalConfig,
|
||||
|
|
@ -26,6 +28,7 @@ import Ollama from "./llm/llms/Ollama";
|
|||
import { createNewPromptFileV2 } from "./promptFiles/v2/createNewPromptFile";
|
||||
import { callTool } from "./tools/callTool";
|
||||
import { ChatDescriber } from "./util/chatDescriber";
|
||||
import { clipboardCache } from "./util/clipboardCache";
|
||||
import { logDevData } from "./util/devdata";
|
||||
import { DevDataSqliteDb } from "./util/devdataSqlite";
|
||||
import { GlobalContext } from "./util/GlobalContext";
|
||||
|
|
@ -35,18 +38,15 @@ import {
|
|||
getConfigJsonPath,
|
||||
setupInitialDotContinueDirectory,
|
||||
} from "./util/paths";
|
||||
import { localPathToUri } from "./util/pathToUri";
|
||||
import { Telemetry } from "./util/posthog";
|
||||
import { getSymbolsForManyFiles } from "./util/treeSitter";
|
||||
import { TTS } from "./util/tts";
|
||||
|
||||
import { type ContextItemId, type IDE, type IndexingProgressUpdate } from ".";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
|
||||
import * as URI from "uri-js";
|
||||
import { SYSTEM_PROMPT_DOT_FILE } from "./config/getSystemPromptDotFile";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
import type { IMessenger, Message } from "./protocol/messenger";
|
||||
import { localPathToUri } from "./util/pathToUri";
|
||||
import { clipboardCache } from "./util/clipboardCache";
|
||||
|
||||
export class Core {
|
||||
// implements IMessenger<ToCoreProtocol, FromCoreProtocol>
|
||||
|
|
@ -299,7 +299,6 @@ export class Core {
|
|||
});
|
||||
|
||||
on("context/loadSubmenuItems", async (msg) => {
|
||||
console.log("Load SUMBENU ITEMS", msg);
|
||||
const config = await this.config();
|
||||
if (!config) {
|
||||
return [];
|
||||
|
|
@ -384,7 +383,6 @@ export class Core {
|
|||
});
|
||||
|
||||
on("clipboardCache/add", (msg) => {
|
||||
console.log("ADD TO CLIPBOARD", msg);
|
||||
clipboardCache.add(uuidv4(), msg.data.content);
|
||||
this.messenger.send("refreshSubmenuItems", undefined);
|
||||
});
|
||||
|
|
@ -665,7 +663,6 @@ export class Core {
|
|||
abortedMessageIds.delete(msg.messageId);
|
||||
break;
|
||||
}
|
||||
console.log(diffLine);
|
||||
yield { content: diffLine };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,17 @@ import os from "node:os";
|
|||
|
||||
import { TeamAnalytics } from "../control-plane/TeamAnalytics.js";
|
||||
import { IdeInfo } from "../index.js";
|
||||
|
||||
import type { PostHog as PostHogType } from "posthog-node";
|
||||
|
||||
export enum PosthogFeatureFlag {
|
||||
AutocompleteTimeout = "autocomplete-timeout",
|
||||
RecentlyVisitedRangesNumSurroundingLines = "recently-visited-ranges-num-surrounding-lines",
|
||||
}
|
||||
|
||||
export const EXPERIMENTS: {
|
||||
[key in PosthogFeatureFlag]: {
|
||||
[key: string]: { value: number };
|
||||
[key: string]: { value: any };
|
||||
};
|
||||
} = {
|
||||
[PosthogFeatureFlag.AutocompleteTimeout]: {
|
||||
|
|
@ -19,6 +21,13 @@ export const EXPERIMENTS: {
|
|||
"350": { value: 350 },
|
||||
"450": { value: 450 },
|
||||
},
|
||||
[PosthogFeatureFlag.RecentlyVisitedRangesNumSurroundingLines]: {
|
||||
control: { value: null },
|
||||
"5": { value: 5 },
|
||||
"10": { value: 10 },
|
||||
"15": { value: 15 },
|
||||
"20": { value: 20 },
|
||||
},
|
||||
};
|
||||
|
||||
export class Telemetry {
|
||||
|
|
|
|||
|
|
@ -96,9 +96,9 @@ class AutocompleteService(private val project: Project) {
|
|||
"line" to line,
|
||||
"character" to column
|
||||
),
|
||||
"recentlyEditedFiles" to emptyList<String>(),
|
||||
"recentlyEditedRanges" to emptyList<String>(),
|
||||
"clipboardText" to ""
|
||||
"clipboardText" to "",
|
||||
"recentlyEditedRanges" to emptyList<Any>(),
|
||||
"recentlyVisitedRanges" to emptyList<Any>(),
|
||||
)
|
||||
|
||||
project.service<ContinuePluginService>().coreMessenger?.request(
|
||||
|
|
@ -115,8 +115,7 @@ class AutocompleteService(private val project: Project) {
|
|||
|
||||
if (shouldRenderCompletion(finalTextToInsert, offset, line, editor)) {
|
||||
renderCompletion(editor, offset, finalTextToInsert)
|
||||
// Hide auto-popup
|
||||
// AutoPopupController.getInstance(project).cancelAllRequests()
|
||||
pendingCompletion = PendingCompletion(editor, offset, completionId, finalTextToInsert)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@
|
|||
},
|
||||
"extends": ["../../.eslintrc.shared.json"],
|
||||
"rules": {
|
||||
"@typescript-eslint/naming-convention": "warn"
|
||||
"@typescript-eslint/naming-convention": "off"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
import { expect } from "chai";
|
||||
import {
|
||||
Key,
|
||||
WebElement,
|
||||
waitForAttributeValue,
|
||||
} from "vscode-extension-tester";
|
||||
import { Key } from "vscode-extension-tester";
|
||||
|
||||
import { DEFAULT_TIMEOUT } from "./constants";
|
||||
|
||||
export class TestUtils {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { TextEditor } from "vscode-extension-tester";
|
||||
import { TestUtils } from "../TestUtils";
|
||||
import { AutocompleteSelectors } from "../selectors/Autocomplete.selectors";
|
||||
import { expect } from "chai";
|
||||
import { TextEditor } from "vscode-extension-tester";
|
||||
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
import { AutocompleteSelectors } from "../selectors/Autocomplete.selectors";
|
||||
import { TestUtils } from "../TestUtils";
|
||||
|
||||
export class AutocompleteActions {
|
||||
public static async testCompletions(editor: TextEditor) {
|
||||
|
|
|
|||
40
extensions/vscode/e2e/actions/Edit.actions.ts
Normal file
40
extensions/vscode/e2e/actions/Edit.actions.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { TextEditor, WebView } from "vscode-extension-tester";
|
||||
|
||||
import { EditSelectors } from "../selectors/Edit.selectors";
|
||||
import { TestUtils } from "../TestUtils";
|
||||
|
||||
export class EditActions {
|
||||
static async invokeEditShortcut(editor: TextEditor) {
|
||||
editor
|
||||
.getDriver()
|
||||
.actions()
|
||||
.keyDown(TestUtils.osControlKey)
|
||||
.sendKeys("i")
|
||||
.keyUp(TestUtils.osControlKey)
|
||||
.perform();
|
||||
}
|
||||
|
||||
static async acceptEditInGUI(view: WebView): Promise<void> {
|
||||
await TestUtils.waitForSuccess(async () =>
|
||||
(await EditSelectors.getEditAcceptButton(view)).click(),
|
||||
);
|
||||
await view.switchBack();
|
||||
}
|
||||
|
||||
static async rejectEditInGUI(view: WebView): Promise<void> {
|
||||
await TestUtils.waitForSuccess(async () =>
|
||||
(await EditSelectors.getEditRejectButton(view)).click(),
|
||||
);
|
||||
await view.switchBack();
|
||||
}
|
||||
|
||||
static async acceptEditWithCodeLens(editor: TextEditor): Promise<void> {
|
||||
const acceptCodeLens = await editor.getCodeLens("Accept");
|
||||
await acceptCodeLens?.click();
|
||||
}
|
||||
|
||||
static async rejectEditWithCodeLens(editor: TextEditor): Promise<void> {
|
||||
const rejectCodeLens = await editor.getCodeLens("Reject");
|
||||
await rejectCodeLens?.click();
|
||||
}
|
||||
}
|
||||
|
|
@ -6,9 +6,10 @@ import {
|
|||
WebView,
|
||||
Workbench,
|
||||
} from "vscode-extension-tester";
|
||||
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
import { GUISelectors } from "../selectors/GUI.selectors";
|
||||
import { TestUtils } from "../TestUtils";
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
|
||||
export class GUIActions {
|
||||
public static moveContinueToSidebar = async (driver: WebDriver) => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,29 @@
|
|||
import { VSBrowser, WebView } from "vscode-extension-tester";
|
||||
import {
|
||||
EditorView,
|
||||
InputBox,
|
||||
TextEditor,
|
||||
VSBrowser,
|
||||
Workbench,
|
||||
} from "vscode-extension-tester";
|
||||
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
|
||||
export class GlobalActions {
|
||||
public static async openTestWorkspace() {
|
||||
return VSBrowser.instance.openResources("e2e/test-continue");
|
||||
}
|
||||
|
||||
public static async createAndOpenNewTextFile(): Promise<{
|
||||
editor: TextEditor;
|
||||
}> {
|
||||
await new Workbench().executeCommand("Create: New File...");
|
||||
await (
|
||||
await InputBox.create(DEFAULT_TIMEOUT.MD)
|
||||
).selectQuickPick("Text File");
|
||||
const editor = (await new EditorView().openEditor(
|
||||
"Untitled-1",
|
||||
)) as TextEditor;
|
||||
|
||||
return { editor };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import { TextEditor, WebDriver, WebView } from "vscode-extension-tester";
|
||||
|
||||
import { TestUtils } from "../TestUtils";
|
||||
import { TextEditor } from "vscode-extension-tester";
|
||||
|
||||
export class KeyboardShortcutsActions {
|
||||
/**
|
||||
|
|
|
|||
13
extensions/vscode/e2e/selectors/Edit.selectors.ts
Normal file
13
extensions/vscode/e2e/selectors/Edit.selectors.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { WebView } from "vscode-extension-tester";
|
||||
|
||||
import { SelectorUtils } from "./SelectorUtils";
|
||||
|
||||
export class EditSelectors {
|
||||
public static getEditAcceptButton(view: WebView) {
|
||||
return SelectorUtils.getElementByDataTestId(view, "edit-accept-button");
|
||||
}
|
||||
|
||||
public static getEditRejectButton(view: WebView) {
|
||||
return SelectorUtils.getElementByDataTestId(view, "edit-reject-button");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { By, until, WebDriver, WebView } from "vscode-extension-tester";
|
||||
import { By, WebDriver, WebView } from "vscode-extension-tester";
|
||||
|
||||
import { SelectorUtils } from "./SelectorUtils";
|
||||
|
||||
export class GUISelectors {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
import {
|
||||
EditorView,
|
||||
TextEditor,
|
||||
InputBox,
|
||||
Workbench,
|
||||
} from "vscode-extension-tester";
|
||||
import { EditorView, TextEditor } from "vscode-extension-tester";
|
||||
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
import { GlobalActions } from "../actions/Global.actions";
|
||||
import { AutocompleteActions } from "../actions/Autocomplete.actions";
|
||||
import { GlobalActions } from "../actions/Global.actions";
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
|
||||
describe("Autocomplete", () => {
|
||||
let editor: TextEditor;
|
||||
|
|
@ -16,11 +11,7 @@ describe("Autocomplete", () => {
|
|||
this.timeout(DEFAULT_TIMEOUT.XL);
|
||||
|
||||
await GlobalActions.openTestWorkspace();
|
||||
await new Workbench().executeCommand("Create: New File...");
|
||||
await (
|
||||
await InputBox.create(DEFAULT_TIMEOUT.MD)
|
||||
).selectQuickPick("Text File");
|
||||
editor = (await new EditorView().openEditor("Untitled-1")) as TextEditor;
|
||||
({ editor } = await GlobalActions.createAndOpenNewTextFile());
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
|
|
|
|||
125
extensions/vscode/e2e/tests/Edit.test.ts
Normal file
125
extensions/vscode/e2e/tests/Edit.test.ts
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
import {
|
||||
EditorView,
|
||||
WebView,
|
||||
WebDriver,
|
||||
Key,
|
||||
VSBrowser,
|
||||
InputBox,
|
||||
TextEditor,
|
||||
Workbench,
|
||||
} from "vscode-extension-tester";
|
||||
|
||||
import { EditActions } from "../actions/Edit.actions";
|
||||
import { GlobalActions } from "../actions/Global.actions";
|
||||
import { GUIActions } from "../actions/GUI.actions";
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
import { EditSelectors } from "../selectors/Edit.selectors";
|
||||
import { GUISelectors } from "../selectors/GUI.selectors";
|
||||
import { TestUtils } from "../TestUtils";
|
||||
|
||||
describe("Edit Test", () => {
|
||||
let view: WebView;
|
||||
let editor: TextEditor;
|
||||
let originalEditorText = "Hello world!";
|
||||
let { userMessage, llmResponse } = TestUtils.generateTestMessagePair();
|
||||
|
||||
before(async function () {
|
||||
this.timeout(DEFAULT_TIMEOUT.XL);
|
||||
await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver);
|
||||
await GlobalActions.openTestWorkspace();
|
||||
({ editor } = await GlobalActions.createAndOpenNewTextFile());
|
||||
});
|
||||
|
||||
beforeEach(async function () {
|
||||
this.timeout(DEFAULT_TIMEOUT.XL);
|
||||
|
||||
await GUIActions.toggleGui();
|
||||
|
||||
await editor.typeTextAt(1, 1, originalEditorText);
|
||||
await editor.selectText(originalEditorText);
|
||||
|
||||
await EditActions.invokeEditShortcut(editor);
|
||||
|
||||
({ view } = await GUIActions.switchToReactIframe());
|
||||
|
||||
await GUIActions.sendMessage({
|
||||
view,
|
||||
message: userMessage,
|
||||
inputFieldIndex: 0,
|
||||
});
|
||||
|
||||
await view.switchBack();
|
||||
|
||||
await TestUtils.waitForSuccess(async () => {
|
||||
const editorText = await editor.getText();
|
||||
return editorText.includes(llmResponse);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
this.timeout(DEFAULT_TIMEOUT.XL);
|
||||
await editor.clearText();
|
||||
});
|
||||
|
||||
it("Accepts an Edit in the GUI", async () => {
|
||||
({ view } = await GUIActions.switchToReactIframe());
|
||||
|
||||
await EditActions.acceptEditInGUI(view);
|
||||
|
||||
await view.switchBack();
|
||||
|
||||
const editorText = await editor.getText();
|
||||
|
||||
await TestUtils.waitForSuccess(
|
||||
async () =>
|
||||
!editorText.includes(originalEditorText) &&
|
||||
editorText.includes(llmResponse),
|
||||
DEFAULT_TIMEOUT.SM,
|
||||
);
|
||||
}).timeout(DEFAULT_TIMEOUT.XL);
|
||||
|
||||
it("Rejects an Edit in the GUI", async () => {
|
||||
({ view } = await GUIActions.switchToReactIframe());
|
||||
|
||||
await EditActions.rejectEditInGUI(view);
|
||||
|
||||
await view.switchBack();
|
||||
|
||||
const editorText = await editor.getText();
|
||||
|
||||
await TestUtils.waitForSuccess(
|
||||
async () =>
|
||||
editorText.includes(originalEditorText) &&
|
||||
!editorText.includes(llmResponse),
|
||||
DEFAULT_TIMEOUT.SM,
|
||||
);
|
||||
}).timeout(DEFAULT_TIMEOUT.XL);
|
||||
|
||||
it("Accepts an Edit using CodeLens buttons", async () => {
|
||||
const acceptCodeLens = await editor.getCodeLens("Accept");
|
||||
await acceptCodeLens?.click();
|
||||
|
||||
const editorText = await editor.getText();
|
||||
|
||||
await TestUtils.waitForSuccess(
|
||||
async () =>
|
||||
!editorText.includes(originalEditorText) &&
|
||||
editorText.includes(llmResponse),
|
||||
DEFAULT_TIMEOUT.SM,
|
||||
);
|
||||
}).timeout(DEFAULT_TIMEOUT.XL);
|
||||
|
||||
it("Rejects an Edit using CodeLens buttons", async () => {
|
||||
const rejectCodeLens = await editor.getCodeLens("Reject");
|
||||
await rejectCodeLens?.click();
|
||||
|
||||
const editorText = await editor.getText();
|
||||
|
||||
await TestUtils.waitForSuccess(
|
||||
async () =>
|
||||
!editorText.includes(originalEditorText) &&
|
||||
editorText.includes(llmResponse),
|
||||
DEFAULT_TIMEOUT.SM,
|
||||
);
|
||||
}).timeout(DEFAULT_TIMEOUT.XL);
|
||||
});
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import { expect } from "chai";
|
||||
import {
|
||||
EditorView,
|
||||
WebView,
|
||||
|
|
@ -7,12 +8,12 @@ import {
|
|||
VSBrowser,
|
||||
until,
|
||||
} from "vscode-extension-tester";
|
||||
import { expect } from "chai";
|
||||
|
||||
import { GlobalActions } from "../actions/Global.actions";
|
||||
import { GUIActions } from "../actions/GUI.actions";
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
import { GUISelectors } from "../selectors/GUI.selectors";
|
||||
import { TestUtils } from "../TestUtils";
|
||||
import { DEFAULT_TIMEOUT } from "../constants";
|
||||
import { GlobalActions } from "../actions/Global.actions";
|
||||
|
||||
describe("GUI Test", () => {
|
||||
let view: WebView;
|
||||
|
|
|
|||
46
extensions/vscode/package-lock.json
generated
46
extensions/vscode/package-lock.json
generated
|
|
@ -35,6 +35,7 @@
|
|||
"https-proxy-agent": "^7.0.2",
|
||||
"ignore": "^5.3.0",
|
||||
"jsdom": "^24.0.0",
|
||||
"lru-cache": "^11.0.2",
|
||||
"minisearch": "^7.0.0",
|
||||
"monaco-editor": "^0.45.0",
|
||||
"monaco-vscode-textmate-theme-converter": "^0.1.7",
|
||||
|
|
@ -6739,6 +6740,18 @@
|
|||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/hosted-git-info/node_modules/lru-cache": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"yallist": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/hpagent": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/hpagent/-/hpagent-1.2.0.tgz",
|
||||
|
|
@ -7920,15 +7933,11 @@
|
|||
}
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
||||
"devOptional": true,
|
||||
"dependencies": {
|
||||
"yallist": "^4.0.0"
|
||||
},
|
||||
"version": "11.0.2",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.2.tgz",
|
||||
"integrity": "sha512-123qHRfJBmo2jXDbo/a5YOQrJoHF/GNQTLzQ5+IdK5pWpceK17yRc6ozlWd25FxvGKQbIUs91fDFkXmDHTKcyA==",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": "20 || >=22"
|
||||
}
|
||||
},
|
||||
"node_modules/lru-queue": {
|
||||
|
|
@ -9368,6 +9377,18 @@
|
|||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/node-gyp/node_modules/lru-cache": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"yallist": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/node-gyp/node_modules/make-fetch-happen": {
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz",
|
||||
|
|
@ -14300,15 +14321,6 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/vscode-extension-tester/node_modules/lru-cache": {
|
||||
"version": "11.0.2",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.2.tgz",
|
||||
"integrity": "sha512-123qHRfJBmo2jXDbo/a5YOQrJoHF/GNQTLzQ5+IdK5pWpceK17yRc6ozlWd25FxvGKQbIUs91fDFkXmDHTKcyA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": "20 || >=22"
|
||||
}
|
||||
},
|
||||
"node_modules/vscode-extension-tester/node_modules/markdown-it": {
|
||||
"version": "14.1.0",
|
||||
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz",
|
||||
|
|
|
|||
|
|
@ -689,6 +689,7 @@
|
|||
"https-proxy-agent": "^7.0.2",
|
||||
"ignore": "^5.3.0",
|
||||
"jsdom": "^24.0.0",
|
||||
"lru-cache": "^11.0.2",
|
||||
"minisearch": "^7.0.0",
|
||||
"monaco-editor": "^0.45.0",
|
||||
"monaco-vscode-textmate-theme-converter": "^0.1.7",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,121 @@
|
|||
import { IDE } from "core";
|
||||
import {
|
||||
AutocompleteCodeSnippet,
|
||||
AutocompleteSnippetType,
|
||||
} from "core/autocomplete/snippets/types";
|
||||
import { PosthogFeatureFlag, Telemetry } from "core/util/posthog";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
/**
|
||||
* Service to keep track of recently visited ranges in files.
|
||||
*/
|
||||
export class RecentlyVisitedRangesService {
|
||||
private cache: LRUCache<
|
||||
string,
|
||||
Array<AutocompleteCodeSnippet & { timestamp: number }>
|
||||
>;
|
||||
// Default value, we override in initWithPostHog
|
||||
private numSurroundingLines = 5;
|
||||
private maxRecentFiles = 3;
|
||||
private maxSnippetsPerFile = 3;
|
||||
private isEnabled = false;
|
||||
|
||||
constructor(private readonly ide: IDE) {
|
||||
this.cache = new LRUCache<
|
||||
string,
|
||||
Array<AutocompleteCodeSnippet & { timestamp: number }>
|
||||
>({
|
||||
max: this.maxRecentFiles,
|
||||
});
|
||||
|
||||
void this.initWithPostHog();
|
||||
}
|
||||
|
||||
private async initWithPostHog() {
|
||||
const recentlyVisitedRangesNumSurroundingLines =
|
||||
await Telemetry.getValueForFeatureFlag(
|
||||
PosthogFeatureFlag.RecentlyVisitedRangesNumSurroundingLines,
|
||||
);
|
||||
|
||||
if (!recentlyVisitedRangesNumSurroundingLines) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isEnabled = true;
|
||||
this.numSurroundingLines = recentlyVisitedRangesNumSurroundingLines;
|
||||
vscode.window.onDidChangeTextEditorSelection(
|
||||
this.cacheCurrentSelectionContext,
|
||||
);
|
||||
}
|
||||
|
||||
private cacheCurrentSelectionContext = async (
|
||||
event: vscode.TextEditorSelectionChangeEvent,
|
||||
) => {
|
||||
const filepath = event.textEditor.document.uri.toString();
|
||||
const line = event.selections[0].active.line;
|
||||
const startLine = Math.max(0, line - this.numSurroundingLines);
|
||||
const endLine = Math.min(
|
||||
line + this.numSurroundingLines,
|
||||
event.textEditor.document.lineCount - 1,
|
||||
);
|
||||
|
||||
try {
|
||||
const fileContents = await this.ide.readFile(filepath);
|
||||
const lines = fileContents.split("\n");
|
||||
const relevantLines = lines
|
||||
.slice(startLine, endLine + 1)
|
||||
.join("\n")
|
||||
.trim();
|
||||
|
||||
const snippet: AutocompleteCodeSnippet & { timestamp: number } = {
|
||||
filepath,
|
||||
content: relevantLines,
|
||||
type: AutocompleteSnippetType.Code,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
|
||||
const existing = this.cache.get(filepath) || [];
|
||||
const newSnippets = [...existing, snippet]
|
||||
.sort((a, b) => b.timestamp - a.timestamp)
|
||||
.slice(0, this.maxSnippetsPerFile);
|
||||
|
||||
this.cache.set(filepath, newSnippets);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"Error caching recently visited ranges for autocomplete: ",
|
||||
err,
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns up to {@link maxSnippetsPerFile} snippets from the {@link maxRecentFiles} most recently visited files.
|
||||
* Excludes snippets from the currently active file.
|
||||
* @returns Array of code snippets from recently visited files
|
||||
*/
|
||||
public getSnippets(): AutocompleteCodeSnippet[] {
|
||||
if (!this.isEnabled) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const currentFilepath =
|
||||
vscode.window.activeTextEditor?.document.uri.toString();
|
||||
let allSnippets: Array<AutocompleteCodeSnippet & { timestamp: number }> =
|
||||
[];
|
||||
|
||||
// Get most recent snippets from each file in cache
|
||||
for (const filepath of Array.from(this.cache.keys())) {
|
||||
const snippets = (this.cache.get(filepath) || [])
|
||||
.sort((a, b) => b.timestamp - a.timestamp)
|
||||
.slice(0, this.maxSnippetsPerFile);
|
||||
allSnippets = [...allSnippets, ...snippets];
|
||||
}
|
||||
|
||||
return allSnippets
|
||||
.filter((s) => !currentFilepath || s.filepath !== currentFilepath)
|
||||
.sort((a, b) => b.timestamp - a.timestamp)
|
||||
.map(({ timestamp, ...snippet }) => snippet);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,26 +4,28 @@ import {
|
|||
type AutocompleteOutcome,
|
||||
} from "core/autocomplete/util/types";
|
||||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
import * as URI from "uri-js";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import * as vscode from "vscode";
|
||||
const Diff = require("diff");
|
||||
|
||||
import { showFreeTrialLoginMessage } from "../util/messages";
|
||||
import { VsCodeWebviewProtocol } from "../webviewProtocol";
|
||||
|
||||
import { getDefinitionsFromLsp } from "./lsp";
|
||||
import { RecentlyEditedTracker } from "./recentlyEdited";
|
||||
import { RecentlyVisitedRangesService } from "./RecentlyVisitedRangesService";
|
||||
import {
|
||||
StatusBarStatus,
|
||||
getStatusBarStatus,
|
||||
setupStatusBar,
|
||||
stopStatusBarLoading,
|
||||
} from "./statusBar";
|
||||
import * as URI from "uri-js";
|
||||
|
||||
import type { IDE } from "core";
|
||||
import type { TabAutocompleteModel } from "../util/loadAutocompleteModel";
|
||||
import { startLocalOllama } from "core/util/ollamaHelper";
|
||||
import type { IDE } from "core";
|
||||
|
||||
const Diff = require("diff");
|
||||
|
||||
interface DiffType {
|
||||
count: number;
|
||||
|
|
@ -75,6 +77,7 @@ export class ContinueCompletionProvider
|
|||
}
|
||||
|
||||
private completionProvider: CompletionProvider;
|
||||
private recentlyVisitedRanges: RecentlyVisitedRangesService;
|
||||
private recentlyEditedTracker = new RecentlyEditedTracker();
|
||||
|
||||
constructor(
|
||||
|
|
@ -90,6 +93,7 @@ export class ContinueCompletionProvider
|
|||
this.onError.bind(this),
|
||||
getDefinitionsFromLsp,
|
||||
);
|
||||
this.recentlyVisitedRanges = new RecentlyVisitedRangesService(ide);
|
||||
}
|
||||
|
||||
_lastShownCompletion: AutocompleteOutcome | undefined;
|
||||
|
|
@ -131,30 +135,6 @@ export class ContinueCompletionProvider
|
|||
}
|
||||
|
||||
let injectDetails: string | undefined = undefined;
|
||||
// Here we could use the details from the intellisense dropdown
|
||||
// and place them just above the line being typed but because
|
||||
// we don't have control over the formatting of the details and
|
||||
// they could be especially long, not doing this for now
|
||||
// if (context.selectedCompletionInfo) {
|
||||
// const results: any = await vscode.commands.executeCommand(
|
||||
// "vscode.executeCompletionItemProvider",
|
||||
// document.uri,
|
||||
// position,
|
||||
// null,
|
||||
// 1,
|
||||
// );
|
||||
// if (results?.items) {
|
||||
// injectDetails = results.items?.[0]?.detail;
|
||||
// // const label = results?.items?.[0].label;
|
||||
// // const workspaceSymbols = (
|
||||
// // (await vscode.commands.executeCommand(
|
||||
// // "vscode.executeWorkspaceSymbolProvider",
|
||||
// // label,
|
||||
// // )) as any
|
||||
// // ).filter((symbol: any) => symbol.name === label);
|
||||
// // console.log(label, "=>", workspaceSymbols);
|
||||
// }
|
||||
// }
|
||||
|
||||
// The first time intellisense dropdown shows up, and the first choice is selected,
|
||||
// we should not consider this. Only once user explicitly moves down the list
|
||||
|
|
@ -218,17 +198,17 @@ export class ContinueCompletionProvider
|
|||
let manuallyPassPrefix: string | undefined = undefined;
|
||||
|
||||
const input: AutocompleteInput = {
|
||||
isUntitledFile: document.isUntitled,
|
||||
completionId: uuidv4(),
|
||||
filepath: document.uri.toString(),
|
||||
pos,
|
||||
recentlyEditedFiles: [],
|
||||
recentlyEditedRanges:
|
||||
await this.recentlyEditedTracker.getRecentlyEditedRanges(),
|
||||
manuallyPassFileContents,
|
||||
manuallyPassPrefix,
|
||||
selectedCompletionInfo,
|
||||
injectDetails,
|
||||
isUntitledFile: document.isUntitled,
|
||||
completionId: uuidv4(),
|
||||
filepath: document.uri.toString(),
|
||||
recentlyVisitedRanges: this.recentlyVisitedRanges.getSnippets(),
|
||||
recentlyEditedRanges:
|
||||
await this.recentlyEditedTracker.getRecentlyEditedRanges(),
|
||||
};
|
||||
|
||||
setupStatusBar(undefined, true);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
// "plugin:@typescript-eslint/recommended-requiring-type-checking"
|
||||
// "plugin:react/recommended"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/naming-convention": "off"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["src/**/*.{js,ts,jsx,tsx}"]
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ export default function AcceptRejectAllButtons({
|
|||
<button
|
||||
className="flex cursor-pointer items-center border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
|
||||
onClick={() => handleAcceptOrReject("rejectDiff")}
|
||||
data-testid="edit-reject-button"
|
||||
>
|
||||
<XMarkIcon className="mr-1 h-4 w-4 text-red-600" />
|
||||
{isSingleRangeEdit ? (
|
||||
|
|
@ -53,6 +54,7 @@ export default function AcceptRejectAllButtons({
|
|||
<button
|
||||
className="flex cursor-pointer items-center border-none bg-transparent px-2 py-1 text-xs text-gray-300 opacity-80 hover:opacity-100 hover:brightness-125"
|
||||
onClick={() => handleAcceptOrReject("acceptDiff")}
|
||||
data-testid="edit-accept-button"
|
||||
>
|
||||
<CheckIcon className="mr-1 h-4 w-4 text-green-600" />
|
||||
{isSingleRangeEdit ? (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue