Skip to content

Use platform specific rewatch binary #1101

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 3 commits into from
Jun 3, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
#### :rocket: New Feature

- Find `bsc.exe` and `rescript-code-editor-analysis.exe` from platform-specific packages used by ReScript `v12.0.0-alpha.13`+.https://github.com/rescript-lang/rescript-vscode/pull/1092
- Find `rewatch.exe` from platform-specific packages used by ReScript `v12.0.0-alpha.13`+. https://github.com/rescript-lang/rescript-vscode/pull/1101

#### :bug: Bug fix

29 changes: 26 additions & 3 deletions server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ type IncrementallyCompiledFileInfo = {
/** Location of the original type file. */
originalTypeFileLocation: string;
};
buildSystem: "bsb" | "rewatch";
/** Cache for build.ninja assets. */
buildNinja: {
/** When build.ninja was last modified. Used as a cache key. */
@@ -223,14 +224,16 @@ function getBscArgs(
) {
return Promise.resolve(rewatchCacheEntry.compilerArgs);
}
return new Promise((resolve, _reject) => {
return new Promise(async(resolve, _reject) => {
function resolveResult(result: Array<string> | RewatchCompilerArgs) {
if (stat != null && Array.isArray(result)) {
entry.buildSystem = "bsb";
entry.buildNinja = {
fileMtime: stat.mtimeMs,
rawExtracted: result,
};
} else if (!Array.isArray(result)) {
entry.buildSystem = "rewatch";
entry.buildRewatch = {
lastFile: entry.file.sourceFilePath,
compilerArgs: result,
@@ -295,6 +298,20 @@ function getBscArgs(
entry.project.workspaceRootPath,
"node_modules/@rolandpeelen/rewatch/rewatch"
);
if (semver.valid(project.rescriptVersion) &&
semver.satisfies(project.rescriptVersion as string, ">11", { includePrerelease: true })) {
const rescriptRewatchPath = await utils.findRewatchBinary(entry.project.workspaceRootPath)
if (rescriptRewatchPath != null) {
rewatchPath = rescriptRewatchPath;
if (debug()) {
console.log(`Found rewatch binary bundled with v12: ${rescriptRewatchPath}`)
}
} else {
if (debug()) {
console.log("Did not find rewatch binary bundled with v12")
}
}
}
const compilerArgs = JSON.parse(
cp
.execFileSync(rewatchPath, [
@@ -445,6 +462,7 @@ function triggerIncrementalCompilationOfFile(
bscBinaryLocation,
incrementalFolderPath,
},
buildSystem: foundRewatchLockfileInProjectRoot ? "rewatch" : "bsb",
buildRewatch: null,
buildNinja: null,
compilation: null,
@@ -531,6 +549,7 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
path.resolve(entry.project.rootPath, c.compilerDirPartialPath, value)
);
} else {
// TODO: once ReScript v12 is out we can remove this check for `.`
if (value === ".") {
callArgs.push(
"-I",
@@ -604,11 +623,15 @@ async function compileContents(

try {
fs.writeFileSync(entry.file.incrementalFilePath, fileContent);

let cwd = entry.buildSystem === "bsb" ? entry.project.rootPath : path.resolve(entry.project.rootPath, c.compilerDirPartialPath)
if (debug()) {
console.log(`About to invoke bsc from \"${cwd}\", used ${entry.buildSystem}`);
console.log(`${entry.project.bscBinaryLocation} ${callArgs.map(c => `"${c}"`).join(" ")}`);
}
const process = cp.execFile(
entry.project.bscBinaryLocation,
callArgs,
{ cwd: entry.project.rootPath },
{ cwd },
async (error, _stdout, stderr) => {
if (!error?.killed) {
if (debug())
7 changes: 6 additions & 1 deletion server/src/utils.ts
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ export let findProjectRootOfFile = (
// We won't know which version is in the project root until we read and parse `{project_root}/node_modules/rescript/package.json`
let findBinary = async (
projectRootPath: p.DocumentUri | null,
binary: "bsc.exe" | "rescript-editor-analysis.exe" | "rescript"
binary: "bsc.exe" | "rescript-editor-analysis.exe" | "rescript" | "rewatch.exe"
) => {
if (config.extensionConfiguration.platformPath != null) {
return path.join(config.extensionConfiguration.platformPath, binary);
@@ -122,6 +122,8 @@ let findBinary = async (
binaryPath = binPaths.bsc_exe
} else if (binary == "rescript-editor-analysis.exe") {
binaryPath = binPaths.rescript_editor_analysis_exe
} else if (binary == "rewatch.exe") {
binaryPath = binPaths.rewatch_exe
}
} else {
binaryPath = path.join(rescriptDir, c.platformDir, binary)
@@ -143,6 +145,9 @@ export let findBscExeBinary = (projectRootPath: p.DocumentUri | null) =>
export let findEditorAnalysisBinary = (projectRootPath: p.DocumentUri | null) =>
findBinary(projectRootPath, "rescript-editor-analysis.exe");

export let findRewatchBinary = (projectRootPath: p.DocumentUri | null) =>
findBinary(projectRootPath, "rewatch.exe");

type execResult =
| {
kind: "success";