Skip to content

prompt the user whenever parsing errors/warning from the compiler log fails #576

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 1 commit into from
Sep 6, 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
20 changes: 16 additions & 4 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,28 @@ let getCurrentCompilerDiagnosticsForFile = (
let sendUpdatedDiagnostics = () => {
projectsFiles.forEach((projectFile, projectRootPath) => {
let { filesWithDiagnostics } = projectFile;
let content = fs.readFileSync(
path.join(projectRootPath, c.compilerLogPartialPath),
{ encoding: "utf-8" }
);
let compilerLogPath = path.join(projectRootPath, c.compilerLogPartialPath);
let content = fs.readFileSync(compilerLogPath, { encoding: "utf-8" });
let {
done,
result: filesAndErrors,
codeActions,
linesWithParseErrors,
} = utils.parseCompilerLogOutput(content);

if (linesWithParseErrors.length > 0) {
let params: p.ShowMessageParams = {
type: p.MessageType.Warning,
message: `There are more compiler warning/errors that we could not parse. You can help us fix this by opening an [issue on the repository](https://github.com/rescript-lang/rescript-vscode/issues/new?title=Compiler%20log%20parse%20error), pasting the contents of the file [lib/bs/.compiler.log](file://${compilerLogPath}).`,
};
let message: p.NotificationMessage = {
jsonrpc: c.jsonrpcVersion,
method: "window/showMessage",
params: params,
};
send(message);
}

projectFile.filesDiagnostics = filesAndErrors;
codeActionsFromDiagnostics = codeActions;

Expand Down
25 changes: 20 additions & 5 deletions server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ type parsedCompilerLogResult = {
done: boolean;
result: filesDiagnostics;
codeActions: codeActions.filesCodeActions;
linesWithParseErrors: string[];
};
export let parseCompilerLogOutput = (
content: string
Expand All @@ -477,6 +478,7 @@ export let parseCompilerLogOutput = (
content: string[];
};
let parsedDiagnostics: parsedDiagnostic[] = [];
let linesWithParseErrors: string[] = [];
let lines = content.split(os.EOL);
let done = false;

Expand Down Expand Up @@ -588,17 +590,25 @@ export let parseCompilerLogOutput = (
// 10 ┆
} else if (line.startsWith(" ")) {
// part of the actual diagnostics message
parsedDiagnostics[parsedDiagnostics.length - 1].content.push(
line.slice(2)
);
if (parsedDiagnostics[parsedDiagnostics.length - 1] == null) {
linesWithParseErrors.push(line);
} else {
parsedDiagnostics[parsedDiagnostics.length - 1].content.push(
line.slice(2)
);
}
} else if (line.trim() != "") {
// We'll assume that everything else is also part of the diagnostics too.
// Most of these should have been indented 2 spaces; sadly, some of them
// aren't (e.g. outcome printer printing badly, and certain old ocaml type
// messages not printing with indent). We used to get bug reports and fix
// the messages, but that strategy turned out too slow. One day we should
// revert to not having this branch...
parsedDiagnostics[parsedDiagnostics.length - 1].content.push(line);
if (parsedDiagnostics[parsedDiagnostics.length - 1] == null) {
linesWithParseErrors.push(line);
} else {
parsedDiagnostics[parsedDiagnostics.length - 1].content.push(line);
}
}
}

Expand Down Expand Up @@ -635,7 +645,12 @@ export let parseCompilerLogOutput = (
result[file].push(diagnostic);
});

return { done, result, codeActions: foundCodeActions };
return {
done,
result,
codeActions: foundCodeActions,
linesWithParseErrors,
};
};

export let rangeContainsRange = (
Expand Down