From 7597ec6097ae82cc1d78e8bd2afe2f5a7a573fe4 Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Sat, 17 Jun 2023 03:54:30 +0800 Subject: [PATCH] refactor: VSCode Extension Settings cleanup. (#248) * refactor: VSCode Extension Settings cleanup. * fix: vscode extension update settings naming. --- clients/vscode/package.json | 72 ++++++++++--------- clients/vscode/src/TabbyCompletionProvider.ts | 4 +- clients/vscode/src/agent.ts | 12 ++-- clients/vscode/src/commands.ts | 20 +++--- clients/vscode/src/statusBarItem.ts | 2 +- 5 files changed, 59 insertions(+), 51 deletions(-) diff --git a/clients/vscode/package.json b/clients/vscode/package.json index 0dee71c..e9c2482 100644 --- a/clients/vscode/package.json +++ b/clients/vscode/package.json @@ -2,7 +2,7 @@ "name": "vscode-tabby", "publisher": "TabbyML", "displayName": "Tabby", - "description": "Get completions from Tabby server", + "description": "Tabby is a self-hosted AI coding assistant that can suggest multi-line code or full functions in real-time.", "repository": "https://github.com/TabbyML/tabby", "version": "0.0.6", "keywords": [ @@ -30,12 +30,8 @@ "title": "Tabby: Toggle Code Suggestion On/Off" }, { - "command": "tabby.setServerUrl", - "title": "Tabby: Set URL of Tabby Server" - }, - { - "command": "tabby.setSuggestionDelay", - "title": "Tabby: Set suggestion delay" + "command": "tabby.setApiEndpoint", + "title": "Tabby: Specify API Endpoint of Tabby" }, { "command": "tabby.openSettings", @@ -45,38 +41,50 @@ "configuration": { "title": "Tabby", "properties": { - "tabby.enabled": { - "type": "boolean", - "default": true, - "description": "Enable Tabby code suggestion or not." - }, - "tabby.serverUrl": { + "tabby.api.endpoint": { "type": "string", - "default": "http://127.0.0.1:8080", + "default": "http://localhost:8080", + "format": "uri", "pattern": "^https?:\\/\\/[^\\s]+$", "patternErrorMessage": "Please enter a validate http or https URL.", - "markdownDescription": "Specifies the url of [Tabby Server](https://github.com/TabbyML/tabby)." + "description": "Specify API Endpoint of Tabby." }, - "tabby.disableAnonymousUsageTracking": { + "tabby.codeCompletion": { + "type": "boolean", + "default": true, + "description": "Enable Tabby code completion or not." + }, + "tabby.developerOptions": { + "type": "object", + "description": "Developer options for Tabby.", + "properties": { + "suggestionDelay": { + "type": "number", + "default": 150, + "minimum": 0, + "description": "Specifies the delay in milliseconds after which the request is sent to the tabby." + }, + "agent": { + "type": "object", + "properties": { + "logs": { + "type": "string", + "enum": [ + "debug", + "error", + "silent" + ], + "default": "error", + "markdownDescription": "Specifies the log level for tabby-agent." + } + } + } + } + }, + "tabby.usage.anonymousUsageTracking": { "type": "boolean", "default": false, "description": "Disable anonymous usage tracking." - }, - "tabby.suggestionDelay": { - "type": "number", - "default": 150, - "minimum": 0, - "description": "Specifies the delay in milliseconds after which the request is sent to the tabby." - }, - "tabby.agentLogs": { - "type": "string", - "enum": [ - "debug", - "error", - "silent" - ], - "default": "error", - "markdownDescription": "Specifies the log level of tabby-agent for debugging purpose. \n * If VSCode is running as desktop application, you can find log files in `$HOME/.tabby/agent-logs/`. It's recommend using `tail -f ~/.tabby/agent-logs/tabby-agent.log | npx pino-pretty` to monitor logs. \n * If VSCode is running in browser, you can find logs in debug console. " } } } diff --git a/clients/vscode/src/TabbyCompletionProvider.ts b/clients/vscode/src/TabbyCompletionProvider.ts index 3450bb7..e1ebf27 100644 --- a/clients/vscode/src/TabbyCompletionProvider.ts +++ b/clients/vscode/src/TabbyCompletionProvider.ts @@ -74,8 +74,8 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider { private updateConfiguration() { const configuration = workspace.getConfiguration("tabby"); - this.enabled = configuration.get("enabled", true); - this.suggestionDelay = configuration.get("suggestionDelay", 150); + this.enabled = configuration.get("codeCompletion", true); + this.suggestionDelay = configuration.get("developerOptions.suggestionDelay", 150); } private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] { diff --git a/clients/vscode/src/agent.ts b/clients/vscode/src/agent.ts index b948c8b..dbc24de 100644 --- a/clients/vscode/src/agent.ts +++ b/clients/vscode/src/agent.ts @@ -4,21 +4,21 @@ import { TabbyAgent, AgentConfig, DataStore } from "tabby-agent"; function getWorkspaceConfiguration(): Partial { const configuration = workspace.getConfiguration("tabby"); const config: Partial = {}; - const serverUrl = configuration.get("serverUrl"); - if (serverUrl) { + const endpoint = configuration.get("api.endpoint"); + if (endpoint) { config.server = { - endpoint: serverUrl, + endpoint, }; } - const agentLogs = configuration.get<"debug" | "error" | "silent">("agentLogs"); + const agentLogs = configuration.get<"debug" | "error" | "silent">("developerOptions.agent.logs"); if (agentLogs) { config.logs = { level: agentLogs, }; } - const disableAnonymousUsageTracking = configuration.get("disableAnonymousUsageTracking", false); + const anonymousUsageTrackingDisabled = configuration.get("usage.anonymousUsageTracking", false); config.anonymousUsageTracking = { - disable: disableAnonymousUsageTracking, + disable: anonymousUsageTrackingDisabled, }; return config; } diff --git a/clients/vscode/src/commands.ts b/clients/vscode/src/commands.ts index 21e20d2..9a6e76b 100644 --- a/clients/vscode/src/commands.ts +++ b/clients/vscode/src/commands.ts @@ -26,9 +26,9 @@ const toggleEnabled: Command = { command: "tabby.toggleEnabled", callback: () => { const configuration = workspace.getConfiguration("tabby"); - const enabled = configuration.get("enabled", true); + const enabled = configuration.get("codeCompletion", true); console.debug(`Toggle Enabled: ${enabled} -> ${!enabled}.`); - configuration.update("enabled", !enabled, configTarget, false); + configuration.update("codeCompletion", !enabled, configTarget, false); }, }; @@ -36,7 +36,7 @@ const setSuggestionDelay: Command = { command: "tabby.setSuggestionDelay", callback: () => { const configuration = workspace.getConfiguration("tabby"); - const current = configuration.get("suggestionDelay", 150); + const current = configuration.get("developerOptions.suggestionDelay", 150); const items = { Immediately: 0, // ms Default: 150, @@ -87,20 +87,20 @@ const setSuggestionDelay: Command = { quickPick.hide(); const delay = new Duration(quickPick.selectedItems[0].label).offset; console.debug("Set suggestion delay: ", delay); - configuration.update("suggestionDelay", delay, configTarget, false); + configuration.update("developerOptions.suggestionDelay", delay, configTarget, false); }); quickPick.show(); }, }; -const setServerUrl: Command = { - command: "tabby.setServerUrl", +const setApiEndpoint: Command = { + command: "tabby.setApiEndpoint", callback: () => { const configuration = workspace.getConfiguration("tabby"); window .showInputBox({ prompt: "Enter the URL of your Tabby Server", - value: configuration.get("serverUrl", ""), + value: configuration.get("api.endpoint", ""), validateInput: (input: string) => { try { let url = new URL(input); @@ -117,7 +117,7 @@ const setServerUrl: Command = { .then((url) => { if (url) { console.debug("Set Tabby Server URL: ", url); - configuration.update("serverUrl", url, configTarget, false); + configuration.update("api.endpoint", url, configTarget, false); } }); }, @@ -126,7 +126,7 @@ const setServerUrl: Command = { const openSettings: Command = { command: "tabby.openSettings", callback: () => { - commands.executeCommand("workbench.action.openSettings", "tabby"); + commands.executeCommand("workbench.action.openSettings", "@ext:TabbyML.vscode-tabby"); }, }; @@ -178,6 +178,6 @@ const statusBarItemClicked: Command = { }; export const tabbyCommands = () => - [toggleEnabled, setServerUrl, setSuggestionDelay, openSettings, emitEvent, openAuthPage, statusBarItemClicked].map( + [toggleEnabled, setApiEndpoint, setSuggestionDelay, openSettings, emitEvent, openAuthPage, statusBarItemClicked].map( (command) => commands.registerCommand(command.command, command.callback, command.thisArg) ); diff --git a/clients/vscode/src/statusBarItem.ts b/clients/vscode/src/statusBarItem.ts index ec6bfde..f7fa1f4 100644 --- a/clients/vscode/src/statusBarItem.ts +++ b/clients/vscode/src/statusBarItem.ts @@ -92,7 +92,7 @@ function toDisabled() { } function updateStatusBarItem() { - const enabled = workspace.getConfiguration("tabby").get("enabled", true); + const enabled = workspace.getConfiguration("tabby").get("codeCompletion", true); if (!enabled) { fsmService.send("disabled"); } else {