diff --git a/package.json b/package.json index a2d05f4f..674f434b 100644 --- a/package.json +++ b/package.json @@ -138,6 +138,11 @@ "error" ] }, + "languageToolLinter.diagnosticSeverityAuto": { + "type": "boolean", + "default": false, + "description": "Spelling mistakes will be set as Error, while punctuation, grammar and typography mistakes as Warning. Anything else as the configured Diagnostic Severity level (recommended to be set as Information when using this option)." + }, "languageToolLinter.enabled": { "type": "boolean", "default": true, diff --git a/src/ConfigurationManager.ts b/src/ConfigurationManager.ts index b6fd1568..c2fd28c0 100644 --- a/src/ConfigurationManager.ts +++ b/src/ConfigurationManager.ts @@ -253,6 +253,14 @@ export class ConfigurationManager implements Disposable { } } + public getDiagnosticSeverityAuto(): boolean { + const severityAuto = this.config.get("diagnosticSeverityAuto"); + if (severityAuto === true) { + return true + } + return false + } + public getClassPath(): string { const jarFile: string = this.get("managed.jarFile") as string; const classPath: string = this.get("managed.classPath") as string; @@ -400,7 +408,7 @@ export class ConfigurationManager implements Disposable { if (username && apiKey) { parameters.set("username", username); parameters.set("apiKey", apiKey); - } + } } // Make sure disabled rules and disabled categories do not contain spaces const CONFIG_DISABLED_RULES = "languageTool.disabledRules"; diff --git a/src/Linter.ts b/src/Linter.ts index 59c6cd33..26133418 100644 --- a/src/Linter.ts +++ b/src/Linter.ts @@ -64,6 +64,14 @@ export class Linter implements CodeActionProvider { ); } + public static isWarningCategory(categoryId: string): boolean { + return ( + categoryId.indexOf("GRAMMAR") !== -1 || + categoryId.indexOf("PUNCTUATION") !== -1 || + categoryId.indexOf("TYPOGRAPHY") !== -1 + ); + } + public diagnosticCollection: DiagnosticCollection; public remarkBuilderOptions: RemarkBuilder.IOptions = RemarkBuilder.defaults; public rehypeBuilderOptions: RehypeBuilder.IOptions = RehypeBuilder.defaults; @@ -366,6 +374,7 @@ export class Linter implements CodeActionProvider { const end: Position = document.positionAt(match.offset + match.length); const ignored: IIgnoreItem[] = this.getIgnoreList(document, start); const diagnosticSeverity: DiagnosticSeverity = this.configManager.getDiagnosticSeverity(); + const diagnosticSeverityAuto: boolean = this.configManager.getDiagnosticSeverityAuto(); const diagnosticRange: Range = new Range(start, end); const diagnosticMessage: string = match.message; const diagnostic: LTDiagnostic = new LTDiagnostic( @@ -388,6 +397,13 @@ export class Linter implements CodeActionProvider { }; } diagnostics.push(diagnostic); + if (diagnosticSeverityAuto) { + if (Linter.isSpellingRule(match.rule.id)) { + diagnostic.severity = DiagnosticSeverity.Error + } else if (Linter.isWarningCategory(match.rule.category.id)) { + diagnostic.severity = DiagnosticSeverity.Warning + } + } if ( Linter.isSpellingRule(match.rule.id) && this.configManager.isIgnoredWord(document.getText(diagnostic.range)) &&