-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vscode): use CommandPalette to display tabby menu (#2917)
* feat(vscode): use CommandPalette to display tabby menu * update * [autofix.ci] apply automated fixes * Apply suggestions from code review * update * Update clients/vscode/src/Commands.ts Co-authored-by: Zhiming Ma <[email protected]> * chore(vscode): display issues help message in CommandPalette * update label * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Zhiming Ma <[email protected]>
- Loading branch information
1 parent
af51b79
commit 8cdf6a5
Showing
5 changed files
with
159 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { commands, QuickPick, QuickPickItem, QuickPickItemKind, ThemeIcon, window } from "vscode"; | ||
import { State as LanguageClientState } from "vscode-languageclient"; | ||
import { Client } from "./lsp/Client"; | ||
import { Config } from "./Config"; | ||
import { Issues } from "./Issues"; | ||
|
||
export default class CommandPalette { | ||
quickPick: QuickPick<CommandPaletteItem>; | ||
|
||
constructor( | ||
private readonly client: Client, | ||
private readonly config: Config, | ||
private readonly issues: Issues, | ||
) { | ||
this.quickPick = window.createQuickPick(); | ||
this.quickPick.title = "Tabby Command Palette"; | ||
|
||
let items: CommandPaletteItem[] = [this.itemForStatus()]; | ||
|
||
if (this.client.chat.isAvailable) { | ||
items.push({ | ||
label: "Chat", | ||
command: "tabby.chatView.focus", | ||
iconPath: new ThemeIcon("comment"), | ||
}); | ||
} | ||
|
||
items = items.concat([ | ||
{ | ||
label: "", | ||
kind: QuickPickItemKind.Separator, | ||
}, | ||
{ | ||
label: this.config.inlineCompletionTriggerMode === "manual" ? "Enable Completions" : "Disable Completions", | ||
command: "tabby.toggleInlineCompletionTriggerMode", | ||
}, | ||
{ | ||
label: "", | ||
kind: QuickPickItemKind.Separator, | ||
}, | ||
{ | ||
label: "Set Credentials", | ||
command: "tabby.setApiToken", | ||
iconPath: new ThemeIcon("key"), | ||
}, | ||
{ | ||
label: "Settings...", | ||
command: "tabby.openSettings", | ||
iconPath: new ThemeIcon("extensions-manage"), | ||
}, | ||
{ | ||
label: "Agent Settings...", | ||
command: "tabby.openTabbyAgentSettings", | ||
iconPath: new ThemeIcon("console"), | ||
}, | ||
{ | ||
label: "Show Logs...", | ||
command: "tabby.outputPanel.focus", | ||
}, | ||
{ | ||
label: "", | ||
kind: QuickPickItemKind.Separator, | ||
}, | ||
{ | ||
label: "Help", | ||
command: "tabby.openOnlineHelp", | ||
iconPath: new ThemeIcon("question"), | ||
}, | ||
]); | ||
|
||
this.quickPick.items = items; | ||
this.quickPick.onDidAccept(this.onDidAccept, this); | ||
this.quickPick.show(); | ||
} | ||
|
||
onDidAccept() { | ||
this.quickPick.hide(); | ||
const item = this.quickPick.activeItems[0]; | ||
if (item?.command) { | ||
if (typeof item.command === "function") { | ||
item.command(); | ||
} else { | ||
commands.executeCommand(item.command); | ||
} | ||
} | ||
} | ||
|
||
private itemForStatus(): CommandPaletteItem { | ||
const lspState = this.client.languageClient.state; | ||
const agentStatus = this.client.agent.status; | ||
const item: CommandPaletteItem = { | ||
label: "Status", | ||
iconPath: new ThemeIcon("warning"), | ||
}; | ||
if (lspState === LanguageClientState.Starting || agentStatus === "notInitialized") { | ||
item.label = "Starting..."; | ||
item.iconPath = new ThemeIcon("sync"); | ||
} else if (lspState === LanguageClientState.Stopped || agentStatus === "finalized") { | ||
item.label = "Disabled"; | ||
item.iconPath = new ThemeIcon("circle-slash"); | ||
} else if (agentStatus === "disconnected" || this.issues.first === "connectionFailed") { | ||
item.label = "Disconnected"; | ||
item.description = "Cannot connect to Tabby Server"; | ||
item.command = "tabby.openSettings"; | ||
} else if (agentStatus === "unauthorized") { | ||
item.label = "Unauthorized"; | ||
item.description = "Your credentials are invalid"; | ||
item.command = "tabby.setApiToken"; | ||
} else if (this.issues.length > 0) { | ||
switch (this.issues.first) { | ||
case "highCompletionTimeoutRate": | ||
item.label = "Timeout"; | ||
item.description = "Most completion requests timed out."; | ||
break; | ||
case "slowCompletionResponseTime": | ||
item.label = "Slow Response"; | ||
item.description = "Completion requests appear to take too much time."; | ||
break; | ||
} | ||
item.command = () => this.issues.showHelpMessage(); | ||
} else if (agentStatus === "ready") { | ||
item.label = "Ready"; | ||
item.iconPath = new ThemeIcon("check"); | ||
item.command = "tabby.outputPanel.focus"; | ||
} | ||
|
||
return item; | ||
} | ||
} | ||
|
||
interface CommandPaletteItem extends QuickPickItem { | ||
command?: string | CallbackCommand; | ||
} | ||
|
||
type CallbackCommand = () => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters