mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
feat(extension): Improve undetectable warning box
This commit is contained in:
parent
c2f7de5f13
commit
cc82080cc1
7
vs-code-extension/src/events/on-language-detected.ts
Normal file
7
vs-code-extension/src/events/on-language-detected.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { GenericNotificationHandler } from "vscode-languageclient";
|
||||
import { tempUndetectableFiles } from "./shared";
|
||||
|
||||
export const onDetectable: GenericNotificationHandler = async (params: LSPLanguageDetected) => {
|
||||
tempUndetectableFiles.add(params.Uri);
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
import { GenericNotificationHandler } from "vscode-languageclient";
|
||||
import * as vscode from "vscode";
|
||||
import { tempUndetectableFiles, undetectableIgnoredFiles } from "./shared";
|
||||
|
||||
const ACTION_SELECT_LANGUAGE = "Select Language";
|
||||
const ACTION_DISABLE = "Ignore for this file";
|
||||
|
||||
const ignoredFiled = new Set<string>();
|
||||
|
||||
export const onUndetectable: GenericNotificationHandler = async (params: LSPLanguageUndetectable) => {
|
||||
if (ignoredFiled.has(params.Uri)) {
|
||||
export const onLanguageUndetectable: GenericNotificationHandler = async (params: LSPLanguageUndetectable) => {
|
||||
if (undetectableIgnoredFiles.has(params.Uri) || tempUndetectableFiles.has(params.Uri)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tempUndetectableFiles.add(params.Uri);
|
||||
|
||||
const result = await vscode.window.showWarningMessage(
|
||||
"config-lsp was unable to detect the appropriate language for this file",
|
||||
{
|
||||
@ -25,9 +26,7 @@ export const onUndetectable: GenericNotificationHandler = async (params: LSPLang
|
||||
vscode.commands.executeCommand("workbench.action.editor.changeLanguageMode");
|
||||
break;
|
||||
case ACTION_DISABLE:
|
||||
ignoredFiled.add(params.Uri);
|
||||
break;
|
||||
undefined:
|
||||
undetectableIgnoredFiles.add(params.Uri);
|
||||
break;
|
||||
}
|
||||
}
|
13
vs-code-extension/src/events/shared.ts
Normal file
13
vs-code-extension/src/events/shared.ts
Normal file
@ -0,0 +1,13 @@
|
||||
// config-lsp constantly sends a undetectable message for each LSP request.
|
||||
// This gets annoying to users quickly as they will be spammed with error messages.
|
||||
// To avoid this, we temporarily ignore files that have sent an undetectable message.
|
||||
//
|
||||
// This will be cleared once the language has been detected.
|
||||
// This is different from `undetectableIgnoredFiles`.
|
||||
// When a user selects "Ignore for this file", we will add the file to `undetectableIgnoredFiles`.
|
||||
// Then, we **never** show a warning for that file again.
|
||||
export const tempUndetectableFiles = new Set<string>();
|
||||
|
||||
export const undetectableIgnoredFiles = new Set<string>();
|
||||
|
||||
|
@ -4,3 +4,7 @@ interface LSPNotification {
|
||||
|
||||
interface LSPLanguageUndetectable extends LSPNotification {}
|
||||
|
||||
interface LSPLanguageDetected extends LSPNotification {
|
||||
Language: string;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
type ServerOptions,
|
||||
} from "vscode-languageclient/node";
|
||||
import { onUndetectable } from "./events/on-undetectable";
|
||||
import { onDetectable as onDetected } from "./events/on-detectable";
|
||||
|
||||
const IS_DEBUG =
|
||||
process.env.VSCODE_DEBUG_MODE === "true" ||
|
||||
@ -32,7 +33,8 @@ export async function activate({subscriptions}: ExtensionContext) {
|
||||
const path = getBundledPath();
|
||||
console.info(`Found config-lsp path at ${path}`);
|
||||
const run: Executable = {
|
||||
command: getBundledPath() ,
|
||||
command: path,
|
||||
args: ["--no-undetectable-errors"],
|
||||
};
|
||||
const serverOptions: ServerOptions = {
|
||||
run,
|
||||
@ -51,6 +53,7 @@ export async function activate({subscriptions}: ExtensionContext) {
|
||||
console.info("Started config-lsp");
|
||||
|
||||
subscriptions.push(client.onNotification("$/config-lsp/languageUndetectable", onUndetectable))
|
||||
subscriptions.push(client.onNotification("$/config-lsp/detectedLanguage", onDetected))
|
||||
}
|
||||
|
||||
function getBundledPath(): string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user