From 7e4d43e69f6f1a113c408e8522bb9a3f02bcf7ed Mon Sep 17 00:00:00 2001 From: Chris Lang Date: Mon, 3 Oct 2022 18:06:17 -0700 Subject: [PATCH] Add a setting for where readability problems are displayed --- package.json | 16 ++++++++++++++++ src/features/vsProvider.ts | 11 +++++++++-- src/features/vsTypes.ts | 7 ++++++- src/features/vsUtils.ts | 9 +++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a374f7b..f2b06a2 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,23 @@ "type": "boolean", "default": false, "description": "Do not show warning dialog that a file must be saved to be linted." + }, + "vale.readabilityProblemLocation": { + "type": "string", + "enum": [ + "status", + "inline", + "both" + ], + "default": "status", + "markdownEnumDescriptions": [ + "Displays readability problems in the status bar.", + "Displays readability problems inline with other problems.", + "Displays readability problems both in the status bar and inline in the file." + ], + "markdownDescription": "Determines where file-level readability problems are displayed." } + } } }, diff --git a/src/features/vsProvider.ts b/src/features/vsProvider.ts index 8a5f773..74f132e 100644 --- a/src/features/vsProvider.ts +++ b/src/features/vsProvider.ts @@ -5,6 +5,7 @@ import * as fs from "fs"; import * as vscode from "vscode"; import * as utils from "./vsUtils"; +import { getReadabilityProblemLocation } from "./vsUtils"; export default class ValeProvider implements vscode.CodeActionProvider { private diagnosticCollection!: vscode.DiagnosticCollection; @@ -103,14 +104,20 @@ export default class ValeProvider implements vscode.CodeActionProvider { return; } + const readabilityProblemLocation = getReadabilityProblemLocation() this.readabilityStatus.hide(); + for (let key in body) { const alerts = body[key]; for (var i = 0; i < alerts.length; ++i) { - if (alerts[i].Match === "") { + const isReadabilityProblem = alerts[i].Match === "" + + if (isReadabilityProblem && readabilityProblemLocation !== "inline") { var readabilityMessage = alerts[0].Message; this.updateStatusBarItem(readabilityMessage); - } else { + } + + if (!isReadabilityProblem || readabilityProblemLocation !== "status") { let diagnostic = utils.toDiagnostic( alerts[i], this.stylesPath, diff --git a/src/features/vsTypes.ts b/src/features/vsTypes.ts index 963f23d..fcf8a0d 100644 --- a/src/features/vsTypes.ts +++ b/src/features/vsTypes.ts @@ -29,4 +29,9 @@ interface IValeErrorJSON { readonly Message: string; readonly Span: [number, number]; readonly Severity: ValeSeverity; -} \ No newline at end of file +} + +/** + * Where to display file-level readability problems. + */ +type ValeReadabilityProblemLocation = "both" | "inline" | "status"; diff --git a/src/features/vsUtils.ts b/src/features/vsUtils.ts index 8cb8038..01b9fcd 100644 --- a/src/features/vsUtils.ts +++ b/src/features/vsUtils.ts @@ -246,3 +246,12 @@ export const buildCommand = ( command = command.concat(["--output", "JSON", path]); return command; }; + +export const getReadabilityProblemLocation = (): ValeReadabilityProblemLocation => { + const configuration = vscode.workspace.getConfiguration(); + + return configuration.get( + "vale.readabilityProblemLocation", + "status" + ); +}