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
parent
3052ad4450
commit
61a885ddd8
|
|
@ -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[] {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue