diff --git a/vs-code-extension/src/events/on-language-detected.ts b/vs-code-extension/src/events/on-language-detected.ts new file mode 100644 index 0000000..88759c4 --- /dev/null +++ b/vs-code-extension/src/events/on-language-detected.ts @@ -0,0 +1,7 @@ +import { GenericNotificationHandler } from "vscode-languageclient"; +import { tempUndetectableFiles } from "./shared"; + +export const onDetectable: GenericNotificationHandler = async (params: LSPLanguageDetected) => { + tempUndetectableFiles.add(params.Uri); +} + diff --git a/vs-code-extension/src/events/on-undetectable.ts b/vs-code-extension/src/events/on-language-undetectable.ts similarity index 65% rename from vs-code-extension/src/events/on-undetectable.ts rename to vs-code-extension/src/events/on-language-undetectable.ts index 0802071..ea3ba78 100644 --- a/vs-code-extension/src/events/on-undetectable.ts +++ b/vs-code-extension/src/events/on-language-undetectable.ts @@ -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(); - -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; } } diff --git a/vs-code-extension/src/events/shared.ts b/vs-code-extension/src/events/shared.ts new file mode 100644 index 0000000..c015ed6 --- /dev/null +++ b/vs-code-extension/src/events/shared.ts @@ -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(); + +export const undetectableIgnoredFiles = new Set(); + + diff --git a/vs-code-extension/src/events/types.ts b/vs-code-extension/src/events/types.ts index 8bae362..073927a 100644 --- a/vs-code-extension/src/events/types.ts +++ b/vs-code-extension/src/events/types.ts @@ -4,3 +4,7 @@ interface LSPNotification { interface LSPLanguageUndetectable extends LSPNotification {} +interface LSPLanguageDetected extends LSPNotification { + Language: string; +} + diff --git a/vs-code-extension/src/extension.ts b/vs-code-extension/src/extension.ts index e794ea4..2fe967e 100644 --- a/vs-code-extension/src/extension.ts +++ b/vs-code-extension/src/extension.ts @@ -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 {