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

Commit

Permalink
Append a line to the output console when Vale ignores a file
Browse files Browse the repository at this point in the history
  • Loading branch information
jvilk-stripe committed Jan 4, 2021
1 parent a2fcb04 commit e77be87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/features/vsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export default class ValeServerProvider implements vscode.CodeActionProvider {
private async runVale(file: vscode.TextDocument) {
const folder = path.dirname(file.fileName);

const binaryLocation = utils.readBinaryLocation(file);
const configLocation = utils.readFileLocation(file);
const binaryLocation = utils.readBinaryLocation(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.
return;
Expand Down
11 changes: 6 additions & 5 deletions src/features/vsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as vscode from "vscode";

// If `customPath` contains `${workspaceFolder}`, replaces it with the workspace that `file` comes from.
// Return `null` if `customPath` contains `${workspaceFolder}` and `file` is _not_ part of the workspace.
function replaceWorkspaceFolder(customPath: string, file: vscode.TextDocument): string | null {
function replaceWorkspaceFolder(logger: vscode.OutputChannel, customPath: string, file: vscode.TextDocument): string | null {
customPath = path.normalize(customPath);
const workspaceFolder = vscode.workspace.getWorkspaceFolder(file.uri);
if (workspaceFolder) {
Expand All @@ -17,25 +17,26 @@ function replaceWorkspaceFolder(customPath: string, file: vscode.TextDocument):
workspaceFolder.uri.fsPath
);
}
logger.appendLine(`Not running Vale on file '${file.uri}' as it is not contained within the workspace`);
return null;
}

export const readBinaryLocation = (file: vscode.TextDocument): string | null => {
export const readBinaryLocation = (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(customBinaryPath, file);
return replaceWorkspaceFolder(logger, customBinaryPath, file);
}
return which.sync("vale");
};

export const readFileLocation = (file: vscode.TextDocument): string | null => {
export const readFileLocation = (logger: vscode.OutputChannel, file: vscode.TextDocument): string | null => {
const configuration = vscode.workspace.getConfiguration();

let customConfigPath = configuration.get<string>("vale.valeCLI.config");
if (customConfigPath) {
return replaceWorkspaceFolder(customConfigPath, file);
return replaceWorkspaceFolder(logger, customConfigPath, file);
}
return "";
};
Expand Down

0 comments on commit e77be87

Please sign in to comment.