Skip to content

Commit d8e1d7a

Browse files
authored
Work with the newest rescript package (#106)
Need to find the new package's name for the formatter. Fixes #104
1 parent aa1712b commit d8e1d7a

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

server/src/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export let bscExePartialPath = path.join(
99
process.platform,
1010
"bsc.exe"
1111
);
12+
export let bscExeReScriptPartialPath = path.join(
13+
"node_modules",
14+
"rescript",
15+
process.platform,
16+
"bsc.exe"
17+
);
1218

1319
// can't use the native bsb since we might need the watcher -w flag, which is only in the js wrapper
1420
// export let bsbPartialPath = path.join('node_modules', 'bs-platform', process.platform, 'bsb.exe');

server/src/server.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ function onMessage(msg: m.Message) {
428428
if (bscExeDir === null) {
429429
let params: p.ShowMessageParams = {
430430
type: p.MessageType.Error,
431-
message: `Cannot find a nearby ${c.bscExePartialPath}. It's needed for formatting.`,
431+
message: `Cannot find a nearby bsc.exe in bs-platform or rescript. It's needed for formatting.`,
432432
};
433433
let response: m.NotificationMessage = {
434434
jsonrpc: c.jsonrpcVersion,
@@ -438,7 +438,9 @@ function onMessage(msg: m.Message) {
438438
send(fakeSuccessResponse);
439439
send(response);
440440
} else {
441-
let resolvedBscExePath = path.join(bscExeDir, c.bscExePartialPath);
441+
let bscExePath1 = path.join(bscExeDir, c.bscExeReScriptPartialPath);
442+
let bscExePath2 = path.join(bscExeDir, c.bscExePartialPath);
443+
let resolvedBscExePath = fs.existsSync(bscExePath1) ? bscExePath1 : bscExePath2;
442444
// code will always be defined here, even though technically it can be undefined
443445
let code = getOpenedFileContent(params.textDocument.uri);
444446
let formattedResult = utils.formatUsingValidBscExePath(

server/src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ export let findBscExeDirOfFile = (
4747
source: p.DocumentUri
4848
): null | p.DocumentUri => {
4949
let dir = path.dirname(source);
50-
let bscPath = path.join(dir, c.bscExePartialPath);
51-
if (fs.existsSync(bscPath)) {
50+
let bscExePath1 = path.join(dir, c.bscExeReScriptPartialPath);
51+
let bscExePath2 = path.join(dir, c.bscExePartialPath);
52+
if (fs.existsSync(bscExePath1) || fs.existsSync(bscExePath2)) {
5253
return dir;
5354
} else {
5455
if (dir === source) {

0 commit comments

Comments
 (0)