Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Embed Vale CLI 2.20.1
Browse files Browse the repository at this point in the history
fixes #75
  • Loading branch information
apupier committed Jul 29, 2022
1 parent 8eb0191 commit 011d081
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -72,4 +71,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.
Binary file added binaries/vale_2.20.1_Linux_64-bit/vale
Binary file not shown.
Binary file added binaries/vale_2.20.1_Windows_64-bit/vale.exe
Binary file not shown.
Binary file added binaries/vale_2.20.1_macOS_64-bit/vale
Binary file not shown.
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 6 additions & 1 deletion src/features/vsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand Down
38 changes: 33 additions & 5 deletions src/features/vsUtils.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<string>("vale.valeCLI.path");
if (customBinaryPath) {
return replaceWorkspaceFolder(logger, customBinaryPath, file);
const valeCLIUsage = configuration.get<string>("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<string>("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();

Expand Down

0 comments on commit 011d081

Please sign in to comment.