@@ -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 ,
@@ -23,9 +24,11 @@ import { WorkspaceEdit } from "vscode-languageserver";
23
24
24
25
interface extensionConfiguration {
25
26
askToStartBuild : boolean ;
27
+ binaryPath : string ;
26
28
}
27
29
let extensionConfiguration : extensionConfiguration = {
28
30
askToStartBuild : true ,
31
+ binaryPath : "" ,
29
32
} ;
30
33
let pullConfigurationPeriodically : NodeJS . Timeout | null = null ;
31
34
@@ -209,7 +212,12 @@ let openedFile = (fileUri: string, fileContent: string) => {
209
212
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
210
213
// stale. Use that logic
211
214
// TODO: close watcher when lang-server shuts down
212
- if ( utils . findNodeBuildOfProjectRoot ( projectRootPath ) != null ) {
215
+ if (
216
+ utils . findNodeBuildOfProjectRoot (
217
+ projectRootPath ,
218
+ extensionConfiguration . binaryPath
219
+ ) != null
220
+ ) {
213
221
let payload : clientSentBuildAction = {
214
222
title : c . startBuildAction ,
215
223
projectRootPath : projectRootPath ,
@@ -231,7 +239,19 @@ let openedFile = (fileUri: string, fileContent: string) => {
231
239
// handle in the isResponseMessage check in the message handling way
232
240
// below
233
241
} else {
234
- // we should send something to say that we can't find bsb.exe. But right now we'll silently not do anything
242
+ let binaryPath = extensionConfiguration . binaryPath === ""
243
+ ? path . join ( projectRootPath , "node_modules" , ".bin" )
244
+ : extensionConfiguration . binaryPath ;
245
+
246
+ let request : p . NotificationMessage = {
247
+ jsonrpc : c . jsonrpcVersion ,
248
+ method : "window/showMessage" ,
249
+ params : {
250
+ type : p . MessageType . Error ,
251
+ message : `Can't find ReScript binary on path ${ binaryPath } ` ,
252
+ } ,
253
+ } ;
254
+ send ( request ) ;
235
255
}
236
256
}
237
257
@@ -570,7 +590,11 @@ function format(msg: p.RequestMessage): Array<p.Message> {
570
590
} else {
571
591
// code will always be defined here, even though technically it can be undefined
572
592
let code = getOpenedFileContent ( params . textDocument . uri ) ;
573
- let formattedResult = utils . formatCode ( filePath , code ) ;
593
+ let formattedResult = utils . formatCode (
594
+ extensionConfiguration . binaryPath ,
595
+ filePath ,
596
+ code
597
+ ) ;
574
598
if ( formattedResult . kind === "success" ) {
575
599
let max = code . length ;
576
600
let result : p . TextEdit [ ] = [
@@ -905,6 +929,17 @@ function onMessage(msg: p.Message) {
905
929
906
930
if ( initialConfiguration != null ) {
907
931
extensionConfiguration = initialConfiguration ;
932
+ if (
933
+ extensionConfiguration . binaryPath !== "" &&
934
+ extensionConfiguration . binaryPath [ 0 ] === "~"
935
+ ) {
936
+ // What should happen if the path contains the home directory symbol?
937
+ // This situation is handled below, but maybe it isn't the best option.
938
+ extensionConfiguration . binaryPath = path . join (
939
+ os . homedir ( ) ,
940
+ extensionConfiguration . binaryPath . slice ( 1 )
941
+ ) ;
942
+ }
908
943
}
909
944
910
945
send ( response ) ;
@@ -1013,7 +1048,10 @@ function onMessage(msg: p.Message) {
1013
1048
// TODO: close watcher when lang-server shuts down. However, by Node's
1014
1049
// default, these subprocesses are automatically killed when this
1015
1050
// language-server process exits
1016
- let found = utils . findNodeBuildOfProjectRoot ( projectRootPath ) ;
1051
+ let found = utils . findNodeBuildOfProjectRoot (
1052
+ projectRootPath ,
1053
+ extensionConfiguration . binaryPath
1054
+ ) ;
1017
1055
if ( found != null ) {
1018
1056
let bsbProcess = utils . runBuildWatcherUsingValidBuildPath (
1019
1057
found . buildPath ,
0 commit comments