Added suggestion delay setting and command to vscode extension. (#106)
* Added suggestion delay setting and command. * Formatted with prettier * Removed yarn local dependencyadd-tracing
parent
ac6637bdbb
commit
dc88f03a1f
|
|
@ -33,6 +33,10 @@
|
||||||
"command": "tabby.setServerUrl",
|
"command": "tabby.setServerUrl",
|
||||||
"title": "Tabby: Set URL of Tabby Server"
|
"title": "Tabby: Set URL of Tabby Server"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "tabby.setSuggestionDelay",
|
||||||
|
"title": "Tabby: Set suggestion delay"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "tabby.openSettings",
|
"command": "tabby.openSettings",
|
||||||
"title": "Tabby: Open Settings"
|
"title": "Tabby: Open Settings"
|
||||||
|
|
@ -50,6 +54,11 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "http://127.0.0.1:5000",
|
"default": "http://127.0.0.1:5000",
|
||||||
"markdownDescription": "Specifies the url of [Tabby Server](https://github.com/TabbyML/tabby)."
|
"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)."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 = {
|
const setServerUrl: Command = {
|
||||||
command: "tabby.setServerUrl",
|
command: "tabby.setServerUrl",
|
||||||
callback: () => {
|
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)
|
commands.registerCommand(command.command, command.callback, command.thisArg)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
||||||
private tabbyClient = TabbyClient.getInstance();
|
private tabbyClient = TabbyClient.getInstance();
|
||||||
// User Settings
|
// User Settings
|
||||||
private enabled: boolean = true;
|
private enabled: boolean = true;
|
||||||
|
private suggestionDelay: number = 150;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.updateConfiguration();
|
this.updateConfiguration();
|
||||||
|
|
@ -49,8 +50,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
||||||
const currentTimestamp = Date.now();
|
const currentTimestamp = Date.now();
|
||||||
this.latestTimestamp = currentTimestamp;
|
this.latestTimestamp = currentTimestamp;
|
||||||
|
|
||||||
const suggestionDelay = 150;
|
await sleep(this.suggestionDelay);
|
||||||
await sleep(suggestionDelay);
|
|
||||||
if (currentTimestamp < this.latestTimestamp) {
|
if (currentTimestamp < this.latestTimestamp) {
|
||||||
return emptyResponse;
|
return emptyResponse;
|
||||||
}
|
}
|
||||||
|
|
@ -94,6 +94,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
||||||
private updateConfiguration() {
|
private updateConfiguration() {
|
||||||
const configuration = workspace.getConfiguration("tabby");
|
const configuration = workspace.getConfiguration("tabby");
|
||||||
this.enabled = configuration.get("enabled", true);
|
this.enabled = configuration.get("enabled", true);
|
||||||
|
this.suggestionDelay = configuration.get("suggestionDelay", 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getPrompt(document: TextDocument, position: Position): string | undefined {
|
private getPrompt(document: TextDocument, position: Position): string | undefined {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue