Skip to content

Commit fa64b08

Browse files
authored
Analysis: resolve @rescript/runtime via environment variable RESCRIPT_RUNTIME (#8023)
* Fix hover for Stdlib module * fmt * Pass runtime via environment variable * Revert test files * Add changelog * Revert Hover.ml * Improve comment
1 parent 8988351 commit fa64b08

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
#### :house: Internal
3131

32+
- Editor: resolve @rescript/runtime via environment variable RESCRIPT_RUNTIME. https://github.com/rescript-lang/rescript/pull/8023
33+
3234
# 12.0.0-rc.4
3335

3436
#### :boom: Breaking Change

analysis/src/BuildSystem.ml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,39 @@ let namespacedName namespace name =
55

66
let ( /+ ) = Filename.concat
77

8+
(*
9+
Editor tooling can more accurately resolve the runtime path and will try and pass it via an environment variable.
10+
Example path: "test-stdlib/node_modules/.pnpm/@[email protected]/node_modules/@rescript/runtime"
11+
*)
12+
813
let getRuntimeDir rootPath =
914
match !Cfg.isDocGenFromCompiler with
1015
| false -> (
11-
let result =
12-
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
13-
"@rescript/runtime"
14-
in
15-
match result with
16-
| Some path -> Some path
17-
| None ->
18-
let message = "@rescript/runtime could not be found" in
19-
Log.log message;
20-
None)
16+
(* First check RESCRIPT_RUNTIME environment variable, like bsc does *)
17+
match Sys.getenv_opt "RESCRIPT_RUNTIME" with
18+
| Some envPath ->
19+
if Debug.verbose () then
20+
Printf.printf "[getRuntimeDir] Using RESCRIPT_RUNTIME=%s\n" envPath;
21+
Some envPath
22+
| None -> (
23+
let result =
24+
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
25+
"@rescript/runtime"
26+
in
27+
match result with
28+
| Some path ->
29+
if Debug.verbose () then
30+
Printf.printf "[getRuntimeDir] Resolved via node_modules: %s\n" path;
31+
Some path
32+
| None ->
33+
let message = "@rescript/runtime could not be found" in
34+
Log.log message;
35+
if Debug.verbose () then
36+
Printf.printf
37+
"[getRuntimeDir] Failed to resolve @rescript/runtime from \
38+
rootPath=%s\n"
39+
rootPath;
40+
None))
2141
| true -> Some rootPath
2242

2343
let getLibBs path = Files.ifExists (path /+ "lib" /+ "bs")

0 commit comments

Comments
 (0)