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 feb59f6..b055ccb 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,6 @@ The extension offers a number of settings and configuration options (_Preference } ``` +- `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 6466595..069c3a1 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,18 @@ "default": null, "markdownDescription": "Absolute path to the Vale binary. The predefined [`${workspaceFolder}`](https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables) variable can be used to reference a non-global binary. (**NOTE**: On Windows you can use '/' and can omit `.cmd` in the path value.)" }, + "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." + }, "vale.minAlertLevel": { "scope": "resource", "type": "string", 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 00c1241..53fad04 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) { const configuration = vscode.workspace.getConfiguration(); @@ -38,7 +43,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();