refactor: move vscode dev options to agent config. (#283)
parent
920ff9d0fe
commit
62e0ea91d4
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -40,6 +40,10 @@ type AgentConfig = {
|
|||
server: {
|
||||
endpoint: string;
|
||||
};
|
||||
completion: {
|
||||
maxPrefixLines: number;
|
||||
maxSuffixLines: number;
|
||||
};
|
||||
logs: {
|
||||
level: "debug" | "error" | "silent";
|
||||
};
|
||||
|
|
@ -57,8 +61,8 @@ type CompletionRequest = {
|
|||
language: string;
|
||||
text: string;
|
||||
position: number;
|
||||
maxPrefixLines: number;
|
||||
maxSuffixLines: number;
|
||||
maxPrefixLines?: number;
|
||||
maxSuffixLines?: number;
|
||||
};
|
||||
type CompletionResponse = CompletionResponse$1;
|
||||
type LogEventRequest = LogEventRequest$1;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -850,6 +850,10 @@ var defaultAgentConfig = {
|
|||
server: {
|
||||
endpoint: "http://localhost:8080"
|
||||
},
|
||||
completion: {
|
||||
maxPrefixLines: 20,
|
||||
maxSuffixLines: 20
|
||||
},
|
||||
logs: {
|
||||
level: "silent"
|
||||
},
|
||||
|
|
@ -1256,8 +1260,8 @@ var _TabbyAgent = class extends import_events2.EventEmitter {
|
|||
});
|
||||
}
|
||||
createSegments(request2) {
|
||||
const maxPrefixLines = request2.maxPrefixLines;
|
||||
const maxSuffixLines = request2.maxSuffixLines;
|
||||
const maxPrefixLines = request2.maxPrefixLines ?? this.config.completion.maxPrefixLines;
|
||||
const maxSuffixLines = request2.maxSuffixLines ?? this.config.completion.maxSuffixLines;
|
||||
const prefix = request2.text.slice(0, request2.position);
|
||||
const prefixLines = splitLines(prefix);
|
||||
const suffix = request2.text.slice(request2.position);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -43811,6 +43811,10 @@ var defaultAgentConfig = {
|
|||
server: {
|
||||
endpoint: "http://localhost:8080"
|
||||
},
|
||||
completion: {
|
||||
maxPrefixLines: 20,
|
||||
maxSuffixLines: 20
|
||||
},
|
||||
logs: {
|
||||
level: "silent"
|
||||
},
|
||||
|
|
@ -45566,8 +45570,8 @@ var _TabbyAgent = class extends EventEmitter {
|
|||
});
|
||||
}
|
||||
createSegments(request2) {
|
||||
const maxPrefixLines = request2.maxPrefixLines;
|
||||
const maxSuffixLines = request2.maxSuffixLines;
|
||||
const maxPrefixLines = request2.maxPrefixLines ?? this.config.completion.maxPrefixLines;
|
||||
const maxSuffixLines = request2.maxSuffixLines ?? this.config.completion.maxSuffixLines;
|
||||
const prefix = request2.text.slice(0, request2.position);
|
||||
const prefixLines = splitLines(prefix);
|
||||
const suffix = request2.text.slice(request2.position);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -16,8 +16,8 @@ export type CompletionRequest = {
|
|||
language: string;
|
||||
text: string;
|
||||
position: number;
|
||||
maxPrefixLines: number;
|
||||
maxSuffixLines: number;
|
||||
maxPrefixLines?: number;
|
||||
maxSuffixLines?: number;
|
||||
};
|
||||
|
||||
export type CompletionResponse = ApiCompletionResponse;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ export type AgentConfig = {
|
|||
server: {
|
||||
endpoint: string;
|
||||
};
|
||||
completion: {
|
||||
maxPrefixLines: number;
|
||||
maxSuffixLines: number;
|
||||
};
|
||||
logs: {
|
||||
level: "debug" | "error" | "silent";
|
||||
};
|
||||
|
|
@ -16,6 +20,10 @@ export const defaultAgentConfig: AgentConfig = {
|
|||
server: {
|
||||
endpoint: "http://localhost:8080",
|
||||
},
|
||||
completion: {
|
||||
maxPrefixLines: 20,
|
||||
maxSuffixLines: 20,
|
||||
},
|
||||
logs: {
|
||||
level: "silent",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -129,8 +129,8 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
|||
|
||||
private createSegments(request: CompletionRequest): { prefix: string; suffix: string } {
|
||||
// max lines in prefix and suffix configurable
|
||||
const maxPrefixLines = request.maxPrefixLines;
|
||||
const maxSuffixLines = request.maxSuffixLines;
|
||||
const maxPrefixLines = request.maxPrefixLines ?? this.config.completion.maxPrefixLines;
|
||||
const maxSuffixLines = request.maxSuffixLines ?? this.config.completion.maxSuffixLines;
|
||||
const prefix = request.text.slice(0, request.position);
|
||||
const prefixLines = splitLines(prefix);
|
||||
const suffix = request.text.slice(request.position);
|
||||
|
|
|
|||
|
|
@ -44,11 +44,23 @@
|
|||
"command": "tabby.openSettings",
|
||||
"title": "Tabby: Open Settings"
|
||||
},
|
||||
{
|
||||
"command": "tabby.openTabbyAgentSettings",
|
||||
"title": "Tabby: Open Tabby Agent Settings"
|
||||
},
|
||||
{
|
||||
"command": "tabby.gettingStarted",
|
||||
"title": "Tabby: Getting Started"
|
||||
}
|
||||
],
|
||||
"menus": {
|
||||
"commandPalette": [
|
||||
{
|
||||
"command": "tabby.openTabbyAgentSettings",
|
||||
"when": "!isWeb"
|
||||
}
|
||||
]
|
||||
},
|
||||
"walkthroughs": [
|
||||
{
|
||||
"id": "gettingStarted",
|
||||
|
|
@ -83,7 +95,7 @@
|
|||
{
|
||||
"id": "commands",
|
||||
"title": "Commands",
|
||||
"description": "Type `>Tabby:` in quick open prompt to list all Tabby commands. \n[Tabby commands](command:workbench.action.quickOpen?%5B%22%3ETabby%3A%22%5D)",
|
||||
"description": "Type `>Tabby:` in command palette to list all Tabby commands. \n[Tabby commands](command:workbench.action.quickOpen?%5B%22%3ETabby%3A%22%5D)",
|
||||
"media": {
|
||||
"image": "assets/walkthroughs/commands.png",
|
||||
"altText": "Tabby Commands"
|
||||
|
|
@ -97,54 +109,16 @@
|
|||
"properties": {
|
||||
"tabby.api.endpoint": {
|
||||
"type": "string",
|
||||
"default": "http://localhost:8080",
|
||||
"format": "uri",
|
||||
"pattern": "^https?:\\/\\/[^\\s]+$",
|
||||
"default": "",
|
||||
"pattern": "(^$)|(^https?:\\/\\/\\S+$)",
|
||||
"patternErrorMessage": "Please enter a validate http or https URL.",
|
||||
"description": "Specify API Endpoint of Tabby."
|
||||
"markdownDescription": "Specify API Endpoint of Tabby. \nIf leave empty, server endpoint in [Tabby Agent Settings](command:tabby.openTabbyAgentSettings) will be used."
|
||||
},
|
||||
"tabby.codeCompletion": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Enable Tabby code completion or not."
|
||||
},
|
||||
"tabby.developerOptions": {
|
||||
"type": "object",
|
||||
"description": "Developer options for Tabby.",
|
||||
"properties": {
|
||||
"maxPrefixLines": {
|
||||
"type": "number",
|
||||
"default": 20,
|
||||
"description": "Number of lines to include in the Prefix for completion requests"
|
||||
},
|
||||
"maxSuffixLines": {
|
||||
"type": "number",
|
||||
"default": 20,
|
||||
"description": "Number of lines to include in the Suffix for completion requests"
|
||||
},
|
||||
"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,
|
||||
|
|
@ -190,7 +164,6 @@
|
|||
"webpack-cli": "^4.10.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sapphire/duration": "^1.1.0",
|
||||
"@xstate/fsm": "^2.0.1",
|
||||
"tabby-agent": "file:../tabby-agent"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
|||
|
||||
// User Settings
|
||||
private enabled: boolean = true;
|
||||
|
||||
// These settings will be move to tabby-agent
|
||||
private suggestionDelay: number = 150;
|
||||
private maxPrefixLines: number = 20;
|
||||
private maxSuffixLines: number = 20;
|
||||
|
|
@ -79,9 +81,6 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
|||
private updateConfiguration() {
|
||||
const configuration = workspace.getConfiguration("tabby");
|
||||
this.enabled = configuration.get("codeCompletion", true);
|
||||
this.suggestionDelay = configuration.get("developerOptions.suggestionDelay", 150);
|
||||
this.maxPrefixLines = configuration.get("developerOptions.maxPrefixLines", 20);
|
||||
this.maxSuffixLines = configuration.get("developerOptions.maxSuffixLines", 20);
|
||||
}
|
||||
|
||||
private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] {
|
||||
|
|
|
|||
|
|
@ -5,17 +5,11 @@ function getWorkspaceConfiguration(): Partial<AgentConfig> {
|
|||
const configuration = workspace.getConfiguration("tabby");
|
||||
const config: Partial<AgentConfig> = {};
|
||||
const endpoint = configuration.get<string>("api.endpoint");
|
||||
if (endpoint) {
|
||||
if (endpoint && endpoint.trim().length > 0) {
|
||||
config.server = {
|
||||
endpoint,
|
||||
};
|
||||
}
|
||||
const agentLogs = configuration.get<"debug" | "error" | "silent">("developerOptions.agent.logs");
|
||||
if (agentLogs) {
|
||||
config.logs = {
|
||||
level: agentLogs,
|
||||
};
|
||||
}
|
||||
const anonymousUsageTrackingDisabled = configuration.get<boolean>("usage.anonymousUsageTracking", false);
|
||||
config.anonymousUsageTracking = {
|
||||
disable: anonymousUsageTrackingDisabled,
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ import {
|
|||
ConfigurationTarget,
|
||||
InputBoxValidationSeverity,
|
||||
ProgressLocation,
|
||||
QuickPickItem,
|
||||
QuickPickItemKind,
|
||||
Uri,
|
||||
workspace,
|
||||
window,
|
||||
|
|
@ -11,7 +9,6 @@ import {
|
|||
commands,
|
||||
} from "vscode";
|
||||
import { strict as assert } from "assert";
|
||||
import { Duration } from "@sapphire/duration";
|
||||
import { CancelablePromise } from "tabby-agent";
|
||||
import { agent } from "./agent";
|
||||
import { notifications } from "./notifications";
|
||||
|
|
@ -34,67 +31,6 @@ const toggleEnabled: Command = {
|
|||
},
|
||||
};
|
||||
|
||||
const setSuggestionDelay: Command = {
|
||||
command: "tabby.setSuggestionDelay",
|
||||
callback: () => {
|
||||
const configuration = workspace.getConfiguration("tabby");
|
||||
const current = configuration.get("developerOptions.suggestionDelay", 150);
|
||||
const items = {
|
||||
Immediately: 0, // ms
|
||||
Default: 150,
|
||||
Slowly: 1000,
|
||||
};
|
||||
const createQuickPickItem = (value: number): QuickPickItem => {
|
||||
const tags: string[] = [];
|
||||
if (value == current) {
|
||||
tags.push("Current");
|
||||
}
|
||||
Object.entries(items).forEach(([k, v]) => {
|
||||
if (v == value) {
|
||||
tags.push(k);
|
||||
}
|
||||
});
|
||||
return {
|
||||
label: value % 1000 == 0 ? `${value / 1000}s` : `${value}ms`,
|
||||
description: tags.join(" "),
|
||||
alwaysShow: true,
|
||||
};
|
||||
};
|
||||
const buildQuickPickList = (input: string = "") => {
|
||||
const list: QuickPickItem[] = [];
|
||||
const customized = new Duration(input).offset || Number.parseInt(input);
|
||||
if (customized >= 0) {
|
||||
list.push(createQuickPickItem(customized));
|
||||
}
|
||||
if (current != customized) {
|
||||
list.push(createQuickPickItem(current));
|
||||
}
|
||||
list.push({
|
||||
label: "",
|
||||
kind: QuickPickItemKind.Separator,
|
||||
});
|
||||
Object.values(items)
|
||||
.filter((item) => item != current && item != customized)
|
||||
.forEach((item) => list.push(createQuickPickItem(item)));
|
||||
return list;
|
||||
};
|
||||
const quickPick = window.createQuickPick();
|
||||
quickPick.placeholder = "Enter the delay after which the completion request is sent";
|
||||
quickPick.matchOnDescription = true;
|
||||
quickPick.items = buildQuickPickList();
|
||||
quickPick.onDidChangeValue((input: string) => {
|
||||
quickPick.items = buildQuickPickList(input);
|
||||
});
|
||||
quickPick.onDidAccept(() => {
|
||||
quickPick.hide();
|
||||
const delay = new Duration(quickPick.selectedItems[0].label).offset;
|
||||
console.debug("Set suggestion delay: ", delay);
|
||||
configuration.update("developerOptions.suggestionDelay", delay, configTarget, false);
|
||||
});
|
||||
quickPick.show();
|
||||
},
|
||||
};
|
||||
|
||||
const setApiEndpoint: Command = {
|
||||
command: "tabby.setApiEndpoint",
|
||||
callback: () => {
|
||||
|
|
@ -132,6 +68,27 @@ const openSettings: Command = {
|
|||
},
|
||||
};
|
||||
|
||||
const openTabbyAgentSettings: Command = {
|
||||
command: "tabby.openTabbyAgentSettings",
|
||||
callback: () => {
|
||||
if (env.appHost !== "desktop") {
|
||||
window.showWarningMessage("Tabby Agent config file is not supported on web.", { modal: true });
|
||||
return;
|
||||
}
|
||||
const agentUserConfig = Uri.joinPath(Uri.file(require("os").homedir()), ".tabby", "agent", "config.toml");
|
||||
workspace.fs.stat(agentUserConfig).then(
|
||||
() => {
|
||||
workspace.openTextDocument(agentUserConfig).then((document) => {
|
||||
window.showTextDocument(document);
|
||||
});
|
||||
},
|
||||
() => {
|
||||
window.showWarningMessage("Tabby Agent config file not found.", { modal: true });
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
const gettingStarted: Command = {
|
||||
command: "tabby.gettingStarted",
|
||||
callback: () => {
|
||||
|
|
@ -219,8 +176,8 @@ export const tabbyCommands = () =>
|
|||
[
|
||||
toggleEnabled,
|
||||
setApiEndpoint,
|
||||
setSuggestionDelay,
|
||||
openSettings,
|
||||
openTabbyAgentSettings,
|
||||
gettingStarted,
|
||||
emitEvent,
|
||||
openAuthPage,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import { commands, window, workspace, ConfigurationTarget } from "vscode";
|
||||
|
||||
const configTarget = ConfigurationTarget.Global;
|
||||
import { commands, window } from "vscode";
|
||||
|
||||
function showInformationWhenLoading() {
|
||||
window.showInformationMessage("Tabby is initializing.", "Settings").then((selection) => {
|
||||
|
|
|
|||
|
|
@ -2527,9 +2527,9 @@ object-keys@^1.1.1:
|
|||
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==
|
||||
|
||||
object-sizeof@^2.6.1:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/object-sizeof/-/object-sizeof-2.6.1.tgz#1e2b6a01d182c268dbb07ee3403f539de45f63d3"
|
||||
integrity sha512-a7VJ1Zx7ZuHceKwjgfsSqzV/X0PVGvpZz7ho3Dn4Cs0LLcR5e5WuV+gsbizmplD8s0nAXMJmckKB2rkSiPm/Gg==
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/object-sizeof/-/object-sizeof-2.6.2.tgz#f162e4fc842115cf06253c89d287105b23ed055b"
|
||||
integrity sha512-yBcuQmJ/hezl+j6TaDxXzVYMRBFH2iJgkJWQz1nRh8t9JfFEcnZyqwEhJqVkpjnbQIJ2s7Xg4pSZxgQcEULgMA==
|
||||
dependencies:
|
||||
buffer "^6.0.3"
|
||||
|
||||
|
|
@ -2908,14 +2908,15 @@ readable-stream@^3.1.1, readable-stream@^3.4.0:
|
|||
util-deprecate "^1.0.1"
|
||||
|
||||
readable-stream@^4.0.0:
|
||||
version "4.4.1"
|
||||
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-4.4.1.tgz#fa0f0878c3bc0c12b6a82e4e58c5dc160e1faaa2"
|
||||
integrity sha512-llAHX9QC25bz5RPIoTeJxPaA/hgryaldValRhVZ2fK9bzbmFiscpz8fw6iBTvJfAk1w4FC1KXQme/nO7fbKyKg==
|
||||
version "4.4.2"
|
||||
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-4.4.2.tgz#e6aced27ad3b9d726d8308515b9a1b98dc1b9d13"
|
||||
integrity sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==
|
||||
dependencies:
|
||||
abort-controller "^3.0.0"
|
||||
buffer "^6.0.3"
|
||||
events "^3.3.0"
|
||||
process "^0.11.10"
|
||||
string_decoder "^1.3.0"
|
||||
|
||||
readdirp@~3.6.0:
|
||||
version "3.6.0"
|
||||
|
|
@ -3181,7 +3182,7 @@ string-width@^4.1.0, string-width@^4.2.0:
|
|||
is-fullwidth-code-point "^3.0.0"
|
||||
strip-ansi "^6.0.1"
|
||||
|
||||
string_decoder@^1.1.1:
|
||||
string_decoder@^1.1.1, string_decoder@^1.3.0:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
|
||||
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
|
||||
|
|
|
|||
Loading…
Reference in New Issue