Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

- Find `@rescript/runtime` for Rewatch compiler-args call. https://github.com/rescript-lang/rescript-vscode/pull/1125
- Use `prepareRename` command (when a new enough ReScript version is used) to speed up the `rename` command. https://github.com/rescript-lang/rescript-vscode/pull/1124
- Use `compiler-info.json` to find the `@rescript/runtime` and `bsc.exe` if available.

## 1.64.0

Expand Down
9 changes: 4 additions & 5 deletions server/src/bsc-args/rewatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ async function getRuntimePath(

export async function getRewatchBscArgs(
send: (msg: p.Message) => void,
bscBinaryLocation: string | null,
projectsFiles: Map<string, projectFiles>,
entry: IncrementallyCompiledFileInfo,
): Promise<RewatchCompilerArgs | null> {
Expand Down Expand Up @@ -124,12 +125,10 @@ export async function getRewatchBscArgs(
"--compiler-args",
entry.file.sourceFilePath,
];
const bscExe = await utils.findBscExeBinary(
entry.project.workspaceRootPath,
);

const env: NodeJS.ProcessEnv = {};
if (bscExe != null) {
env["RESCRIPT_BSC_EXE"] = bscExe;
if (bscBinaryLocation != null) {
env["RESCRIPT_BSC_EXE"] = bscBinaryLocation;
}

// For ReScript >= 12.0.0-beta.11 we need to set RESCRIPT_RUNTIME
Expand Down
5 changes: 5 additions & 0 deletions server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export let rescriptJsonPartialPath = "rescript.json";
export let compilerDirPartialPath = path.join("lib", "bs");
export let compilerOcamlDirPartialPath = path.join("lib", "ocaml");
export let compilerLogPartialPath = path.join("lib", "bs", ".compiler.log");
export let compilerInfoPartialPath = path.join(
"lib",
"bs",
"compiler-info.json",
);
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");
Expand Down
19 changes: 16 additions & 3 deletions server/src/find-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readdir, stat as statAsync } from "fs/promises";
import { readdir, stat as statAsync, readFile } from "fs/promises";
import { join, resolve } from "path";
import { compilerInfoPartialPath } from "./constants";

// Efficient parallel folder traversal to find node_modules directories
async function findNodeModulesDirs(
Expand Down Expand Up @@ -91,7 +92,19 @@ async function findRescriptRuntimeInAlternativeLayout(
return results;
}

async function findRuntimePath(project: string) {
async function findRuntimePath(project: string): Promise<string[]> {
// Try a compiler-info.json file first
const compilerInfo = resolve(project, compilerInfoPartialPath);
try {
const contents = await readFile(compilerInfo, "utf8");
const compileInfo: { runtime_path?: string } = JSON.parse(contents);
if (compileInfo && compileInfo.runtime_path) {
return [compileInfo.runtime_path];
}
} catch {
// Ignore errors, fallback to node_modules search
}

// Find all node_modules directories using efficient traversal
const node_modules = await findNodeModulesDirs(project);

Expand Down Expand Up @@ -136,7 +149,7 @@ async function findRuntimePath(project: string) {
return rescriptRuntimeDirs.map((runtime) => resolve(runtime));
}

function findRuntimeCached() {
function findRuntimeCached(): (project: string) => Promise<string[]> {
const cache = new Map<string, string[]>();
return async (project: string) => {
if (cache.has(project)) {
Expand Down
7 changes: 6 additions & 1 deletion server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ export async function getBscArgs(
): Promise<BsbCompilerArgs | RewatchCompilerArgs | null> {
return entry.buildSystem === "bsb"
? await getBsbBscArgs(entry)
: await getRewatchBscArgs(send, projectsFiles, entry);
: await getRewatchBscArgs(
send,
entry.project.bscBinaryLocation,
projectsFiles,
entry,
);
}

function argCouples(argList: string[]): string[][] {
Expand Down
14 changes: 14 additions & 0 deletions server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ let findBinary = async (
return path.join(config.extensionConfiguration.platformPath, binary);
}

if (projectRootPath !== null && binary === "bsc.exe") {
try {
const compilerInfo = path.resolve(
projectRootPath,
c.compilerInfoPartialPath,
);
const contents = await fsAsync.readFile(compilerInfo, "utf8");
const compileInfo = JSON.parse(contents);
if (compileInfo && compileInfo.runtime_path) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hackwaly problem is here!
Sorry about this, copy paste error

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we release a hotfix for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a new prerelease for this, please let me know how it goes.

return compileInfo.runtime_path;
}
} catch {}
}

const rescriptDir = lookup.findFilePathFromProjectRoot(
projectRootPath,
path.join("node_modules", "rescript"),
Expand Down
Loading