11import * as path from "path" ;
22import * as utils from "../utils" ;
33import * as cp from "node:child_process" ;
4+ import * as p from "vscode-languageserver-protocol" ;
45import semver from "semver" ;
56import {
67 debug ,
@@ -9,6 +10,7 @@ import {
910import type { projectFiles } from "../projectFiles" ;
1011import config from "../config" ;
1112import { findRescriptRuntimesInProject } from "../find-runtime" ;
13+ import { jsonrpcVersion } from "../constants" ;
1214
1315export type RewatchCompilerArgs = {
1416 compiler_args : Array < string > ;
@@ -54,6 +56,7 @@ async function getRuntimePath(
5456}
5557
5658export async function getRewatchBscArgs (
59+ send : ( msg : p . Message ) => void ,
5760 projectsFiles : Map < string , projectFiles > ,
5861 entry : IncrementallyCompiledFileInfo ,
5962) : Promise < RewatchCompilerArgs | null > {
@@ -129,17 +132,33 @@ export async function getRewatchBscArgs(
129132 ( env as any ) [ "RESCRIPT_BSC_EXE" ] = bscExe ;
130133 }
131134
132- let rescriptRuntime : string | null = await getRuntimePath ( entry ) ;
133-
135+ // For ReScript >= 12.0.0-beta.11 we need to set RESCRIPT_RUNTIME
134136 if (
135- rescriptRuntime !== null &&
136137 semver . satisfies ( project . rescriptVersion , ">=12.0.0-beta.11" , {
137138 includePrerelease : true ,
138139 } )
139140 ) {
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+ }
143162 }
144163
145164 const compilerArgs = JSON . parse (
0 commit comments