Skip to content

Fixes for incremental compilation #945

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 2 commits into from
Mar 7, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 34 additions & 23 deletions server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export function recreateIncrementalFileFolder(projectRootPath: string) {
removeIncrementalFileFolder(projectRootPath, () => {
fs.mkdir(
path.resolve(projectRootPath, INCREMENTAL_FILE_FOLDER_LOCATION),
{ recursive: true },
(_) => {}
);
});
Expand Down Expand Up @@ -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<string>) {
Expand Down Expand Up @@ -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 {}
}

Expand Down Expand Up @@ -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.`,
Expand Down