@@ -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
@@ -62,6 +65,11 @@ let codeActionsFromDiagnostics: codeActions.filesCodeActions = {};
62
65
// will be properly defined later depending on the mode (stdio/node-rpc)
63
66
let send : ( msg : p . Message ) => void = ( _ ) => { } ;
64
67
68
+ let findBinary = ( projectRootPath : p . DocumentUri ) =>
69
+ extensionConfiguration . binaryPath === null
70
+ ? utils . findNodeBuildOfProjectRoot ( projectRootPath )
71
+ : utils . findBinaryFromConfig ( extensionConfiguration . binaryPath ) ;
72
+
65
73
interface CreateInterfaceRequestParams {
66
74
uri : string ;
67
75
}
@@ -232,7 +240,7 @@ let openedFile = (fileUri: string, fileContent: string) => {
232
240
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
233
241
// stale. Use that logic
234
242
// TODO: close watcher when lang-server shuts down
235
- if ( utils . findNodeBuildOfProjectRoot ( projectRootPath ) != null ) {
243
+ if ( findBinary ( projectRootPath ) != null ) {
236
244
let payload : clientSentBuildAction = {
237
245
title : c . startBuildAction ,
238
246
projectRootPath : projectRootPath ,
@@ -254,7 +262,20 @@ 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 =
266
+ extensionConfiguration . binaryPath === null
267
+ ? path . join ( projectRootPath , "node_modules" , ".bin" )
268
+ : extensionConfiguration . binaryPath ;
269
+
270
+ let request : p . NotificationMessage = {
271
+ jsonrpc : c . jsonrpcVersion ,
272
+ method : "window/showMessage" ,
273
+ params : {
274
+ type : p . MessageType . Error ,
275
+ message : `Can't find ReScript binary on path ${ binaryPath } ` ,
276
+ } ,
277
+ } ;
278
+ send ( request ) ;
258
279
}
259
280
}
260
281
@@ -593,7 +614,11 @@ function format(msg: p.RequestMessage): Array<p.Message> {
593
614
} else {
594
615
// code will always be defined here, even though technically it can be undefined
595
616
let code = getOpenedFileContent ( params . textDocument . uri ) ;
596
- let formattedResult = utils . formatCode ( filePath , code ) ;
617
+ let formattedResult = utils . formatCode (
618
+ extensionConfiguration . binaryPath ,
619
+ filePath ,
620
+ code
621
+ ) ;
597
622
if ( formattedResult . kind === "success" ) {
598
623
let max = code . length ;
599
624
let result : p . TextEdit [ ] = [
@@ -933,6 +958,17 @@ function onMessage(msg: p.Message) {
933
958
934
959
if ( initialConfiguration != null ) {
935
960
extensionConfiguration = initialConfiguration ;
961
+ if (
962
+ extensionConfiguration . binaryPath !== null &&
963
+ extensionConfiguration . binaryPath [ 0 ] === "~"
964
+ ) {
965
+ // What should happen if the path contains the home directory symbol?
966
+ // This situation is handled below, but maybe it isn't the best option.
967
+ extensionConfiguration . binaryPath = path . join (
968
+ os . homedir ( ) ,
969
+ extensionConfiguration . binaryPath . slice ( 1 )
970
+ ) ;
971
+ }
936
972
}
937
973
938
974
send ( response ) ;
@@ -1041,7 +1077,7 @@ function onMessage(msg: p.Message) {
1041
1077
// TODO: close watcher when lang-server shuts down. However, by Node's
1042
1078
// default, these subprocesses are automatically killed when this
1043
1079
// language-server process exits
1044
- let found = utils . findNodeBuildOfProjectRoot ( projectRootPath ) ;
1080
+ let found = findBinary ( projectRootPath ) ;
1045
1081
if ( found != null ) {
1046
1082
let bsbProcess = utils . runBuildWatcherUsingValidBuildPath (
1047
1083
found . buildPath ,
0 commit comments