From 61a885ddd881016e4f57bce456d7b9fda51fc246 Mon Sep 17 00:00:00 2001 From: Zhiming Ma Date: Thu, 10 Aug 2023 15:57:59 +0800 Subject: [PATCH] fix(vscode): will show warning if editor inline suggest is disabled. (#348) * fix(vscode): will show warning if editor inline suggest is disabled. * fix(vscode): update notification message when inline suggest disabled. --- clients/vscode/src/TabbyCompletionProvider.ts | 13 +++++- clients/vscode/src/commands.ts | 8 +++- clients/vscode/src/notifications.ts | 46 ++++++++++++++----- clients/vscode/src/statusBarItem.ts | 5 +- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/clients/vscode/src/TabbyCompletionProvider.ts b/clients/vscode/src/TabbyCompletionProvider.ts index c4742f8..30bd8d6 100644 --- a/clients/vscode/src/TabbyCompletionProvider.ts +++ b/clients/vscode/src/TabbyCompletionProvider.ts @@ -12,6 +12,7 @@ import { } from "vscode"; import { CompletionResponse, CancelablePromise } from "tabby-agent"; import { agent } from "./agent"; +import { notifications } from "./notifications"; import { sleep } from "./utils"; export class TabbyCompletionProvider implements InlineCompletionItemProvider { @@ -30,7 +31,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider { constructor() { this.updateConfiguration(); workspace.onDidChangeConfiguration((event) => { - if (event.affectsConfiguration("tabby")) { + if (event.affectsConfiguration("tabby") || event.affectsConfiguration("editor.inlineSuggest")) { this.updateConfiguration(); } }); @@ -81,6 +82,16 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider { private updateConfiguration() { const configuration = workspace.getConfiguration("tabby"); this.enabled = configuration.get("codeCompletion", true); + this.checkInlineCompletionEnabled(); + } + + private checkInlineCompletionEnabled() { + const configuration = workspace.getConfiguration("editor.inlineSuggest"); + const inlineSuggestEnabled = configuration.get("enabled", true); + if (this.enabled && !inlineSuggestEnabled) { + console.debug("Tabby code completion is enabled but inline suggest is disabled."); + notifications.showInformationWhenInlineSuggestDisabled(); + } } private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] { diff --git a/clients/vscode/src/commands.ts b/clients/vscode/src/commands.ts index 1960a5c..4b38d04 100644 --- a/clients/vscode/src/commands.ts +++ b/clients/vscode/src/commands.ts @@ -175,7 +175,13 @@ const statusBarItemClicked: Command = { notifications.showInformationStartAuth(); break; case "disabled": - notifications.showInformationWhenDisabled(); + const enabled = workspace.getConfiguration("tabby").get("codeCompletion", true); + const inlineSuggestEnabled = workspace.getConfiguration("editor").get("inlineSuggest.enabled", true); + if (enabled && !inlineSuggestEnabled) { + notifications.showInformationWhenInlineSuggestDisabled(); + } else { + notifications.showInformationWhenDisabled(); + } break; } }, diff --git a/clients/vscode/src/notifications.ts b/clients/vscode/src/notifications.ts index e039219..3af5e4c 100644 --- a/clients/vscode/src/notifications.ts +++ b/clients/vscode/src/notifications.ts @@ -1,4 +1,4 @@ -import { commands, window } from "vscode"; +import { commands, window, workspace, ConfigurationTarget } from "vscode"; function showInformationWhenLoading() { window.showInformationMessage("Tabby is initializing.", "Settings").then((selection) => { @@ -11,16 +11,18 @@ function showInformationWhenLoading() { } function showInformationWhenDisabled() { - window.showInformationMessage("Tabby is disabled. Enable it?", "Enable", "Settings").then((selection) => { - switch (selection) { - case "Enable": - commands.executeCommand("tabby.toggleEnabled"); - break; - case "Settings": - commands.executeCommand("tabby.openSettings"); - break; - } - }); + window + .showInformationMessage("Tabby code completion is disabled. Enable it?", "Enable", "Settings") + .then((selection) => { + switch (selection) { + case "Enable": + commands.executeCommand("tabby.toggleEnabled"); + break; + case "Settings": + commands.executeCommand("tabby.openSettings"); + break; + } + }); } function showInformationWhenReady() { @@ -86,6 +88,27 @@ function showInformationWhenAuthFailed() { }); } +function showInformationWhenInlineSuggestDisabled() { + window + .showWarningMessage( + "Tabby's suggestion is not showing because inline suggestion is disabled. Please enable it first.", + "Enable", + "Settings", + ) + .then((selection) => { + switch (selection) { + case "Enable": + const configuration = workspace.getConfiguration("editor"); + console.debug(`Set editor.inlineSuggest.enabled: true.`); + configuration.update("inlineSuggest.enabled", true, ConfigurationTarget.Global, false); + break; + case "Settings": + commands.executeCommand("workbench.action.openSettings", "@id:editor.inlineSuggest.enabled"); + break; + } + }); +} + export const notifications = { showInformationWhenLoading, showInformationWhenDisabled, @@ -95,4 +118,5 @@ export const notifications = { showInformationAuthSuccess, showInformationWhenStartAuthButAlreadyAuthorized, showInformationWhenAuthFailed, + showInformationWhenInlineSuggestDisabled, }; diff --git a/clients/vscode/src/statusBarItem.ts b/clients/vscode/src/statusBarItem.ts index dccd751..6d8c389 100644 --- a/clients/vscode/src/statusBarItem.ts +++ b/clients/vscode/src/statusBarItem.ts @@ -103,7 +103,8 @@ function toDisabled() { function updateStatusBarItem() { const enabled = workspace.getConfiguration("tabby").get("codeCompletion", true); - if (!enabled) { + const inlineSuggestEnabled = workspace.getConfiguration("editor").get("inlineSuggest.enabled", true); + if (!enabled || !inlineSuggestEnabled) { fsmService.send("disabled"); } else { const status = agent().getStatus(); @@ -125,7 +126,7 @@ export const tabbyStatusBarItem = () => { updateStatusBarItem(); workspace.onDidChangeConfiguration((event) => { - if (event.affectsConfiguration("tabby")) { + if (event.affectsConfiguration("tabby") || event.affectsConfiguration("editor.inlineSuggest")) { updateStatusBarItem(); } });