From dc88f03a1ff9901bc05299a8e869c41c144b6c57 Mon Sep 17 00:00:00 2001 From: TheEmber <40074315+TheEmber@users.noreply.github.com> Date: Mon, 17 Apr 2023 04:12:16 +0300 Subject: [PATCH] Added suggestion delay setting and command to vscode extension. (#106) * Added suggestion delay setting and command. * Formatted with prettier * Removed yarn local dependency --- clients/vscode/package.json | 9 ++++++ clients/vscode/src/Commands.ts | 29 ++++++++++++++++++- clients/vscode/src/TabbyCompletionProvider.ts | 5 ++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/clients/vscode/package.json b/clients/vscode/package.json index f3cc5c7..2688c7a 100644 --- a/clients/vscode/package.json +++ b/clients/vscode/package.json @@ -33,6 +33,10 @@ "command": "tabby.setServerUrl", "title": "Tabby: Set URL of Tabby Server" }, + { + "command": "tabby.setSuggestionDelay", + "title": "Tabby: Set suggestion delay" + }, { "command": "tabby.openSettings", "title": "Tabby: Open Settings" @@ -50,6 +54,11 @@ "type": "string", "default": "http://127.0.0.1:5000", "markdownDescription": "Specifies the url of [Tabby Server](https://github.com/TabbyML/tabby)." + }, + "tabby.suggestionDelay": { + "type": "number", + "default": 150, + "markdownDescription": "Specifies the delay after which the request is sent to the tabby(ms)." } } } diff --git a/clients/vscode/src/Commands.ts b/clients/vscode/src/Commands.ts index bcd92cf..61050d3 100644 --- a/clients/vscode/src/Commands.ts +++ b/clients/vscode/src/Commands.ts @@ -20,6 +20,33 @@ const toogleEnabled: Command = { }, }; +const setSuggestionDelay: Command = { + command: "tabby.setSuggestionDelay", + callback: () => { + const configuration = workspace.getConfiguration("tabby"); + window + .showInputBox({ + prompt: "Enter the suggestion delay in ms", + value: configuration.get("suggestionDelay", "150"), + }) + .then((delay) => { + if (delay) { + if (Number.parseInt(delay) !== null) { + console.debug("Set suggestion delay: ", Number.parseInt(delay)); + configuration.update( + "suggestionDelay", + Number.parseInt(delay), + target, + false + ); + } else { + console.debug("Set suggestion delay error. Wrong input."); + } + } + }); + }, +}; + const setServerUrl: Command = { command: "tabby.setServerUrl", callback: () => { @@ -59,6 +86,6 @@ const emitEvent: Command = { }, }; -export const tabbyCommands = [toogleEnabled, setServerUrl, openSettings, emitEvent].map((command) => +export const tabbyCommands = [toogleEnabled, setServerUrl, setSuggestionDelay, openSettings, emitEvent].map((command) => commands.registerCommand(command.command, command.callback, command.thisArg) ); diff --git a/clients/vscode/src/TabbyCompletionProvider.ts b/clients/vscode/src/TabbyCompletionProvider.ts index 8098cd9..8b668d7 100644 --- a/clients/vscode/src/TabbyCompletionProvider.ts +++ b/clients/vscode/src/TabbyCompletionProvider.ts @@ -21,6 +21,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider { private tabbyClient = TabbyClient.getInstance(); // User Settings private enabled: boolean = true; + private suggestionDelay: number = 150; constructor() { this.updateConfiguration(); @@ -49,8 +50,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider { const currentTimestamp = Date.now(); this.latestTimestamp = currentTimestamp; - const suggestionDelay = 150; - await sleep(suggestionDelay); + await sleep(this.suggestionDelay); if (currentTimestamp < this.latestTimestamp) { return emptyResponse; } @@ -94,6 +94,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider { private updateConfiguration() { const configuration = workspace.getConfiguration("tabby"); this.enabled = configuration.get("enabled", true); + this.suggestionDelay = configuration.get("suggestionDelay", 150); } private getPrompt(document: TextDocument, position: Position): string | undefined {