From 7911efab891a28368aec099560245a83aec144a7 Mon Sep 17 00:00:00 2001 From: zhanba Date: Sat, 11 Jan 2025 21:41:39 +0800 Subject: [PATCH] feat(vscode): add inline edit on context menu --- clients/vscode/CONTRIBUTING.md | 8 +++++++- clients/vscode/package.json | 9 +++++++-- clients/vscode/src/commands/index.ts | 11 +++++++++++ clients/vscode/src/inline-edit/index.ts | 4 ++++ clients/vscode/tsup.config.ts | 10 ++++++---- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/clients/vscode/CONTRIBUTING.md b/clients/vscode/CONTRIBUTING.md index a658cc762bfa..c1a2ffd4a348 100644 --- a/clients/vscode/CONTRIBUTING.md +++ b/clients/vscode/CONTRIBUTING.md @@ -9,8 +9,14 @@ Thank you for considering contributing to Tabby VSCode Extension, to get started # Install dependencies pnpm install +# Build project +pnpm build + +# Change directory to VSCode extension +cd ./clients/vscode + # Start VSCode in development mode, with the extension loaded -pnpm dev +pnpm vscode:dev # Start VSCode Webview in development mode, with the extension loaded pnpm dev:browser diff --git a/clients/vscode/package.json b/clients/vscode/package.json index e83c4effa8ba..9198b1fab601 100644 --- a/clients/vscode/package.json +++ b/clients/vscode/package.json @@ -149,15 +149,20 @@ ], "menus": { "tabby.submenu": [ + { + "command": "tabby.chat.edit.start", + "when": "tabby.chatEnabled", + "group": "tabby.submenu.0edit@1" + }, { "command": "tabby.chat.addRelevantContext", "when": "editorHasSelection && tabby.chatEnabled", - "group": "tabby.submenu@1" + "group": "tabby.submenu.1chat@1" }, { "command": "tabby.chat.addFileContext", "when": "tabby.chatEnabled", - "group": "tabby.submenu@2" + "group": "tabby.submenu.1chat@2" } ], "commandPalette": [ diff --git a/clients/vscode/src/commands/index.ts b/clients/vscode/src/commands/index.ts index 2e9f875582c0..c4bdd3311f2b 100644 --- a/clients/vscode/src/commands/index.ts +++ b/clients/vscode/src/commands/index.ts @@ -285,6 +285,17 @@ export class Commands { }, }; + if (userCommand) { + try { + // when invoke from editor context menu, the first param `userCommand` is the current file path, we reset userCommand to undefined. + // uri parse will throw error when no scheme can be parsed. + Uri.parse(userCommand, true); + userCommand = undefined; + } catch { + // + } + } + const inlineEditController = new InlineEditController( this.client, this.config, diff --git a/clients/vscode/src/inline-edit/index.ts b/clients/vscode/src/inline-edit/index.ts index f3d89606dbb5..20ad4644c803 100644 --- a/clients/vscode/src/inline-edit/index.ts +++ b/clients/vscode/src/inline-edit/index.ts @@ -14,8 +14,10 @@ import { } from "vscode"; import { Client } from "../lsp/Client"; import { ContextVariables } from "../ContextVariables"; +import { getLogger } from "../logger"; export class InlineEditController { + private readonly logger = getLogger("InlineEditController"); private chatEditCancellationTokenSource: CancellationTokenSource | null = null; private quickPick: QuickPick; @@ -53,6 +55,7 @@ export class InlineEditController { } async start() { + this.logger.log(`Start inline edit with user command: ${this.userCommand}`); this.userCommand ? await this.provideEditWithCommand(this.userCommand) : this.quickPick.show(); } @@ -82,6 +85,7 @@ export class InlineEditController { this.editor.selection = new Selection(startPosition, startPosition); this.contextVariables.chatEditInProgress = true; this.chatEditCancellationTokenSource = new CancellationTokenSource(); + this.logger.log(`Provide edit with command: ${command}`); try { await this.client.chat.provideEdit( { diff --git a/clients/vscode/tsup.config.ts b/clients/vscode/tsup.config.ts index 9bdd0cb0a3d9..e54bdfdfd5fc 100644 --- a/clients/vscode/tsup.config.ts +++ b/clients/vscode/tsup.config.ts @@ -15,14 +15,16 @@ const banner = dedent` */`; export default defineConfig(async (options: Options): Promise => { - const tabbyAgentDist = path.join(await getInstalledPath("tabby-agent", { local: true }), "dist"); + const tabbyAgentDist = path + .join(await getInstalledPath("tabby-agent", { local: true }), "dist") + .replaceAll(path.sep, path.posix.sep); const copyTabbyAgentTask: Options = { name: "copy-tabby-agent", entry: ["scripts/dummy.js"], clean: true, esbuildPlugins: [ copy({ - assets: { from: `${tabbyAgentDist}/**`, to: "dist/tabby-agent" }, + assets: { from: `${tabbyAgentDist}/**`, to: path.join("dist", "tabby-agent") }, resolveFrom: "cwd", }), ], @@ -52,7 +54,7 @@ export default defineConfig(async (options: Options): Promise => { js: banner, }, onSuccess: options.env?.["LAUNCH_ON_SUCCESS"] - ? "code --extensionDevelopmentPath=$PWD --disable-extensions" + ? `code --extensionDevelopmentPath=${__dirname} --disable-extensions` : undefined, }; const buildBrowserTask: Options = { @@ -81,7 +83,7 @@ export default defineConfig(async (options: Options): Promise => { js: banner, }, onSuccess: options.env?.["LAUNCH_ON_SUCCESS"] - ? "vscode-test-web --extensionDevelopmentPath=$PWD --browserType=chromium --port=3000" + ? `vscode-test-web --extensionDevelopmentPath=${__dirname} --browserType=chromium --port=3000` : undefined, };