From cd0ef4a1642020c631f563924d2979eb2b4b37ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20Sch=C3=BC=C3=9Fler?= Date: Tue, 24 Dec 2024 16:17:29 +0100 Subject: [PATCH] fix: bug where language ID ignore list was ignored on subsequent saves --- src/ConfigurationManager.ts | 28 ++++++++++------------------ src/Linter.ts | 6 +++--- src/extension.ts | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/ConfigurationManager.ts b/src/ConfigurationManager.ts index 5c010fef..fdb3e1cb 100644 --- a/src/ConfigurationManager.ts +++ b/src/ConfigurationManager.ts @@ -139,8 +139,8 @@ export class ConfigurationManager implements Disposable { return this.config.get("smartFormat.onSave") as boolean; } - // Is Language ID Supported? - public isSupportedDocument(document: TextDocument): boolean { + // Is language ID supported and enabled? + public isLanguageSupportedAndEnabled(document: TextDocument): boolean { if ( document.uri.scheme === Constants.SCHEME_FILE || document.uri.scheme === Constants.SCHEME_UNTITLED @@ -166,20 +166,7 @@ export class ConfigurationManager implements Disposable { public getDocumentSelectors(): DocumentSelector[] { const selectors: DocumentSelector[] = []; - const supportedLanguageIds = Constants.SUPPORTED_LANGUAGE_IDS; - const disabledLanguageIds: string[] = - this.config.get(Constants.CONFIGURATION_DISABLED_IDS) || []; - const languageIds = supportedLanguageIds.filter( - (languageId) => !disabledLanguageIds.includes(languageId), - ); - - if (this.isPlainTextEnabled()) { - const plaintextLanguageIds: string[] = - this.config.get(Constants.CONFIGURATION_PLAIN_TEXT_IDS) || []; - plaintextLanguageIds.forEach((languageId) => { - languageIds.push(languageId); - }); - } + const languageIds = this.getLanguageIds(); languageIds.forEach((languageId) => { const fileSelector: DocumentSelector = { @@ -223,9 +210,14 @@ export class ConfigurationManager implements Disposable { } } - // Get a list of current enabled language Ids + // Get a list of language Ids that are supported and enabled public getLanguageIds(): string[] { - const languageIds: string[] = Constants.SUPPORTED_LANGUAGE_IDS; + const supportedLanguageIds = Constants.SUPPORTED_LANGUAGE_IDS; + const disabledLanguageIds: string[] = + this.config.get(Constants.CONFIGURATION_DISABLED_IDS) || []; + const languageIds = supportedLanguageIds.filter( + (languageId) => !disabledLanguageIds.includes(languageId), + ); if (this.isPlainTextEnabled()) { const plainTextLanguageIds: string[] = this.config.get(Constants.CONFIGURATION_PLAIN_TEXT_IDS) || []; diff --git a/src/Linter.ts b/src/Linter.ts index 3e09b002..b40edc95 100644 --- a/src/Linter.ts +++ b/src/Linter.ts @@ -155,7 +155,7 @@ export class Linter implements CodeActionProvider { this.statusBarManager.hide(); return; } else { - if (this.configManager.isSupportedDocument(document)) { + if (this.configManager.isLanguageSupportedAndEnabled(document)) { this.statusBarManager.show(); if (lint) { if (this.configManager.isHideDiagnosticsOnChange()) { @@ -179,7 +179,7 @@ export class Linter implements CodeActionProvider { document: TextDocument, timeoutDuration: number = Constants.EXTENSION_TIMEOUT_MS, ): void { - if (this.configManager.isSupportedDocument(document)) { + if (this.configManager.isLanguageSupportedAndEnabled(document)) { this.cancelLint(document); const uriString = document.uri.toString(); const timeout = setTimeout(() => { @@ -260,7 +260,7 @@ export class Linter implements CodeActionProvider { // Perform Lint on Document public lintDocument(document: TextDocument): void { - if (this.configManager.isSupportedDocument(document)) { + if (this.configManager.isLanguageSupportedAndEnabled(document)) { if (document.languageId === Constants.LANGUAGE_ID_MARKDOWN) { this.ignoreList = this.buildIgnoreList(document); const annotatedMarkdown: string = JSON.stringify( diff --git a/src/extension.ts b/src/extension.ts index 69c7b108..da69060e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -230,7 +230,7 @@ export function activate(context: vscode.ExtensionContext): void { const smartFormatCommand = vscode.commands.registerTextEditorCommand( Constants.COMMAND_SMART_FORMAT, (editor: vscode.TextEditor, edit: vscode.TextEditorEdit) => { - if (configMan.isSupportedDocument(editor.document)) { + if (configMan.isLanguageSupportedAndEnabled(editor.document)) { // Revert to regex here for cleaner code. const text: string = editor.document.getText(); const lastOffset: number = text.length;