From 9dde0676f7726e8b45c2e68fcc92dccc57d07a4f Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Mon, 5 Sep 2022 20:51:44 +0200 Subject: [PATCH] prompt the user whenever parsing errors/warning from the compiler log fails, including instructions on how to report the issue --- server/src/server.ts | 20 ++++++++++++++++---- server/src/utils.ts | 25 ++++++++++++++++++++----- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 1c5e6c2e8..08cf31945 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -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; diff --git a/server/src/utils.ts b/server/src/utils.ts index 11c41c11c..d92ad1a81 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -466,6 +466,7 @@ type parsedCompilerLogResult = { done: boolean; result: filesDiagnostics; codeActions: codeActions.filesCodeActions; + linesWithParseErrors: string[]; }; export let parseCompilerLogOutput = ( content: string @@ -477,6 +478,7 @@ export let parseCompilerLogOutput = ( content: string[]; }; let parsedDiagnostics: parsedDiagnostic[] = []; + let linesWithParseErrors: string[] = []; let lines = content.split(os.EOL); let done = false; @@ -588,9 +590,13 @@ 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 @@ -598,7 +604,11 @@ export let parseCompilerLogOutput = ( // 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); + } } } @@ -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 = (