Skip to content

Commit

Permalink
feat(vscode): add inline edit on context menu (#3675)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanba authored Jan 13, 2025
1 parent 3bd73a8 commit f67a3fe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
8 changes: 7 additions & 1 deletion clients/vscode/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions clients/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
11 changes: 11 additions & 0 deletions clients/vscode/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions clients/vscode/src/inline-edit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditCommand>;

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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(
{
Expand Down
10 changes: 6 additions & 4 deletions clients/vscode/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ const banner = dedent`
*/`;

export default defineConfig(async (options: Options): Promise<Options[]> => {
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",
}),
],
Expand Down Expand Up @@ -52,7 +54,7 @@ export default defineConfig(async (options: Options): Promise<Options[]> => {
js: banner,
},
onSuccess: options.env?.["LAUNCH_ON_SUCCESS"]
? "code --extensionDevelopmentPath=$PWD --disable-extensions"
? `code --extensionDevelopmentPath=${__dirname} --disable-extensions`
: undefined,
};
const buildBrowserTask: Options = {
Expand Down Expand Up @@ -81,7 +83,7 @@ export default defineConfig(async (options: Options): Promise<Options[]> => {
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,
};

Expand Down

0 comments on commit f67a3fe

Please sign in to comment.