diff --git a/Changelog.md b/Changelog.md new file mode 100644 index 0000000..2ea798c --- /dev/null +++ b/Changelog.md @@ -0,0 +1,7 @@ +# 0.16.0 + +- Embed Vale CLI (version 2.20.1). It is still possible to provide a specific path to the CLI or to use the one from system path. This is configurable from _File -> Preferences_. + +# 0.15.0 + +- Remove Vale Server whcih is deprecated. Keeping only Vale CLI diff --git a/README.md b/README.md index 61ba3a5..83bfd0f 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,8 @@ As of **v0.15.0**, the extension drops support for [Vale Server](https://errata. ## Installation -1. Install [Vale](https://docs.errata.ai/vale/install); -2. install `vale-vscode` (this extension) via the [Marketplace](https://marketplace.visualstudio.com/items?itemName=errata-ai.vale-server); -3. restart VS Code (recommended). +1. Install `vale-vscode` (this extension) via the [Marketplace](https://marketplace.visualstudio.com/items?itemName=errata-ai.vale-server); +2. Restart VS Code (recommended). ## Features @@ -73,3 +72,7 @@ The extension offers a number of settings and configuration options (_Preference ``` - `vale.valeCLI.minAlertLevel` (default: `inherited`): Defines from which level of errors and above to display in the problems output. + +- `vale.valeCLI.usage` (default: `Use Vale CLI specified in vale.valeCLI.path setting`): Define which Vale CLI to use. Check the description of each field to have more details in priority order and fallbacks. See `Output -> Vale` to see if a fallback has been used. + +- `vale.minAlertLevel` (default: `inherited`): Defines from which level of errors and above to display in the problems output. diff --git a/binaries/vale_2.20.1_Linux_64-bit/vale b/binaries/vale_2.20.1_Linux_64-bit/vale new file mode 100755 index 0000000..fd8d9e9 Binary files /dev/null and b/binaries/vale_2.20.1_Linux_64-bit/vale differ diff --git a/binaries/vale_2.20.1_Windows_64-bit/vale.exe b/binaries/vale_2.20.1_Windows_64-bit/vale.exe new file mode 100755 index 0000000..a5fa96e Binary files /dev/null and b/binaries/vale_2.20.1_Windows_64-bit/vale.exe differ diff --git a/binaries/vale_2.20.1_macOS_64-bit/vale b/binaries/vale_2.20.1_macOS_64-bit/vale new file mode 100755 index 0000000..16de83f Binary files /dev/null and b/binaries/vale_2.20.1_macOS_64-bit/vale differ diff --git a/package.json b/package.json index 7ac0ad5..bb52dce 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,22 @@ "Sets `minAlertLevel` to `error`, overriding any configuration files." ], "markdownDescription": "Defines from which level of errors and above to display in the problems output." + }, + "vale.valeCLI.usage": { + "scope": "resource", + "type": "string", + "default": "Use Vale CLI specified in vale.valeCLI.path setting", + "enum": [ + "Use embedded Vale CLI", + "Use Vale CLI specified in vale.valeCLI.path setting", + "Use Vale CLI available from system path" + ], + "enumDescriptions": [ + "Use embedded Vale CLI. It is available for Linux, Mac and Windows; all in x64 architectures.", + "Use Vale CLI specified in vale.valeCLI.path setting in priority, if not available fall back to embedded", + "Use Vale CLI available from system path, if not available fall back to embedded" + ], + "description": "Define which Vale CLI to use. Check the description of each field to have more details in priority order and fallbacks. See Output -> Vale to see if a fallback has been used." } } } diff --git a/src/extension.ts b/src/extension.ts index 8d1e89c..81c7cf6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,6 @@ import * as vscode from "vscode"; import ValeProvider from "./features/vsProvider"; export function activate(context: vscode.ExtensionContext) { - let linter = new ValeProvider(); + let linter = new ValeProvider(context); linter.activate(context.subscriptions); } diff --git a/src/features/vsProvider.ts b/src/features/vsProvider.ts index 9c7427f..4a57f9b 100644 --- a/src/features/vsProvider.ts +++ b/src/features/vsProvider.ts @@ -16,6 +16,11 @@ export default class ValeProvider implements vscode.CodeActionProvider { private static commandId: string = "ValeProvider.runCodeAction"; private command!: vscode.Disposable; private logger!: vscode.OutputChannel; + private context: vscode.ExtensionContext; + + constructor(context: vscode.ExtensionContext) { + this.context = context; + } private async doVale(textDocument: vscode.TextDocument) { if (!utils.isElligibleDocument(textDocument)) { @@ -37,7 +42,7 @@ export default class ValeProvider implements vscode.CodeActionProvider { private async runVale(file: vscode.TextDocument) { const folder = path.dirname(file.fileName); - const binaryLocation = utils.readBinaryLocation(this.logger, file); + const binaryLocation = utils.readBinaryLocation(this.context, this.logger, file); const configLocation = utils.readFileLocation(this.logger, file); if (binaryLocation === null || configLocation === null) { // `file` is not part of the workspace, so we could not resolve a workspace-relative path. Ignore this file. diff --git a/src/features/vsUtils.ts b/src/features/vsUtils.ts index 69054c3..117bf92 100644 --- a/src/features/vsUtils.ts +++ b/src/features/vsUtils.ts @@ -1,6 +1,7 @@ import * as path from "path"; import * as which from "which"; import * as fs from "fs"; +import * as os from "os"; import { execFile } from "child_process"; import * as vscode from "vscode"; @@ -20,16 +21,43 @@ function replaceWorkspaceFolder(logger: vscode.OutputChannel, customPath: string return null; } -export const readBinaryLocation = (logger: vscode.OutputChannel, file: vscode.TextDocument): string | null => { +export const readBinaryLocation = (context: vscode.ExtensionContext, logger: vscode.OutputChannel, file: vscode.TextDocument): string | null => { const configuration = vscode.workspace.getConfiguration(); - let customBinaryPath = configuration.get("vale.valeCLI.path"); - if (customBinaryPath) { - return replaceWorkspaceFolder(logger, customBinaryPath, file); + const valeCLIUsage = configuration.get("vale.valeCLI.usage") + + if (valeCLIUsage === "Use embedded Vale CLI") { + return embeddedBinaryPath(context, logger); + } else if(valeCLIUsage === "Use Vale CLI specified in vale.valeCLI.path setting") { + let customBinaryPath = configuration.get("vale.valeCLI.path"); + if (customBinaryPath) { + return replaceWorkspaceFolder(logger, customBinaryPath, file); + } + logger.appendLine(`Falling back to embedded Vale CLI despite "Use Vale CLI specified in vale.valeCLI.path setting" specified because "vale.valeCLI.path" is empty.`); + } else if(valeCLIUsage === "Use Vale CLI available from system path") { + const valeOnSystemPath = which.sync("vale"); + if (valeOnSystemPath !== null) { + return valeOnSystemPath; + } } - return which.sync("vale"); + + return embeddedBinaryPath(context, logger); }; +function embeddedBinaryPath(context: vscode.ExtensionContext, logger: vscode.OutputChannel): string { + const osPlatform = os.platform(); + if(osPlatform === "win32") { + return context.asAbsolutePath(path.join('binaries', 'vale_2.20.1_Windows_64-bit', 'vale.exe')); + } else if(osPlatform === "linux"){ + return context.asAbsolutePath(path.join('binaries', 'vale_2.20.1_Linux_64-bit', 'vale')); + } else if(osPlatform === "darwin") { + return context.asAbsolutePath(path.join('binaries', 'vale_2.20.1_macOS_64-bit', 'vale')); + } else { + logger.appendLine(`Cannot use embedded Vale CLI with OS Platform "${osPlatform}"`); + return "vale"; + } +} + export const readFileLocation = (logger: vscode.OutputChannel, file: vscode.TextDocument): string | null => { const configuration = vscode.workspace.getConfiguration();