Skip to content

Commit 0d0f411

Browse files
committed
prompt the user whenever parsing errors/warning from the compiler log fails, including instructions on how to report the issue
1 parent 7109b39 commit 0d0f411

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

server/src/server.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,28 @@ let getCurrentCompilerDiagnosticsForFile = (
174174
let sendUpdatedDiagnostics = () => {
175175
projectsFiles.forEach((projectFile, projectRootPath) => {
176176
let { filesWithDiagnostics } = projectFile;
177-
let content = fs.readFileSync(
178-
path.join(projectRootPath, c.compilerLogPartialPath),
179-
{ encoding: "utf-8" }
180-
);
177+
let compilerLogPath = path.join(projectRootPath, c.compilerLogPartialPath);
178+
let content = fs.readFileSync(compilerLogPath, { encoding: "utf-8" });
181179
let {
182180
done,
183181
result: filesAndErrors,
184182
codeActions,
183+
linesWithParseErrors,
185184
} = utils.parseCompilerLogOutput(content);
186185

186+
if (linesWithParseErrors.length > 0) {
187+
let params: p.ShowMessageParams = {
188+
type: p.MessageType.Warning,
189+
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}).`,
190+
};
191+
let message: p.NotificationMessage = {
192+
jsonrpc: c.jsonrpcVersion,
193+
method: "window/showMessage",
194+
params: params,
195+
};
196+
send(message);
197+
}
198+
187199
projectFile.filesDiagnostics = filesAndErrors;
188200
codeActionsFromDiagnostics = codeActions;
189201

server/src/utils.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ type parsedCompilerLogResult = {
466466
done: boolean;
467467
result: filesDiagnostics;
468468
codeActions: codeActions.filesCodeActions;
469+
linesWithParseErrors: string[];
469470
};
470471
export let parseCompilerLogOutput = (
471472
content: string
@@ -477,6 +478,7 @@ export let parseCompilerLogOutput = (
477478
content: string[];
478479
};
479480
let parsedDiagnostics: parsedDiagnostic[] = [];
481+
let linesWithParseErrors: string[] = [];
480482
let lines = content.split(os.EOL);
481483
let done = false;
482484

@@ -588,17 +590,25 @@ export let parseCompilerLogOutput = (
588590
// 10 ┆
589591
} else if (line.startsWith(" ")) {
590592
// part of the actual diagnostics message
591-
parsedDiagnostics[parsedDiagnostics.length - 1].content.push(
592-
line.slice(2)
593-
);
593+
if (parsedDiagnostics[parsedDiagnostics.length - 1] == null) {
594+
linesWithParseErrors.push(line);
595+
} else {
596+
parsedDiagnostics[parsedDiagnostics.length - 1].content.push(
597+
line.slice(2)
598+
);
599+
}
594600
} else if (line.trim() != "") {
595601
// We'll assume that everything else is also part of the diagnostics too.
596602
// Most of these should have been indented 2 spaces; sadly, some of them
597603
// aren't (e.g. outcome printer printing badly, and certain old ocaml type
598604
// messages not printing with indent). We used to get bug reports and fix
599605
// the messages, but that strategy turned out too slow. One day we should
600606
// revert to not having this branch...
601-
parsedDiagnostics[parsedDiagnostics.length - 1].content.push(line);
607+
if (parsedDiagnostics[parsedDiagnostics.length - 1] == null) {
608+
linesWithParseErrors.push(line);
609+
} else {
610+
parsedDiagnostics[parsedDiagnostics.length - 1].content.push(line);
611+
}
602612
}
603613
}
604614

@@ -635,7 +645,12 @@ export let parseCompilerLogOutput = (
635645
result[file].push(diagnostic);
636646
});
637647

638-
return { done, result, codeActions: foundCodeActions };
648+
return {
649+
done,
650+
result,
651+
codeActions: foundCodeActions,
652+
linesWithParseErrors,
653+
};
639654
};
640655

641656
export let rangeContainsRange = (

0 commit comments

Comments
 (0)