@@ -4,6 +4,7 @@ import * as v from "vscode-languageserver";
4
4
import * as rpc from "vscode-jsonrpc/node" ;
5
5
import * as path from "path" ;
6
6
import fs from "fs" ;
7
+ import os from "os" ;
7
8
// TODO: check DidChangeWatchedFilesNotification.
8
9
import {
9
10
DidOpenTextDocumentNotification ,
@@ -24,9 +25,11 @@ import { filesDiagnostics } from "./utils";
24
25
25
26
interface extensionConfiguration {
26
27
askToStartBuild : boolean ;
28
+ binaryPath : string | null ;
27
29
}
28
30
let extensionConfiguration : extensionConfiguration = {
29
31
askToStartBuild : true ,
32
+ binaryPath : null ,
30
33
} ;
31
34
let pullConfigurationPeriodically : NodeJS . Timeout | null = null ;
32
35
@@ -232,7 +235,12 @@ let openedFile = (fileUri: string, fileContent: string) => {
232
235
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
233
236
// stale. Use that logic
234
237
// TODO: close watcher when lang-server shuts down
235
- if ( utils . findNodeBuildOfProjectRoot ( projectRootPath ) != null ) {
238
+ if (
239
+ utils . findNodeBuildOfProjectRoot (
240
+ projectRootPath ,
241
+ extensionConfiguration . binaryPath
242
+ ) != null
243
+ ) {
236
244
let payload : clientSentBuildAction = {
237
245
title : c . startBuildAction ,
238
246
projectRootPath : projectRootPath ,
@@ -254,7 +262,19 @@ let openedFile = (fileUri: string, fileContent: string) => {
254
262
// handle in the isResponseMessage check in the message handling way
255
263
// below
256
264
} else {
257
- // we should send something to say that we can't find bsb.exe. But right now we'll silently not do anything
265
+ let binaryPath = extensionConfiguration . binaryPath === null
266
+ ? path . join ( projectRootPath , "node_modules" , ".bin" )
267
+ : extensionConfiguration . binaryPath ;
268
+
269
+ let request : p . NotificationMessage = {
270
+ jsonrpc : c . jsonrpcVersion ,
271
+ method : "window/showMessage" ,
272
+ params : {
273
+ type : p . MessageType . Error ,
274
+ message : `Can't find ReScript binary on path ${ binaryPath } ` ,
275
+ } ,
276
+ } ;
277
+ send ( request ) ;
258
278
}
259
279
}
260
280
@@ -593,7 +613,11 @@ function format(msg: p.RequestMessage): Array<p.Message> {
593
613
} else {
594
614
// code will always be defined here, even though technically it can be undefined
595
615
let code = getOpenedFileContent ( params . textDocument . uri ) ;
596
- let formattedResult = utils . formatCode ( filePath , code ) ;
616
+ let formattedResult = utils . formatCode (
617
+ extensionConfiguration . binaryPath ,
618
+ filePath ,
619
+ code
620
+ ) ;
597
621
if ( formattedResult . kind === "success" ) {
598
622
let max = code . length ;
599
623
let result : p . TextEdit [ ] = [
@@ -933,6 +957,17 @@ function onMessage(msg: p.Message) {
933
957
934
958
if ( initialConfiguration != null ) {
935
959
extensionConfiguration = initialConfiguration ;
960
+ if (
961
+ extensionConfiguration . binaryPath !== null &&
962
+ extensionConfiguration . binaryPath [ 0 ] === "~"
963
+ ) {
964
+ // What should happen if the path contains the home directory symbol?
965
+ // This situation is handled below, but maybe it isn't the best option.
966
+ extensionConfiguration . binaryPath = path . join (
967
+ os . homedir ( ) ,
968
+ extensionConfiguration . binaryPath . slice ( 1 )
969
+ ) ;
970
+ }
936
971
}
937
972
938
973
send ( response ) ;
@@ -1041,7 +1076,10 @@ function onMessage(msg: p.Message) {
1041
1076
// TODO: close watcher when lang-server shuts down. However, by Node's
1042
1077
// default, these subprocesses are automatically killed when this
1043
1078
// language-server process exits
1044
- let found = utils . findNodeBuildOfProjectRoot ( projectRootPath ) ;
1079
+ let found = utils . findNodeBuildOfProjectRoot (
1080
+ projectRootPath ,
1081
+ extensionConfiguration . binaryPath
1082
+ ) ;
1045
1083
if ( found != null ) {
1046
1084
let bsbProcess = utils . runBuildWatcherUsingValidBuildPath (
1047
1085
found . buildPath ,
0 commit comments