From 81f92e64c73908c49410dd827962342b2753cbeb Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Sat, 21 Nov 2020 13:58:06 -0800 Subject: [PATCH 1/2] Create our own `OUTPUT` panel --- src/features/vsProvider.ts | 25 ++++++++++++++++--------- src/features/vsUtils.ts | 8 ++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/features/vsProvider.ts b/src/features/vsProvider.ts index b8b9369..6779606 100644 --- a/src/features/vsProvider.ts +++ b/src/features/vsProvider.ts @@ -18,6 +18,7 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { private static commandId: string = "ValeServerProvider.runCodeAction"; private command!: vscode.Disposable; + private logger!: vscode.OutputChannel; private async doVale(textDocument: vscode.TextDocument) { const configuration = vscode.workspace.getConfiguration(); @@ -25,8 +26,10 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { return; } - // Reset out alert map: + // Reset out alert map and run-time log: this.alertMap = {}; + this.logger.clear(); + this.useCLI = configuration.get("vale.core.useCLI", false); if (!this.useCLI) { @@ -72,7 +75,7 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { let stylesPath: Array = []; if (configLocation !== "" && !fs.existsSync(configLocation)) { vscode.window.showErrorMessage( - `There was an error running Vale: '${configLocation}' does not exist.` + `[Vale]: '${configLocation}' does not exist.` ); } else if (configLocation !== "") { stylesPath = [ @@ -100,11 +103,7 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { const stdout = await utils.runInWorkspace(folder, command); this.handleJSON(stdout.toString(), file, 0); } catch (error) { - // We can't find a configuration, but this might not be an error: - // - // TODO: in case (2), how do we unintrusively communicate that we - // couldn't find a config file? - console.log(`[Vale] runtime error: ${error}`); + vscode.window.showErrorMessage(`[Vale]: ${error}`); } } @@ -114,9 +113,14 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { offset: number ) { const diagnostics: vscode.Diagnostic[] = []; - let body = JSON.parse(contents.toString()); const backend = this.useCLI ? "Vale" : "Vale Server"; + let body = JSON.parse(contents.toString()); + if (body.Code && body.Text) { + this.logger.appendLine(body.Text); + return; + } + this.readabilityStatus.hide(); for (let key in body) { const alerts = body[key]; @@ -254,8 +258,9 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { } public async activate(subscriptions: vscode.Disposable[]) { - const configuration = vscode.workspace.getConfiguration(); + this.logger = vscode.window.createOutputChannel("Vale"); + const configuration = vscode.workspace.getConfiguration(); this.command = vscode.commands.registerCommand( ValeServerProvider.commandId, this.runCodeAction, @@ -303,5 +308,7 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { this.diagnosticMap = {}; this.alertMap = {}; + + this.logger.dispose(); } } diff --git a/src/features/vsUtils.ts b/src/features/vsUtils.ts index 56a6140..269d213 100644 --- a/src/features/vsUtils.ts +++ b/src/features/vsUtils.ts @@ -152,8 +152,12 @@ export const runInWorkspace = ( command[0], command.slice(1), { cwd, maxBuffer }, - (error, stdout) => { - resolve(stdout); + (error, stdout, stderr) => { + if (error) { + resolve(stderr); + } else { + resolve(stdout); + } } ); }); From b370b34d461283cb8f7e954253fc896daecf8dc3 Mon Sep 17 00:00:00 2001 From: Joseph Kato Date: Mon, 23 Nov 2020 14:43:17 -0800 Subject: [PATCH 2/2] Include path, if possible --- src/features/vsProvider.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/features/vsProvider.ts b/src/features/vsProvider.ts index 6779606..93429f3 100644 --- a/src/features/vsProvider.ts +++ b/src/features/vsProvider.ts @@ -118,6 +118,9 @@ export default class ValeServerProvider implements vscode.CodeActionProvider { let body = JSON.parse(contents.toString()); if (body.Code && body.Text) { this.logger.appendLine(body.Text); + if (body.Path) { + this.logger.appendLine(body.Path); + } return; }