From ae494efbc524d280bf2a8211ef0d143dc352e13c Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 7 Mar 2024 13:12:03 +0100 Subject: [PATCH 1/2] a few fixes for incremental compilation --- server/src/incrementalCompilation.ts | 57 +++++++++++++++++----------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/server/src/incrementalCompilation.ts b/server/src/incrementalCompilation.ts index 74cef0d61..260f99344 100644 --- a/server/src/incrementalCompilation.ts +++ b/server/src/incrementalCompilation.ts @@ -127,6 +127,7 @@ export function recreateIncrementalFileFolder(projectRootPath: string) { removeIncrementalFileFolder(projectRootPath, () => { fs.mkdir( path.resolve(projectRootPath, INCREMENTAL_FILE_FOLDER_LOCATION), + { recursive: true }, (_) => {} ); }); @@ -177,23 +178,22 @@ function getBscArgs( entry.project.rootPath, "lib/bs/build.ninja" ); - const cacheEntry = entry.buildNinja; let stat: fs.Stats | null = null; - if (cacheEntry != null) { - try { - stat = fs.statSync(buildNinjaPath); - } catch { - if (debug()) { - console.log("Did not find build.ninja, cannot proceed.."); - } - } - if (stat != null) { - if (cacheEntry.fileMtime >= stat.mtimeMs) { - return Promise.resolve(cacheEntry.rawExtracted); - } - } else { - return Promise.resolve(null); + try { + stat = fs.statSync(buildNinjaPath); + } catch { + if (debug()) { + console.log("Did not find build.ninja, cannot proceed.."); } + return Promise.resolve(null); + } + const cacheEntry = entry.buildNinja; + if ( + cacheEntry != null && + stat != null && + cacheEntry.fileMtime >= stat.mtimeMs + ) { + return Promise.resolve(cacheEntry.rawExtracted); } return new Promise((resolve, _reject) => { function resolveResult(result: Array) { @@ -471,20 +471,26 @@ async function compileContents( onCompilationFinished?: () => void ) { const triggerToken = entry.compilation?.triggerToken; - const callArgs = await entry.project.callArgs; + let callArgs = await entry.project.callArgs; if (callArgs == null) { - if (debug()) { - console.log( - "Could not figure out call args. Maybe build.ninja does not exist yet?" - ); + const callArgsRetried = await figureOutBscArgs(entry); + if (callArgsRetried != null) { + callArgs = callArgsRetried; + entry.project.callArgs = Promise.resolve(callArgsRetried); + } else { + if (debug()) { + console.log( + "Could not figure out call args. Maybe build.ninja does not exist yet?" + ); + } + return; } - return; } const startTime = performance.now(); if (!fs.existsSync(entry.project.incrementalFolderPath)) { try { - fs.mkdirSync(entry.project.incrementalFolderPath); + fs.mkdirSync(entry.project.incrementalFolderPath, { recursive: true }); } catch {} } @@ -552,7 +558,12 @@ async function compileContents( entry.project.incrementalFolderPath, "error.log" ); - fs.writeFileSync(logfile, stderr); + fs.writeFileSync( + logfile, + `== BSC ARGS ==\n${callArgs?.join( + " " + )}\n\n== OUTPUT ==\n${stderr}` + ); let params: p.ShowMessageParams = { type: p.MessageType.Warning, message: `[Incremental typechecking] Something might have gone wrong with incremental type checking. Check out the [error log](file://${logfile}) and report this issue please.`, From 045073b844bbf5ca0beaeb7e7c24451157cdbdca Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 7 Mar 2024 13:14:01 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f33de9490..0dfdeb9af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ ## master +#### :bug: Bug Fix + +- Stability fixes for the experimental incremental compilation mode. https://github.com/rescript-lang/rescript-vscode/pull/945 + ## 1.46.0 #### :bug: Bug Fix