Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vscode): add inline edit on context menu #3675

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading