feat(extension): Improve undetectable warning box

This commit is contained in:
Myzel394 2025-02-11 19:52:18 +01:00
parent c2f7de5f13
commit cc82080cc1
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F
5 changed files with 34 additions and 8 deletions

View 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);
}

View File

@ -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;
}
}

View 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>();

View File

@ -4,3 +4,7 @@ interface LSPNotification {
interface LSPLanguageUndetectable extends LSPNotification {}
interface LSPLanguageDetected extends LSPNotification {
Language: string;
}

View File

@ -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 {