Skip to content

Commit

Permalink
feat(vscode): add inline edit on context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanba committed Jan 11, 2025
1 parent e93e28f commit c5234eb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion clients/vscode/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ Thank you for considering contributing to Tabby VSCode Extension, to get started
# Install dependencies
pnpm install

# Build project
pnpm build

# cd into 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
5 changes: 5 additions & 0 deletions clients/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@
"command": "tabby.chat.addFileContext",
"when": "tabby.chatEnabled",
"group": "tabby.submenu@2"
},
{
"command": "tabby.chat.edit.start",
"when": "tabby.chatEnabled",
"group": "tabby.submenu@3"
}
],
"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
4 changes: 3 additions & 1 deletion clients/vscode/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default defineConfig(async (options: Options): Promise<Options[]> => {
}),
],
onSuccess: async () => {
// Esbuild copy seems not work on windows
console.log(`copy tabby-agent from ${tabbyAgentDist} success`)
await fs.remove(path.join(__dirname, "dist/dummy.js"));
},
};
Expand All @@ -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

0 comments on commit c5234eb

Please sign in to comment.