1
1
import * as path from "path" ;
2
2
import * as utils from "../utils" ;
3
3
import * as cp from "node:child_process" ;
4
+ import * as p from "vscode-languageserver-protocol" ;
4
5
import semver from "semver" ;
5
6
import {
6
7
debug ,
@@ -9,6 +10,7 @@ import {
9
10
import type { projectFiles } from "../projectFiles" ;
10
11
import config from "../config" ;
11
12
import { findRescriptRuntimesInProject } from "../find-runtime" ;
13
+ import { jsonrpcVersion } from "../constants" ;
12
14
13
15
export type RewatchCompilerArgs = {
14
16
compiler_args : Array < string > ;
@@ -54,6 +56,7 @@ async function getRuntimePath(
54
56
}
55
57
56
58
export async function getRewatchBscArgs (
59
+ send : ( msg : p . Message ) => void ,
57
60
projectsFiles : Map < string , projectFiles > ,
58
61
entry : IncrementallyCompiledFileInfo ,
59
62
) : Promise < RewatchCompilerArgs | null > {
@@ -129,17 +132,33 @@ export async function getRewatchBscArgs(
129
132
( env as any ) [ "RESCRIPT_BSC_EXE" ] = bscExe ;
130
133
}
131
134
132
- let rescriptRuntime : string | null = await getRuntimePath ( entry ) ;
133
-
135
+ // For ReScript >= 12.0.0-beta.11 we need to set RESCRIPT_RUNTIME
134
136
if (
135
- rescriptRuntime !== null &&
136
137
semver . satisfies ( project . rescriptVersion , ">=12.0.0-beta.11" , {
137
138
includePrerelease : true ,
138
139
} )
139
140
) {
140
- ( env as any ) [ "RESCRIPT_RUNTIME" ] = rescriptRuntime ;
141
- } else {
142
- // TODO: if no runtime was found, we should let the user know
141
+ let rescriptRuntime : string | null = await getRuntimePath ( entry ) ;
142
+
143
+ if ( rescriptRuntime !== null ) {
144
+ ( env as any ) [ "RESCRIPT_RUNTIME" ] = rescriptRuntime ;
145
+ } else {
146
+ // If no runtime was found, we should let the user know.
147
+ let params : p . ShowMessageParams = {
148
+ type : p . MessageType . Error ,
149
+ message :
150
+ `[Incremental type checking] The @rescript/runtime package was not found in your project. ` +
151
+ `It is normally included with ReScript, but either it's missing or could not be detected. ` +
152
+ `Check that it exists in your dependencies, or configure 'rescript.settings.runtimePath' to point to it. ` +
153
+ `Without this package, incremental type checking may not work as expected.` ,
154
+ } ;
155
+ let message : p . NotificationMessage = {
156
+ jsonrpc : jsonrpcVersion ,
157
+ method : "window/showMessage" ,
158
+ params : params ,
159
+ } ;
160
+ send ( message ) ;
161
+ }
143
162
}
144
163
145
164
const compilerArgs = JSON . parse (
0 commit comments