Skip to content

Commit

Permalink
feat: add feature to disable languages (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschuessler authored Nov 23, 2024
1 parent e19ce80 commit 03bfc20
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@
"plaintext"
],
"markdownDescription": "A list of [Language IDs](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) to treat as plain text."
},
"languageToolLinter.disabledLanguageIds": {
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "A list of [Language IDs](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers) not to lint."
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/ConfigurationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ export class ConfigurationManager implements Disposable {
);
}
}
// List of plaintext ids changed - need to reload
if (event.affectsConfiguration("languageToolLinter.plainText")) {
// List of plaintext ids or disabled language ids changed - need to reload
if (
event.affectsConfiguration("languageToolLinter.plainText") ||
event.affectsConfiguration("languageToolLinter.disabledLanguageIds")
) {
const action = "Reload";
window
.showInformationMessage(
"The settings for linting plaintext documents have changed. \
"The settings for linting documents have changed. \
Please reload the window for the configuration to take effect.",
action,
)
Expand Down Expand Up @@ -163,7 +166,12 @@ export class ConfigurationManager implements Disposable {

public getDocumentSelectors(): DocumentSelector[] {
const selectors: DocumentSelector[] = [];
const languageIds = 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[] =
Expand Down
1 change: 1 addition & 0 deletions src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const CONFIGURATION_DISABLED_CATEGORIES =
"languageTool.disabledCategories";
export const CONFIGURATION_PLAIN_TEXT_ENABLED = "plainText.enabled";
export const CONFIGURATION_PLAIN_TEXT_IDS = "plainText.languageIds";
export const CONFIGURATION_DISABLED_IDS = "disabledLanguageIds";
export const CONFIGURATION_LANGUAGE = "language";

// LanguageTool Services
Expand Down

0 comments on commit 03bfc20

Please sign in to comment.