Skip to content

Commit

Permalink
feat(vscode): reorganize settings (#2501)
Browse files Browse the repository at this point in the history
* feat(vscode): reorganize settings

* fix

* update

* clean
  • Loading branch information
wwayne authored Jun 25, 2024
1 parent 9d2a193 commit a0491f9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
39 changes: 20 additions & 19 deletions clients/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"commandPalette": [
{
"command": "tabby.inlineCompletion.trigger",
"when": "config.tabby.inlineCompletion.triggerMode === 'manual' && !editorHasSelection && !inlineSuggestionsVisible"
"when": "tabby.inlineCompletionTriggerMode === 'manual' && !editorHasSelection && !inlineSuggestionsVisible"
},
{
"command": "tabby.openTabbyAgentSettings",
Expand Down Expand Up @@ -234,26 +234,13 @@
{
"title": "Tabby",
"properties": {
"tabby.api.endpoint": {
"tabby.endpoint": {
"type": "string",
"default": "",
"pattern": "(^$)|(^https?:\\/\\/\\S+$)",
"patternErrorMessage": "Please enter a validate http or https URL.",
"markdownDescription": "Specify the API endpoint for the Tabby server. \nIf authentication is required, please [Set Credentials](command:tabby.setApiToken). \nIf left empty, the server endpoint specified in the [Tabby Agent Settings](command:tabby.openTabbyAgentSettings) will be used."
},
"tabby.inlineCompletion.triggerMode": {
"type": "string",
"enum": [
"automatic",
"manual"
],
"default": "automatic",
"description": "Select the code completion trigger mode.",
"enumDescriptions": [
"Automatic trigger when you stop typing",
"Manual trigger by pressing `Alt + \\`"
]
},
"tabby.keybindings": {
"type": "string",
"enum": [
Expand All @@ -263,14 +250,28 @@
"default": "vscode-style",
"markdownDescription": "Select the keybinding profile to accept inline completion. You can also customize it in [Keyboard Shortcuts](command:tabby.openKeybindings). \n | | Next Line | Full Completion | Next Word | \n |:---|:---|:---|:---| \n | _vscode-style_ | - | `Tab` | `Ctrl + RightArrow` (macOS: `Cmd + RightArrow`) | \n | _tabby-style_ _(experimental)_ | `Tab` | `Ctrl + Tab` | `Ctrl + RightArrow` (macOS: `Cmd + RightArrow`) | \n"
},
"tabby.usage.anonymousUsageTracking": {
"tabby.config.telemetry": {
"type": "boolean",
"default": false,
"markdownDescription": "**Disable anonymous usage tracking** \nTabby collects aggregated anonymous usage data and sends it to the Tabby team to help improve our products. \nYour code, generated completions, or any identifying information is never tracked or transmitted. \nFor more details on data collection, please check our [online documentation](https://tabby.tabbyml.com/docs/extensions/configurations#usage-collection)."
},
"tabby.experimental": {
"tabby.settings.advanced": {
"default": {},
"properties": {}
"properties": {
"inlineCompletion.triggerMode": {
"type": "string",
"enum": [
"automatic",
"manual"
],
"default": "automatic",
"description": "Select the code completion trigger mode.",
"enumDescriptions": [
"Automatic trigger when you stop typing",
"Manual trigger by pressing `Alt + \\`"
]
}
}
}
}
}
Expand All @@ -279,7 +280,7 @@
{
"key": "alt+\\",
"command": "tabby.inlineCompletion.trigger",
"when": "config.tabby.inlineCompletion.triggerMode === 'manual' && editorTextFocus && !editorHasSelection && !inlineSuggestionsVisible"
"when": "tabby.inlineCompletionTriggerMode === 'manual' && editorTextFocus && !editorHasSelection && !inlineSuggestionsVisible"
},
{
"command": "tabby.inlineCompletion.accept",
Expand Down
18 changes: 13 additions & 5 deletions clients/vscode/src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { EventEmitter } from "events";
import { workspace, ExtensionContext, WorkspaceConfiguration, ConfigurationTarget, Memento } from "vscode";
import { ClientProvidedConfig } from "tabby-agent";

interface AdvancedSettings {
"inlineCompletion.triggerMode"?: "automatic" | "manual";
}

export class Config extends EventEmitter {
constructor(private readonly context: ExtensionContext) {
super();
Expand All @@ -23,12 +27,12 @@ export class Config extends EventEmitter {
}

get serverEndpoint(): string {
return this.workspace.get("api.endpoint", "");
return this.workspace.get("endpoint", "");
}

set serverEndpoint(value: string) {
if (value !== this.serverEndpoint) {
this.workspace.update("api.endpoint", value, ConfigurationTarget.Global);
this.workspace.update("endpoint", value, ConfigurationTarget.Global);
}
}

Expand All @@ -44,12 +48,16 @@ export class Config extends EventEmitter {
}

get inlineCompletionTriggerMode(): "automatic" | "manual" {
return this.workspace.get("inlineCompletion.triggerMode", "automatic");
const advancedSettings = this.workspace.get("settings.advanced", {}) as AdvancedSettings;
return advancedSettings["inlineCompletion.triggerMode"] || "automatic";
}

set inlineCompletionTriggerMode(value: "automatic" | "manual") {
if (value !== this.inlineCompletionTriggerMode) {
this.workspace.update("inlineCompletion.triggerMode", value, ConfigurationTarget.Global);
const advancedSettings = this.workspace.get("settings.advanced", {}) as AdvancedSettings;
const updatedValue = { ...advancedSettings, "inlineCompletion.triggerMode": value };
this.workspace.update("settings.advanced", updatedValue, ConfigurationTarget.Global);
this.emit("updated");
}
}

Expand All @@ -68,7 +76,7 @@ export class Config extends EventEmitter {
}

get anonymousUsageTrackingDisabled(): boolean {
return this.workspace.get("usage.anonymousUsageTracking", false);
return this.workspace.get("config.telemetry", false);
}

get mutedNotifications(): string[] {
Expand Down
20 changes: 19 additions & 1 deletion clients/vscode/src/ContextVariables.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { commands, window, workspace, Range } from "vscode";
import { Client } from "./lsp/Client";
import { Config } from "./Config";

export class ContextVariables {
private chatEnabledValue = false;
private chatEditInProgressValue = false;
private chatEditResolvingValue = false;
private inlineCompletionTriggerModeValue: "automatic" | "manual" = "automatic";

constructor(private readonly client: Client) {
constructor(
private readonly client: Client,
private readonly config: Config,
) {
this.chatEnabled = this.client.chat.isAvailable;
this.inlineCompletionTriggerMode = config.inlineCompletionTriggerMode;
this.client.chat.on("didChangeAvailability", (params: boolean) => {
this.chatEnabled = params;
});
this.config.on("updated", () => {
this.inlineCompletionTriggerMode = config.inlineCompletionTriggerMode;
});
this.updateChatEditResolving();
window.onDidChangeTextEditorSelection((params) => {
if (params.textEditor === window.activeTextEditor) {
Expand Down Expand Up @@ -66,4 +75,13 @@ export class ContextVariables {
commands.executeCommand("setContext", "tabby.chatEditResolving", value);
this.chatEditResolvingValue = value;
}

get inlineCompletionTriggerMode(): "automatic" | "manual" {
return this.inlineCompletionTriggerModeValue;
}

set inlineCompletionTriggerMode(value: "automatic" | "manual") {
commands.executeCommand("setContext", "tabby.inlineCompletionTriggerMode", value);
this.inlineCompletionTriggerModeValue = value;
}
}
2 changes: 1 addition & 1 deletion clients/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function activate(context: ExtensionContext) {
);

const issues = new Issues(client, config);
const contextVariables = new ContextVariables(client);
const contextVariables = new ContextVariables(client, config);
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ /* @ts-expect-error noUnusedLocals */
const statusBarItem = new StatusBarItem(context, client, config, issues, inlineCompletionProvider);
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ /* @ts-expect-error noUnusedLocals */
Expand Down

0 comments on commit a0491f9

Please sign in to comment.