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 shortcut hint in codeLens title #3637

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions clients/tabby-agent/src/codeLens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class CodeLensProvider implements Feature {
line: changesPreviewLineType.header,
},
});

lineCodeLenses.push({
range: codeLensRange,
command: {
Expand Down
17 changes: 17 additions & 0 deletions clients/vscode/src/lsp/CodeLensMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { CodeLensMiddleware as VscodeLspCodeLensMiddleware, ProvideCodeLensesSignature } from "vscode-languageclient";
import { CodeLens as TabbyCodeLens } from "tabby-agent";
import { findTextEditor } from "./vscodeWindowUtils";
import { isBrowser } from "../env";

type CodeLens = VscodeCodeLens & TabbyCodeLens;

Expand Down Expand Up @@ -74,7 +75,9 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware {
if (!editor) {
return codeLenses;
}

this.removeDecorations(editor);

const result =
codeLenses
?.map((codeLens) => this.handleCodeLens(codeLens, editor))
Expand All @@ -84,6 +87,7 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware {
}

private handleCodeLens(codeLens: CodeLens, editor: TextEditor): CodeLens | null {
this.addShortcut(codeLens);
if (!codeLens.data || codeLens.data.type !== "previewChanges") {
return codeLens;
}
Expand All @@ -106,6 +110,19 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware {
return null;
}

private addShortcut(codeLens: CodeLens) {
if (codeLens.command?.arguments?.[0].action === "accept") {
// FIXME: Read ~/.config/Code/User/keybindings.json from LSP client, then send to LSP server to avoid hardcode.
const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "⌘+Enter" : "Ctrl+Enter"})`;

codeLens.command.title += acceptShortcut;
} else if (codeLens.command?.arguments?.[0].action === "discard") {
const discardShortcut = isBrowser ? "" : ` (Esc)`;

codeLens.command.title += discardShortcut;
}
}

private addDecorationRange(editor: TextEditor, decorationType: TextEditorDecorationType, range: Range) {
let decorations: Map<TextEditorDecorationType, Range[]> | undefined;
if (this.decorationMap.has(editor)) {
Expand Down
Loading