From 3f1d34dd81322324722381ef5fa36678e62cd868 Mon Sep 17 00:00:00 2001 From: zzgu Date: Tue, 31 Dec 2024 13:50:07 -0800 Subject: [PATCH 01/11] feat(vscode): add shortcur hint in codeLens title --- clients/tabby-agent/src/codeLens.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/clients/tabby-agent/src/codeLens.ts b/clients/tabby-agent/src/codeLens.ts index 848dadd5faf4..8c5659af6d71 100644 --- a/clients/tabby-agent/src/codeLens.ts +++ b/clients/tabby-agent/src/codeLens.ts @@ -11,6 +11,7 @@ import { import { ClientCapabilities, ServerCapabilities, CodeLens, CodeLensType, ChangesPreviewLineType } from "./protocol"; import { TextDocuments } from "./lsp/textDocuments"; import { TextDocument } from "vscode-languageserver-textdocument"; +import { isBrowser } from "./env"; const codeLensType: CodeLensType = "previewChanges"; const changesPreviewLineType = { @@ -116,10 +117,12 @@ export class CodeLensProvider implements Feature { }, }); } else if (!previewBlockMarkers.includes("x")) { + // TODO: read keybinds from LSP client, then send to LSP server to avoid hardcode. + const acceptShortcut = isBrowser ? '' : ` (${process.platform === 'darwin' ? 'cmd+enter' : 'ctrl+enter'})` lineCodeLenses.push({ range: codeLensRange, command: { - title: "$(check)Accept", + title: `$(check)Accept${acceptShortcut}`, command: "tabby/chat/edit/resolve", arguments: [{ location: codeLensLocation, action: "accept" }], }, @@ -128,10 +131,12 @@ export class CodeLensProvider implements Feature { line: changesPreviewLineType.header, }, }); + + const discardShortcut = isBrowser ? '' : ` (esc)` lineCodeLenses.push({ range: codeLensRange, command: { - title: "$(remove-close)Discard", + title: `$(remove-close)Discard${discardShortcut}`, command: "tabby/chat/edit/resolve", arguments: [{ location: codeLensLocation, action: "discard" }], }, From 75c12d06cc5ad5f4f6fb18d68233b037cc433a36 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 31 Dec 2024 21:57:39 +0000 Subject: [PATCH 02/11] [autofix.ci] apply automated fixes --- clients/tabby-agent/src/codeLens.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/tabby-agent/src/codeLens.ts b/clients/tabby-agent/src/codeLens.ts index 8c5659af6d71..e626bd1da470 100644 --- a/clients/tabby-agent/src/codeLens.ts +++ b/clients/tabby-agent/src/codeLens.ts @@ -118,7 +118,7 @@ export class CodeLensProvider implements Feature { }); } else if (!previewBlockMarkers.includes("x")) { // TODO: read keybinds from LSP client, then send to LSP server to avoid hardcode. - const acceptShortcut = isBrowser ? '' : ` (${process.platform === 'darwin' ? 'cmd+enter' : 'ctrl+enter'})` + const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "cmd+enter" : "ctrl+enter"})`; lineCodeLenses.push({ range: codeLensRange, command: { @@ -132,7 +132,7 @@ export class CodeLensProvider implements Feature { }, }); - const discardShortcut = isBrowser ? '' : ` (esc)` + const discardShortcut = isBrowser ? "" : ` (esc)`; lineCodeLenses.push({ range: codeLensRange, command: { From 587c8927e80dcffc2814b836f2cf78a02483945a Mon Sep 17 00:00:00 2001 From: zzgu Date: Thu, 2 Jan 2025 13:54:00 -0800 Subject: [PATCH 03/11] fix: implement shortcut in client middelware --- clients/tabby-agent/src/codeLens.ts | 8 ++----- clients/vscode/src/lsp/CodeLensMiddleware.ts | 24 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/clients/tabby-agent/src/codeLens.ts b/clients/tabby-agent/src/codeLens.ts index e626bd1da470..3340f0ce81c3 100644 --- a/clients/tabby-agent/src/codeLens.ts +++ b/clients/tabby-agent/src/codeLens.ts @@ -11,7 +11,6 @@ import { import { ClientCapabilities, ServerCapabilities, CodeLens, CodeLensType, ChangesPreviewLineType } from "./protocol"; import { TextDocuments } from "./lsp/textDocuments"; import { TextDocument } from "vscode-languageserver-textdocument"; -import { isBrowser } from "./env"; const codeLensType: CodeLensType = "previewChanges"; const changesPreviewLineType = { @@ -117,12 +116,10 @@ export class CodeLensProvider implements Feature { }, }); } else if (!previewBlockMarkers.includes("x")) { - // TODO: read keybinds from LSP client, then send to LSP server to avoid hardcode. - const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "cmd+enter" : "ctrl+enter"})`; lineCodeLenses.push({ range: codeLensRange, command: { - title: `$(check)Accept${acceptShortcut}`, + title: `$(check)Accept`, command: "tabby/chat/edit/resolve", arguments: [{ location: codeLensLocation, action: "accept" }], }, @@ -132,11 +129,10 @@ export class CodeLensProvider implements Feature { }, }); - const discardShortcut = isBrowser ? "" : ` (esc)`; lineCodeLenses.push({ range: codeLensRange, command: { - title: `$(remove-close)Discard${discardShortcut}`, + title: `$(remove-close)Discard`, command: "tabby/chat/edit/resolve", arguments: [{ location: codeLensLocation, action: "discard" }], }, diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index 9a9cfd28ef84..00dd803f6ff4 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -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; @@ -74,16 +75,22 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { if (!editor) { return codeLenses; } + + if (!codeLenses) { + return []; + } + this.removeDecorations(editor); const result = codeLenses - ?.map((codeLens) => this.handleCodeLens(codeLens, editor)) - .filter((codeLens): codeLens is CodeLens => codeLens !== null) ?? []; + .map((codeLens) => this.handleCodeLens(codeLens, editor)) + .filter((codeLens): codeLens is CodeLens => codeLens !== null); this.purgeDecorationMap(); return result; } private handleCodeLens(codeLens: CodeLens, editor: TextEditor): CodeLens | null { + this.addShortcut(codeLens); if (!codeLens.data || codeLens.data.type !== "previewChanges") { return codeLens; } @@ -106,6 +113,19 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { return null; } + private addShortcut(codeLens: CodeLens) { + if (codeLens.command?.arguments?.[0].action === "accept") { + // TODO: read keybinds from LSP client, then send to LSP server to avoid hardcode. + const acceptShortcut = isBrowser ? '' : ` (${process.platform === 'darwin' ? 'cmd+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 | undefined; if (this.decorationMap.has(editor)) { From 5d384d24ba04fbdeb15890a90a8f54650c5f810e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:03:12 +0000 Subject: [PATCH 04/11] [autofix.ci] apply automated fixes --- clients/vscode/src/lsp/CodeLensMiddleware.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index 00dd803f6ff4..400f53fac32a 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -81,10 +81,9 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { } this.removeDecorations(editor); - const result = - codeLenses - .map((codeLens) => this.handleCodeLens(codeLens, editor)) - .filter((codeLens): codeLens is CodeLens => codeLens !== null); + const result = codeLenses + .map((codeLens) => this.handleCodeLens(codeLens, editor)) + .filter((codeLens): codeLens is CodeLens => codeLens !== null); this.purgeDecorationMap(); return result; } @@ -113,16 +112,16 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { return null; } - private addShortcut(codeLens: CodeLens) { + private addShortcut(codeLens: CodeLens) { if (codeLens.command?.arguments?.[0].action === "accept") { // TODO: read keybinds from LSP client, then send to LSP server to avoid hardcode. - const acceptShortcut = isBrowser ? '' : ` (${process.platform === 'darwin' ? 'cmd+enter' : 'ctrl+enter'})`; + const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "cmd+enter" : "ctrl+enter"})`; - codeLens.command.title += (acceptShortcut); + codeLens.command.title += acceptShortcut; } else if (codeLens.command?.arguments?.[0].action === "discard") { - const discardShortcut = isBrowser ? '' : ` (esc)`; + const discardShortcut = isBrowser ? "" : ` (esc)`; - codeLens.command.title += (discardShortcut); + codeLens.command.title += discardShortcut; } } From 104e5d368cbcf653ce6cb2d309a51eb3f836c370 Mon Sep 17 00:00:00 2001 From: zzgu Date: Thu, 2 Jan 2025 13:54:00 -0800 Subject: [PATCH 05/11] fix: implement shortcut in client middelware --- clients/vscode/src/lsp/CodeLensMiddleware.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index 400f53fac32a..1b369dc7ccc3 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -112,16 +112,16 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { return null; } - private addShortcut(codeLens: CodeLens) { + private addShortcut(codeLens: CodeLens) { if (codeLens.command?.arguments?.[0].action === "accept") { - // TODO: read keybinds from LSP client, then send to LSP server to avoid hardcode. - const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "cmd+enter" : "ctrl+enter"})`; + // TODO: read ~/.config/Code/User/keybindings.json from LSP client, then send to LSP server to avoid hardcode. + const acceptShortcut = isBrowser ? '' : ` (${process.platform === 'darwin' ? 'cmd+enter' : 'ctrl+enter'})`; - codeLens.command.title += acceptShortcut; + codeLens.command.title += (acceptShortcut); } else if (codeLens.command?.arguments?.[0].action === "discard") { - const discardShortcut = isBrowser ? "" : ` (esc)`; + const discardShortcut = isBrowser ? '' : ` (esc)`; - codeLens.command.title += discardShortcut; + codeLens.command.title += (discardShortcut); } } From 3a926f0a8c8bf49ab02e4e1150baf7d85f2c866f Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:31:13 +0000 Subject: [PATCH 06/11] [autofix.ci] apply automated fixes --- clients/vscode/src/lsp/CodeLensMiddleware.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index 1b369dc7ccc3..1e563f795899 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -112,16 +112,16 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { return null; } - private addShortcut(codeLens: CodeLens) { + private addShortcut(codeLens: CodeLens) { if (codeLens.command?.arguments?.[0].action === "accept") { // TODO: read ~/.config/Code/User/keybindings.json from LSP client, then send to LSP server to avoid hardcode. - const acceptShortcut = isBrowser ? '' : ` (${process.platform === 'darwin' ? 'cmd+enter' : 'ctrl+enter'})`; + const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "cmd+enter" : "ctrl+enter"})`; - codeLens.command.title += (acceptShortcut); + codeLens.command.title += acceptShortcut; } else if (codeLens.command?.arguments?.[0].action === "discard") { - const discardShortcut = isBrowser ? '' : ` (esc)`; + const discardShortcut = isBrowser ? "" : ` (esc)`; - codeLens.command.title += (discardShortcut); + codeLens.command.title += discardShortcut; } } From 71c209e86562d957f04b29a589d928565d8d3f69 Mon Sep 17 00:00:00 2001 From: zzgu Date: Mon, 6 Jan 2025 11:21:28 -0800 Subject: [PATCH 07/11] resolve comments --- clients/vscode/src/lsp/CodeLensMiddleware.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index 1e563f795899..dfddcca13c73 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -76,11 +76,11 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { return codeLenses; } + this.removeDecorations(editor); if (!codeLenses) { return []; } - this.removeDecorations(editor); const result = codeLenses .map((codeLens) => this.handleCodeLens(codeLens, editor)) .filter((codeLens): codeLens is CodeLens => codeLens !== null); @@ -114,8 +114,8 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { private addShortcut(codeLens: CodeLens) { if (codeLens.command?.arguments?.[0].action === "accept") { - // TODO: read ~/.config/Code/User/keybindings.json from LSP client, then send to LSP server to avoid hardcode. - const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "cmd+enter" : "ctrl+enter"})`; + // 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") { From 5454e8158d4d4a779a7fe8523009d83eef82591d Mon Sep 17 00:00:00 2001 From: zzgu Date: Mon, 6 Jan 2025 11:28:13 -0800 Subject: [PATCH 08/11] revoke codeLnses empty check --- clients/vscode/src/lsp/CodeLensMiddleware.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index dfddcca13c73..0cbd2874e0b0 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -77,13 +77,11 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { } this.removeDecorations(editor); - if (!codeLenses) { - return []; - } - - const result = codeLenses - .map((codeLens) => this.handleCodeLens(codeLens, editor)) - .filter((codeLens): codeLens is CodeLens => codeLens !== null); + + const result = + codeLenses + ?.map((codeLens) => this.handleCodeLens(codeLens, editor)) + .filter((codeLens): codeLens is CodeLens => codeLens !== null) ?? []; this.purgeDecorationMap(); return result; } From bf21283fe19e46ddaaf609698a3fadd50f5a1bed Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 01:18:31 +0000 Subject: [PATCH 09/11] [autofix.ci] apply automated fixes --- clients/vscode/src/lsp/CodeLensMiddleware.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index 0cbd2874e0b0..7ae7b31136ef 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -77,11 +77,11 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { } this.removeDecorations(editor); - + const result = - codeLenses - ?.map((codeLens) => this.handleCodeLens(codeLens, editor)) - .filter((codeLens): codeLens is CodeLens => codeLens !== null) ?? []; + codeLenses + ?.map((codeLens) => this.handleCodeLens(codeLens, editor)) + .filter((codeLens): codeLens is CodeLens => codeLens !== null) ?? []; this.purgeDecorationMap(); return result; } @@ -113,7 +113,7 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { 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'})`; + const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "⌘+enter" : "Ctrl+enter"})`; codeLens.command.title += acceptShortcut; } else if (codeLens.command?.arguments?.[0].action === "discard") { From 677b07798557c66d0b4fb5117539e29e29960fb2 Mon Sep 17 00:00:00 2001 From: zzgu Date: Mon, 13 Jan 2025 15:54:06 -0800 Subject: [PATCH 10/11] fix comments --- clients/tabby-agent/src/codeLens.ts | 4 ++-- clients/vscode/src/lsp/CodeLensMiddleware.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clients/tabby-agent/src/codeLens.ts b/clients/tabby-agent/src/codeLens.ts index 3340f0ce81c3..220fc38fb988 100644 --- a/clients/tabby-agent/src/codeLens.ts +++ b/clients/tabby-agent/src/codeLens.ts @@ -119,7 +119,7 @@ export class CodeLensProvider implements Feature { lineCodeLenses.push({ range: codeLensRange, command: { - title: `$(check)Accept`, + title: "$(check)Accept", command: "tabby/chat/edit/resolve", arguments: [{ location: codeLensLocation, action: "accept" }], }, @@ -132,7 +132,7 @@ export class CodeLensProvider implements Feature { lineCodeLenses.push({ range: codeLensRange, command: { - title: `$(remove-close)Discard`, + title: "$(remove-close)Discard", command: "tabby/chat/edit/resolve", arguments: [{ location: codeLensLocation, action: "discard" }], }, diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index 7ae7b31136ef..4ea3c2b35e99 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -113,11 +113,11 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { 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"})`; + 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)`; + const discardShortcut = isBrowser ? "" : ` (Esc)`; codeLens.command.title += discardShortcut; } From 8cb06b37f2847e2f3d390b25c96a2562c5d42019 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 00:23:25 +0000 Subject: [PATCH 11/11] [autofix.ci] apply automated fixes --- clients/vscode/src/lsp/CodeLensMiddleware.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/vscode/src/lsp/CodeLensMiddleware.ts b/clients/vscode/src/lsp/CodeLensMiddleware.ts index 4ea3c2b35e99..5889e4562c2c 100644 --- a/clients/vscode/src/lsp/CodeLensMiddleware.ts +++ b/clients/vscode/src/lsp/CodeLensMiddleware.ts @@ -113,7 +113,7 @@ export class CodeLensMiddleware implements VscodeLspCodeLensMiddleware { 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'})`; + const acceptShortcut = isBrowser ? "" : ` (${process.platform === "darwin" ? "⌘+Enter" : "Ctrl+Enter"})`; codeLens.command.title += acceptShortcut; } else if (codeLens.command?.arguments?.[0].action === "discard") {