Skip to content

Commit

Permalink
fix(vscode): only display Edit with Tabby when chat is enabled (#3020)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored Aug 30, 2024
1 parent 2dfd0bb commit 85a8376
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 34 deletions.
39 changes: 39 additions & 0 deletions clients/vscode/src/CodeAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
CancellationToken,
CodeAction,
CodeActionContext,
CodeActionKind,
CodeActionProvider as CodeActionProviderInterface,
Range,
Selection,
TextDocument,
} from "vscode";
import { ContextVariables } from "./ContextVariables";

export class CodeActionProvider implements CodeActionProviderInterface {
constructor(private readonly contextVariables: ContextVariables) {}

provideCodeActions(
_document: TextDocument,
_range: Range | Selection,
_context: CodeActionContext,
token: CancellationToken,
): CodeAction[] | undefined {
if (token.isCancellationRequested) {
return;
}

if (!this.contextVariables.chatEnabled) {
return;
}

const inlineEditing = new CodeAction("Edit using Tabby", CodeActionKind.RefactorRewrite);

inlineEditing.command = {
command: "tabby.chat.edit.start",
title: "Edit using Tabby",
};

return [inlineEditing];
}
}
31 changes: 0 additions & 31 deletions clients/vscode/src/InlineEditCodeActionProvider.ts

This file was deleted.

6 changes: 3 additions & 3 deletions clients/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { StatusBarItem } from "./StatusBarItem";
import { ChatViewProvider } from "./chat/ChatViewProvider";
import { Commands } from "./Commands";
import { Status } from "tabby-agent";
import { InlineEditCodeActionProvider } from "./InlineEditCodeActionProvider";
import { CodeActionProvider } from "./CodeAction";

const isBrowser = !!process.env["IS_BROWSER"];
const logger = getLogger();
Expand Down Expand Up @@ -51,12 +51,13 @@ export async function activate(context: ExtensionContext) {
client = new Client(context, languageClient);
}
const config = new Config(context);
const contextVariables = new ContextVariables(client, config);
const inlineCompletionProvider = new InlineCompletionProvider(client, config);
const gitProvider = new GitProvider();
client.registerConfigManager(config);
client.registerInlineCompletionProvider(inlineCompletionProvider);
client.registerGitProvider(gitProvider);
client.registerCodeActionProvider(new InlineEditCodeActionProvider());
client.registerCodeActionProvider(new CodeActionProvider(contextVariables));

// Register config callback for past ServerConfig
client.agent.addListener("didChangeStatus", async (status: Status) => {
Expand Down Expand Up @@ -89,7 +90,6 @@ export async function activate(context: ExtensionContext) {
await client.start();

const issues = new Issues(client, config);
const contextVariables = new ContextVariables(client, config);
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */ /* eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error */
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ // @ts-ignore noUnusedLocals
const statusBarItem = new StatusBarItem(context, client, config, issues, inlineCompletionProvider);
Expand Down

0 comments on commit 85a8376

Please sign in to comment.