Skip to content

Commit

Permalink
fix: bug where language ID ignore list was ignored on subsequent saves
Browse files Browse the repository at this point in the history
  • Loading branch information
dschuessler committed Dec 24, 2024
1 parent 4daaadd commit cd0ef4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
28 changes: 10 additions & 18 deletions src/ConfigurationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -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) || [];
Expand Down
6 changes: 3 additions & 3 deletions src/Linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cd0ef4a

Please sign in to comment.