Skip to content

Commit 3d1700f

Browse files
committed
Send message to lsp client when runtime was not found.
1 parent 39b7ed2 commit 3d1700f

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

server/src/bsc-args/rewatch.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "path";
22
import * as utils from "../utils";
33
import * as cp from "node:child_process";
4+
import * as p from "vscode-languageserver-protocol";
45
import semver from "semver";
56
import {
67
debug,
@@ -9,6 +10,7 @@ import {
910
import type { projectFiles } from "../projectFiles";
1011
import config from "../config";
1112
import { findRescriptRuntimesInProject } from "../find-runtime";
13+
import { jsonrpcVersion } from "../constants";
1214

1315
export type RewatchCompilerArgs = {
1416
compiler_args: Array<string>;
@@ -54,6 +56,7 @@ async function getRuntimePath(
5456
}
5557

5658
export 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(

server/src/incrementalCompilation.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,12 @@ export function cleanUpIncrementalFiles(
180180
}
181181

182182
export async function getBscArgs(
183+
send: (msg: p.Message) => void,
183184
entry: IncrementallyCompiledFileInfo,
184185
): Promise<BsbCompilerArgs | RewatchCompilerArgs | null> {
185186
return entry.buildSystem === "bsb"
186187
? await getBsbBscArgs(entry)
187-
: await getRewatchBscArgs(projectsFiles, entry);
188+
: await getRewatchBscArgs(send, projectsFiles, entry);
188189
}
189190

190191
function argCouples(argList: string[]): string[][] {
@@ -331,6 +332,7 @@ function triggerIncrementalCompilationOfFile(
331332
};
332333

333334
incrementalFileCacheEntry.project.callArgs = figureOutBscArgs(
335+
send,
334336
incrementalFileCacheEntry,
335337
);
336338
originalTypeFileToFilePath.set(
@@ -371,7 +373,10 @@ function verifyTriggerToken(filePath: string, triggerToken: number): boolean {
371373

372374
const isWindows = os.platform() === "win32";
373375

374-
async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
376+
async function figureOutBscArgs(
377+
send: (msg: p.Message) => void,
378+
entry: IncrementallyCompiledFileInfo,
379+
) {
375380
const project = projectsFiles.get(entry.project.rootPath);
376381
if (project?.rescriptVersion == null) {
377382
if (debug()) {
@@ -382,7 +387,7 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
382387
}
383388
return null;
384389
}
385-
const res = await getBscArgs(entry);
390+
const res = await getBscArgs(send, entry);
386391
if (res == null) return null;
387392
let astArgs: Array<Array<string>> = [];
388393
let buildArgs: Array<Array<string>> = [];
@@ -483,7 +488,7 @@ async function compileContents(
483488
const triggerToken = entry.compilation?.triggerToken;
484489
let callArgs = await entry.project.callArgs;
485490
if (callArgs == null) {
486-
const callArgsRetried = await figureOutBscArgs(entry);
491+
const callArgsRetried = await figureOutBscArgs(send, entry);
487492
if (callArgsRetried != null) {
488493
callArgs = callArgsRetried;
489494
entry.project.callArgs = Promise.resolve(callArgsRetried);

0 commit comments

Comments
 (0)