Skip to content

More elaborate error message for users on reanalyze json error #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions client/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagnosticCollection } from "vscode";
import { DiagnosticCollection, OutputChannel } from "vscode";

import {
DiagnosticsResultCodeActionsMap,
Expand All @@ -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
);
};
27 changes: 23 additions & 4 deletions client/src/commands/code_analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CodeAction,
CodeActionKind,
WorkspaceEdit,
OutputChannel,
} from "vscode";

export type DiagnosticsResultCodeActionsMap = Map<
Expand Down Expand Up @@ -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);
Expand All @@ -168,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,
});

Expand Down Expand Up @@ -207,9 +210,25 @@ 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("\n\n>>>>");
outputChannel.appendLine(
"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) {
Expand Down
12 changes: 10 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ let client: LanguageClient;
// });

export function activate(context: ExtensionContext) {
let outputChannel = window.createOutputChannel(
"ReScript Language Server",
"rescript"
);

Comment on lines +73 to +77
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating and passing around an explicit output channel lets us have a good place to log things to, that's also easy to reveal programatically.

function createLanguageClient() {
// The server is implemented in node
let serverModule = context.asAbsolutePath(
Expand Down Expand Up @@ -99,6 +104,7 @@ export function activate(context: ExtensionContext) {
initializationOptions: {
extensionConfiguration: workspace.getConfiguration("rescript.settings"),
},
outputChannel,
};

const client = new LanguageClient(
Expand All @@ -123,7 +129,8 @@ export function activate(context: ExtensionContext) {
customCommands.codeAnalysisWithReanalyze(
inCodeAnalysisState.activatedFromDirectory,
diagnosticsCollection,
diagnosticsResultCodeActions
diagnosticsResultCodeActions,
outputChannel
);
}
})
Expand Down Expand Up @@ -207,7 +214,8 @@ export function activate(context: ExtensionContext) {
customCommands.codeAnalysisWithReanalyze(
inCodeAnalysisState.activatedFromDirectory,
diagnosticsCollection,
diagnosticsResultCodeActions
diagnosticsResultCodeActions,
outputChannel
);
});

Expand Down