Skip to content

Commit d582510

Browse files
authoredMar 7, 2024··
Fixes for incremental compilation (#945)
* a few fixes for incremental compilation * changelog
1 parent d402233 commit d582510

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
## master
1414

15+
#### :bug: Bug Fix
16+
17+
- Stability fixes for the experimental incremental compilation mode. https://github.com/rescript-lang/rescript-vscode/pull/945
18+
1519
## 1.46.0
1620

1721
#### :bug: Bug Fix

‎server/src/incrementalCompilation.ts

+34-23
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export function recreateIncrementalFileFolder(projectRootPath: string) {
127127
removeIncrementalFileFolder(projectRootPath, () => {
128128
fs.mkdir(
129129
path.resolve(projectRootPath, INCREMENTAL_FILE_FOLDER_LOCATION),
130+
{ recursive: true },
130131
(_) => {}
131132
);
132133
});
@@ -177,23 +178,22 @@ function getBscArgs(
177178
entry.project.rootPath,
178179
"lib/bs/build.ninja"
179180
);
180-
const cacheEntry = entry.buildNinja;
181181
let stat: fs.Stats | null = null;
182-
if (cacheEntry != null) {
183-
try {
184-
stat = fs.statSync(buildNinjaPath);
185-
} catch {
186-
if (debug()) {
187-
console.log("Did not find build.ninja, cannot proceed..");
188-
}
189-
}
190-
if (stat != null) {
191-
if (cacheEntry.fileMtime >= stat.mtimeMs) {
192-
return Promise.resolve(cacheEntry.rawExtracted);
193-
}
194-
} else {
195-
return Promise.resolve(null);
182+
try {
183+
stat = fs.statSync(buildNinjaPath);
184+
} catch {
185+
if (debug()) {
186+
console.log("Did not find build.ninja, cannot proceed..");
196187
}
188+
return Promise.resolve(null);
189+
}
190+
const cacheEntry = entry.buildNinja;
191+
if (
192+
cacheEntry != null &&
193+
stat != null &&
194+
cacheEntry.fileMtime >= stat.mtimeMs
195+
) {
196+
return Promise.resolve(cacheEntry.rawExtracted);
197197
}
198198
return new Promise((resolve, _reject) => {
199199
function resolveResult(result: Array<string>) {
@@ -471,20 +471,26 @@ async function compileContents(
471471
onCompilationFinished?: () => void
472472
) {
473473
const triggerToken = entry.compilation?.triggerToken;
474-
const callArgs = await entry.project.callArgs;
474+
let callArgs = await entry.project.callArgs;
475475
if (callArgs == null) {
476-
if (debug()) {
477-
console.log(
478-
"Could not figure out call args. Maybe build.ninja does not exist yet?"
479-
);
476+
const callArgsRetried = await figureOutBscArgs(entry);
477+
if (callArgsRetried != null) {
478+
callArgs = callArgsRetried;
479+
entry.project.callArgs = Promise.resolve(callArgsRetried);
480+
} else {
481+
if (debug()) {
482+
console.log(
483+
"Could not figure out call args. Maybe build.ninja does not exist yet?"
484+
);
485+
}
486+
return;
480487
}
481-
return;
482488
}
483489

484490
const startTime = performance.now();
485491
if (!fs.existsSync(entry.project.incrementalFolderPath)) {
486492
try {
487-
fs.mkdirSync(entry.project.incrementalFolderPath);
493+
fs.mkdirSync(entry.project.incrementalFolderPath, { recursive: true });
488494
} catch {}
489495
}
490496

@@ -552,7 +558,12 @@ async function compileContents(
552558
entry.project.incrementalFolderPath,
553559
"error.log"
554560
);
555-
fs.writeFileSync(logfile, stderr);
561+
fs.writeFileSync(
562+
logfile,
563+
`== BSC ARGS ==\n${callArgs?.join(
564+
" "
565+
)}\n\n== OUTPUT ==\n${stderr}`
566+
);
556567
let params: p.ShowMessageParams = {
557568
type: p.MessageType.Warning,
558569
message: `[Incremental typechecking] Something might have gone wrong with incremental type checking. Check out the [error log](file://${logfile}) and report this issue please.`,

0 commit comments

Comments
 (0)
Please sign in to comment.