From f0f5c3bc9d6bc84e01b5e5026fbd7ba4e2af6530 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 2 Aug 2022 19:23:36 +0200 Subject: [PATCH 1/2] log reanalyze invalid json messages in a more elaborate way, including an instruction on what to do with the error --- client/src/commands.ts | 8 +++++--- client/src/commands/code_analysis.ts | 20 +++++++++++++++++--- client/src/extension.ts | 12 ++++++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/src/commands.ts b/client/src/commands.ts index 10e4b0ba3..98bcec00d 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -1,4 +1,4 @@ -import { DiagnosticCollection } from "vscode"; +import { DiagnosticCollection, OutputChannel } from "vscode"; import { DiagnosticsResultCodeActionsMap, @@ -12,11 +12,13 @@ export { switchImplIntf } from "./commands/switch_impl_intf"; export const codeAnalysisWithReanalyze = ( targetDir: string | null, diagnosticsCollection: DiagnosticCollection, - diagnosticsResultCodeActions: DiagnosticsResultCodeActionsMap + diagnosticsResultCodeActions: DiagnosticsResultCodeActionsMap, + outputChannel: OutputChannel ) => { runCodeAnalysisWithReanalyze( targetDir, diagnosticsCollection, - diagnosticsResultCodeActions + diagnosticsResultCodeActions, + outputChannel ); }; diff --git a/client/src/commands/code_analysis.ts b/client/src/commands/code_analysis.ts index db190e0c1..e19d21101 100644 --- a/client/src/commands/code_analysis.ts +++ b/client/src/commands/code_analysis.ts @@ -12,6 +12,7 @@ import { CodeAction, CodeActionKind, WorkspaceEdit, + OutputChannel, } from "vscode"; export type DiagnosticsResultCodeActionsMap = Map< @@ -157,7 +158,8 @@ let getAnalysisBinaryPath = (): string | null => { export const runCodeAnalysisWithReanalyze = ( targetDir: string | null, diagnosticsCollection: DiagnosticCollection, - diagnosticsResultCodeActions: DiagnosticsResultCodeActionsMap + diagnosticsResultCodeActions: DiagnosticsResultCodeActionsMap, + outputChannel: OutputChannel ) => { let currentDocument = window.activeTextEditor.document; let cwd = targetDir ?? path.dirname(currentDocument.uri.fsPath); @@ -207,8 +209,20 @@ export const runCodeAnalysisWithReanalyze = ( try { json = JSON.parse(data); } catch (e) { - window.showErrorMessage( - `Something went wrong parsing the json output of reanalyze: '${e}'` + window + .showErrorMessage( + `Something went wrong when running the code analyzer.`, + "See details in error log" + ) + .then((_choice) => { + outputChannel.show(); + }); + + outputChannel.appendLine("--invalid json start--"); + outputChannel.append(data); + outputChannel.appendLine("--invalid json end--"); + outputChannel.appendLine( + "Parsing JSON from reanalyze failed. The raw, invalid JSON is logged above this message. Please report this on the extension bug tracker: https://github.com/rescript-lang/rescript-vscode/issues" ); } diff --git a/client/src/extension.ts b/client/src/extension.ts index 7bd85b918..33f1335ad 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -70,6 +70,11 @@ let client: LanguageClient; // }); export function activate(context: ExtensionContext) { + let outputChannel = window.createOutputChannel( + "ReScript Language Server", + "rescript" + ); + function createLanguageClient() { // The server is implemented in node let serverModule = context.asAbsolutePath( @@ -99,6 +104,7 @@ export function activate(context: ExtensionContext) { initializationOptions: { extensionConfiguration: workspace.getConfiguration("rescript.settings"), }, + outputChannel, }; const client = new LanguageClient( @@ -123,7 +129,8 @@ export function activate(context: ExtensionContext) { customCommands.codeAnalysisWithReanalyze( inCodeAnalysisState.activatedFromDirectory, diagnosticsCollection, - diagnosticsResultCodeActions + diagnosticsResultCodeActions, + outputChannel ); } }) @@ -207,7 +214,8 @@ export function activate(context: ExtensionContext) { customCommands.codeAnalysisWithReanalyze( inCodeAnalysisState.activatedFromDirectory, diagnosticsCollection, - diagnosticsResultCodeActions + diagnosticsResultCodeActions, + outputChannel ); }); From c1ca7a6a24179478d146963c1ccacce3b944b78f Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Wed, 3 Aug 2022 19:48:42 +0200 Subject: [PATCH 2/2] include command to reproduce failing JSON --- client/src/commands/code_analysis.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/client/src/commands/code_analysis.ts b/client/src/commands/code_analysis.ts index e19d21101..248304062 100644 --- a/client/src/commands/code_analysis.ts +++ b/client/src/commands/code_analysis.ts @@ -170,7 +170,8 @@ export const runCodeAnalysisWithReanalyze = ( return; } - let p = cp.spawn(binaryPath, ["reanalyze", "-json"], { + let opts = ["reanalyze", "-json"]; + let p = cp.spawn(binaryPath, opts, { cwd, }); @@ -218,12 +219,16 @@ export const runCodeAnalysisWithReanalyze = ( outputChannel.show(); }); - outputChannel.appendLine("--invalid json start--"); - outputChannel.append(data); - outputChannel.appendLine("--invalid json end--"); + outputChannel.appendLine("\n\n>>>>"); outputChannel.appendLine( - "Parsing JSON from reanalyze failed. The raw, invalid JSON is logged above this message. Please report this on the extension bug tracker: https://github.com/rescript-lang/rescript-vscode/issues" + "Parsing JSON from reanalyze failed. The raw, invalid JSON can be reproduced by following the instructions below. Please run that command and report the issue + failing JSON on the extension bug tracker: https://github.com/rescript-lang/rescript-vscode/issues" ); + outputChannel.appendLine( + `> To reproduce, run "${binaryPath} ${opts.join( + " " + )}" in directory: "${cwd}"` + ); + outputChannel.appendLine("\n"); } if (json == null) {