diff --git a/server/src/constants.ts b/server/src/constants.ts index 81d883b52..f5becaef9 100644 --- a/server/src/constants.ts +++ b/server/src/constants.ts @@ -35,6 +35,7 @@ export let compilerOcamlDirPartialPath = path.join("lib", "ocaml"); export let compilerLogPartialPath = path.join("lib", "bs", ".compiler.log"); export let buildNinjaPartialPath = path.join("lib", "bs", "build.ninja"); export let rewatchLockPartialPath = path.join("lib", "rewatch.lock"); +export let rescriptLockPartialPath = path.join("lib", "rescript.lock"); export let resExt = ".res"; export let resiExt = ".resi"; export let cmiExt = ".cmi"; diff --git a/server/src/incrementalCompilation.ts b/server/src/incrementalCompilation.ts index e180d7369..8a6897c41 100644 --- a/server/src/incrementalCompilation.ts +++ b/server/src/incrementalCompilation.ts @@ -191,6 +191,10 @@ function getBscArgs( entry.project.workspaceRootPath, c.rewatchLockPartialPath ); + const rescriptLockfile = path.resolve( + entry.project.workspaceRootPath, + c.rescriptLockPartialPath + ); let buildSystem: "bsb" | "rewatch" | null = null; let stat: fs.Stats | null = null; @@ -202,9 +206,16 @@ function getBscArgs( stat = fs.statSync(rewatchLockfile); buildSystem = "rewatch"; } catch {} + try { + stat = fs.statSync(rescriptLockfile); + buildSystem = "rewatch"; + } + catch {} if (buildSystem == null) { console.log("Did not find build.ninja or rewatch.lock, cannot proceed.."); return Promise.resolve(null); + } else if (debug()) { + console.log(`Using build system: ${buildSystem} for ${entry.file.sourceFilePath}`); } const bsbCacheEntry = entry.buildNinja; const rewatchCacheEntry = entry.buildRewatch; @@ -298,20 +309,28 @@ function getBscArgs( entry.project.workspaceRootPath, "node_modules/@rolandpeelen/rewatch/rewatch" ); + let rescriptRewatchPath = null; 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") - } + rescriptRewatchPath = await utils.findRewatchBinary(entry.project.workspaceRootPath) + } + + if (semver.valid(project.rescriptVersion) && + semver.satisfies(project.rescriptVersion as string, ">=12.0.0-beta.1", { includePrerelease: true })) { + rescriptRewatchPath = await utils.findRescriptExeBinary(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 rewatchArguments = semver.satisfies(project.rescriptVersion, ">12.0.0-alpha.14", { includePrerelease: true }) ? [ "compiler-args", "--rescript-version", diff --git a/server/src/utils.ts b/server/src/utils.ts index 0cd3ae336..ae2639252 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -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" | "rewatch.exe" + binary: "bsc.exe" | "rescript-editor-analysis.exe" | "rescript" | "rewatch.exe" | "rescript.exe" ) => { if (config.extensionConfiguration.platformPath != null) { return path.join(config.extensionConfiguration.platformPath, binary); @@ -124,6 +124,8 @@ let findBinary = async ( binaryPath = binPaths.rescript_editor_analysis_exe } else if (binary == "rewatch.exe") { binaryPath = binPaths.rewatch_exe + } else if (binary == "rescript.exe") { + binaryPath = binPaths.rescript_exe } } else { binaryPath = path.join(rescriptDir, c.platformDir, binary) @@ -148,6 +150,9 @@ export let findEditorAnalysisBinary = (projectRootPath: p.DocumentUri | null) => export let findRewatchBinary = (projectRootPath: p.DocumentUri | null) => findBinary(projectRootPath, "rewatch.exe"); +export let findRescriptExeBinary = (projectRootPath: p.DocumentUri | null) => + findBinary(projectRootPath, "rescript.exe"); + type execResult = | { kind: "success";