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

Commit

Permalink
Merge pull request #31 from errata-ai/logging
Browse files Browse the repository at this point in the history
Create our own `OUTPUT` panel
  • Loading branch information
ChrisChinchilla authored Nov 24, 2020
2 parents fa52202 + b370b34 commit 10f5976
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
28 changes: 19 additions & 9 deletions src/features/vsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ 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();
if (!utils.isElligibleDocument(textDocument)) {
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) {
Expand Down Expand Up @@ -72,7 +75,7 @@ export default class ValeServerProvider implements vscode.CodeActionProvider {
let stylesPath: Array<string> = [];
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 = [
Expand Down Expand Up @@ -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}`);
}
}

Expand All @@ -114,9 +113,17 @@ 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);
if (body.Path) {
this.logger.appendLine(body.Path);
}
return;
}

this.readabilityStatus.hide();
for (let key in body) {
const alerts = body[key];
Expand Down Expand Up @@ -254,8 +261,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,
Expand Down Expand Up @@ -303,5 +311,7 @@ export default class ValeServerProvider implements vscode.CodeActionProvider {

this.diagnosticMap = {};
this.alertMap = {};

this.logger.dispose();
}
}
8 changes: 6 additions & 2 deletions src/features/vsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
);
});
Expand Down

0 comments on commit 10f5976

Please sign in to comment.