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.
release-0.0
Zhiming Ma 2023-08-10 15:57:59 +08:00 committed by GitHub
parent 3052ad4450
commit 61a885ddd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 15 deletions

View File

@ -12,6 +12,7 @@ import {
} from "vscode"; } from "vscode";
import { CompletionResponse, CancelablePromise } from "tabby-agent"; import { CompletionResponse, CancelablePromise } from "tabby-agent";
import { agent } from "./agent"; import { agent } from "./agent";
import { notifications } from "./notifications";
import { sleep } from "./utils"; import { sleep } from "./utils";
export class TabbyCompletionProvider implements InlineCompletionItemProvider { export class TabbyCompletionProvider implements InlineCompletionItemProvider {
@ -30,7 +31,7 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
constructor() { constructor() {
this.updateConfiguration(); this.updateConfiguration();
workspace.onDidChangeConfiguration((event) => { workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration("tabby")) { if (event.affectsConfiguration("tabby") || event.affectsConfiguration("editor.inlineSuggest")) {
this.updateConfiguration(); this.updateConfiguration();
} }
}); });
@ -81,6 +82,16 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
private updateConfiguration() { private updateConfiguration() {
const configuration = workspace.getConfiguration("tabby"); const configuration = workspace.getConfiguration("tabby");
this.enabled = configuration.get("codeCompletion", true); 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[] { private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] {

View File

@ -175,7 +175,13 @@ const statusBarItemClicked: Command = {
notifications.showInformationStartAuth(); notifications.showInformationStartAuth();
break; break;
case "disabled": case "disabled":
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(); notifications.showInformationWhenDisabled();
}
break; break;
} }
}, },

View File

@ -1,4 +1,4 @@
import { commands, window } from "vscode"; import { commands, window, workspace, ConfigurationTarget } from "vscode";
function showInformationWhenLoading() { function showInformationWhenLoading() {
window.showInformationMessage("Tabby is initializing.", "Settings").then((selection) => { window.showInformationMessage("Tabby is initializing.", "Settings").then((selection) => {
@ -11,7 +11,9 @@ function showInformationWhenLoading() {
} }
function showInformationWhenDisabled() { function showInformationWhenDisabled() {
window.showInformationMessage("Tabby is disabled. Enable it?", "Enable", "Settings").then((selection) => { window
.showInformationMessage("Tabby code completion is disabled. Enable it?", "Enable", "Settings")
.then((selection) => {
switch (selection) { switch (selection) {
case "Enable": case "Enable":
commands.executeCommand("tabby.toggleEnabled"); commands.executeCommand("tabby.toggleEnabled");
@ -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 = { export const notifications = {
showInformationWhenLoading, showInformationWhenLoading,
showInformationWhenDisabled, showInformationWhenDisabled,
@ -95,4 +118,5 @@ export const notifications = {
showInformationAuthSuccess, showInformationAuthSuccess,
showInformationWhenStartAuthButAlreadyAuthorized, showInformationWhenStartAuthButAlreadyAuthorized,
showInformationWhenAuthFailed, showInformationWhenAuthFailed,
showInformationWhenInlineSuggestDisabled,
}; };

View File

@ -103,7 +103,8 @@ function toDisabled() {
function updateStatusBarItem() { function updateStatusBarItem() {
const enabled = workspace.getConfiguration("tabby").get("codeCompletion", true); 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"); fsmService.send("disabled");
} else { } else {
const status = agent().getStatus(); const status = agent().getStatus();
@ -125,7 +126,7 @@ export const tabbyStatusBarItem = () => {
updateStatusBarItem(); updateStatusBarItem();
workspace.onDidChangeConfiguration((event) => { workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration("tabby")) { if (event.affectsConfiguration("tabby") || event.affectsConfiguration("editor.inlineSuggest")) {
updateStatusBarItem(); updateStatusBarItem();
} }
}); });