Skip to content

Commit c843ad2

Browse files
committed
Use rescript runtime from configuration if provided
1 parent ff032c8 commit c843ad2

File tree

4 files changed

+57
-27
lines changed

4 files changed

+57
-27
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010

1111
## Contents
1212

13+
- [Contents](#contents)
1314
- [📝 Prerequisite](#-prerequisite)
1415
- [🌈 Supported Themes](#-supported-themes)
1516
- [💡 Features](#-features)
1617
- [📥 Installation](#-installation)
18+
- [Pre-release channel](#pre-release-channel)
1719
- [📦 Commands](#-commands)
1820
- [🔨 Settings](#-settings)
1921
- [🚀 Code Analyzer](#-code-analyzer)
2022
- [Configuring the Code Analyzer](#configuring-the-code-analyzer)
2123
- [Usage](#usage)
2224
- [Caveats](#caveats)
23-
- [🪄 Tips & Tricks](#-tips--tricks)
25+
- [🪄 Tips \& Tricks](#-tips--tricks)
2426
- [Hide generated files](#hide-generated-files)
25-
- [⌨️ Use with Other Editors](#️-use-with-other-editors)
2627
- [📰 Changelog](#-changelog)
2728
- [👏 How to Contribute](#-how-to-contribute)
2829
- [📄 License](#-license)
@@ -102,6 +103,7 @@ You'll find all ReScript specific settings under the scope `rescript.settings`.
102103
| Prompt to Start Build | If there's no ReScript build running already in the opened project, the extension will prompt you and ask if you want to start a build automatically. You can turn off this automatic prompt via the setting `rescript.settings.askToStartBuild`. |
103104
| ReScript Binary Path | The extension will look for the existence of a `node_modules/.bin/rescript` file and use its directory as the `binaryPath`. If it does not find it at the project root (which is where the nearest `rescript.json` resides), it goes up folders in the filesystem recursively until it either finds it (often the case in monorepos) or hits the top level. To override this lookup process, the path can be configured explicitly using the setting `rescript.settings.binaryPath` |
104105
| ReScript Platform Path | The extension will look for the existence of a `node_modules/rescript` directory and use the subdirectory corresponding to the current platform as the `platformPath`. If it does not find it at the project root (which is where the nearest `rescript.json` resides), it goes up folders in the filesystem recursively until it either finds it (often the case in monorepos) or hits the top level. To override this lookup process, the path can be configured explicitly using the setting `rescript.settings.platformPath` |
106+
| ReScript Runtime Path | The extension will look for the existence of a `node_modules/@rescript/runtime` directory (ReScript v12 beta 11+). To override this lookup process, the path can be configured explicitly using the setting `rescript.settings.runtimePath`. |
105107
| Inlay Hints (experimental) | This allows an editor to place annotations inline with text to display type hints. Enable using `rescript.settings.inlayHints.enable: true` |
106108
| Code Lens (experimental) | This tells the editor to add code lenses to function definitions, showing its full type above the definition. Enable using `rescript.settings.codeLens: true` |
107109
| Signature Help | This tells the editor to show signature help when you're writing function calls. Enable using `rescript.settings.signatureHelp.enabled: true` |

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,14 @@
207207
"default": null,
208208
"description": "Path to the directory where platform-specific ReScript binaries are. You can use it if you haven't or don't want to use the installed ReScript from node_modules in your project."
209209
},
210+
"rescript.settings.runtimePath": {
211+
"type": [
212+
"string",
213+
"null"
214+
],
215+
"default": null,
216+
"description": "Optional path to the directory containing the @rescript/runtime package. Set this if your tooling is unable to automatically locate the package in your project."
217+
},
210218
"rescript.settings.compileStatus.enable": {
211219
"type": "boolean",
212220
"default": true,
@@ -268,5 +276,6 @@
268276
},
269277
"dependencies": {
270278
"semver": "^7.7.2"
271-
}
279+
},
280+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
272281
}

server/src/bsc-args/rewatch.ts

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,52 @@ import {
77
IncrementallyCompiledFileInfo,
88
} from "../incrementalCompilation";
99
import type { projectFiles } from "../projectFiles";
10+
import config from "../config";
1011
import { findRescriptRuntimesInProject } from "../find-runtime";
1112

1213
export type RewatchCompilerArgs = {
1314
compiler_args: Array<string>;
1415
parser_args: Array<string>;
1516
};
1617

18+
async function getRuntimePath(
19+
entry: IncrementallyCompiledFileInfo,
20+
): Promise<string | null> {
21+
let rescriptRuntime: string | null =
22+
config.extensionConfiguration.runtimePath ?? null;
23+
24+
if (rescriptRuntime !== null) {
25+
if (debug()) {
26+
console.log(
27+
`Using configured runtime path as RESCRIPT_RUNTIME: ${rescriptRuntime}`,
28+
);
29+
}
30+
return rescriptRuntime;
31+
}
32+
33+
const rescriptRuntimes = await findRescriptRuntimesInProject(
34+
entry.project.workspaceRootPath,
35+
);
36+
37+
if (debug()) {
38+
if (rescriptRuntimes.length === 0) {
39+
console.log(
40+
`Did not find @rescript/runtime directory for ${entry.project.workspaceRootPath}`,
41+
);
42+
} else if (rescriptRuntimes.length > 1) {
43+
console.warn(
44+
`Found multiple @rescript/runtime directories, using the first one as RESCRIPT_RUNTIME: ${rescriptRuntimes.join(", ")}`,
45+
);
46+
} else {
47+
console.log(
48+
`Found @rescript/runtime directory: ${rescriptRuntimes.join(", ")}`,
49+
);
50+
}
51+
}
52+
53+
return rescriptRuntimes.at(0) ?? null;
54+
}
55+
1756
export async function getRewatchBscArgs(
1857
projectsFiles: Map<string, projectFiles>,
1958
entry: IncrementallyCompiledFileInfo,
@@ -90,31 +129,10 @@ export async function getRewatchBscArgs(
90129
(env as any)["RESCRIPT_BSC_EXE"] = bscExe;
91130
}
92131

93-
// TODO: We should check a potential configured value
94-
// Users should be able to provide this themselves if they like.
95-
96-
const rescriptRuntimes = await findRescriptRuntimesInProject(
97-
entry.project.workspaceRootPath,
98-
);
99-
100-
if (debug()) {
101-
if (rescriptRuntimes.length === 0) {
102-
console.log(
103-
`Did not find @rescript/runtime directory for ${entry.project.workspaceRootPath}`,
104-
);
105-
} else if (rescriptRuntimes.length > 1) {
106-
console.warn(
107-
`Found multiple @rescript/runtime directories, using the first one as RESCRIPT_RUNTIME: ${rescriptRuntimes.join(", ")}`,
108-
);
109-
} else {
110-
console.log(
111-
`Found @rescript/runtime directory: ${rescriptRuntimes.join(", ")}`,
112-
);
113-
}
114-
}
132+
let rescriptRuntime: string | null = await getRuntimePath(entry);
115133

116-
if (rescriptRuntimes.length > 0) {
117-
(env as any)["RESCRIPT_RUNTIME"] = rescriptRuntimes[0];
134+
if (rescriptRuntime !== null) {
135+
(env as any)["RESCRIPT_RUNTIME"] = rescriptRuntime;
118136
} else {
119137
// TODO: if no runtime was found, we should let the user know
120138
}

server/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface extensionConfiguration {
1111
codeLens?: boolean;
1212
binaryPath?: string | null;
1313
platformPath?: string | null;
14+
runtimePath?: string | null;
1415
signatureHelp?: {
1516
enabled?: boolean;
1617
forConstructorPayloads?: boolean;

0 commit comments

Comments
 (0)