@@ -10,6 +10,7 @@ import {
10
10
DidOpenTextDocumentNotification ,
11
11
DidChangeTextDocumentNotification ,
12
12
DidCloseTextDocumentNotification ,
13
+ DidChangeConfigurationNotification ,
13
14
} from "vscode-languageserver-protocol" ;
14
15
import * as utils from "./utils" ;
15
16
import * as codeActions from "./codeActions" ;
@@ -20,6 +21,14 @@ import { fileURLToPath } from "url";
20
21
import { ChildProcess } from "child_process" ;
21
22
import { WorkspaceEdit } from "vscode-languageserver" ;
22
23
24
+ interface extensionConfiguration {
25
+ askToStartBuild : boolean ;
26
+ }
27
+ let extensionConfiguration : extensionConfiguration = {
28
+ askToStartBuild : true ,
29
+ } ;
30
+ let pullConfigurationInterval : NodeJS . Timeout | null = null ;
31
+
23
32
// https://microsoft.github.io/language-server-protocol/specification#initialize
24
33
// According to the spec, there could be requests before the 'initialize' request. Link in comment tells how to handle them.
25
34
let initialized = false ;
@@ -183,7 +192,11 @@ let openedFile = (fileUri: string, fileContent: string) => {
183
192
// check if .bsb.lock is still there. If not, start a bsb -w ourselves
184
193
// because otherwise the diagnostics info we'll display might be stale
185
194
let bsbLockPath = path . join ( projectRootPath , c . bsbLock ) ;
186
- if ( firstOpenFileOfProject && ! fs . existsSync ( bsbLockPath ) ) {
195
+ if (
196
+ extensionConfiguration . askToStartBuild === true &&
197
+ firstOpenFileOfProject &&
198
+ ! fs . existsSync ( bsbLockPath )
199
+ ) {
187
200
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
188
201
// stale. Use that logic
189
202
// TODO: close watcher when lang-server shuts down
@@ -268,6 +281,8 @@ if (process.argv.includes("--stdio")) {
268
281
process . on ( "message" , onMessage ) ;
269
282
}
270
283
284
+ askForAllCurrentConfiguration ( ) ;
285
+
271
286
function hover ( msg : p . RequestMessage ) {
272
287
let params = msg . params as p . HoverParams ;
273
288
let filePath = fileURLToPath ( params . textDocument . uri ) ;
@@ -412,6 +427,24 @@ function documentSymbol(msg: p.RequestMessage) {
412
427
return response ;
413
428
}
414
429
430
+ function askForAllCurrentConfiguration ( ) {
431
+ // https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration
432
+ let params : p . ConfigurationParams = {
433
+ items : [
434
+ {
435
+ section : "rescript.settings" ,
436
+ } ,
437
+ ] ,
438
+ } ;
439
+ let req : p . RequestMessage = {
440
+ jsonrpc : c . jsonrpcVersion ,
441
+ id : c . configurationRequestId ,
442
+ method : p . ConfigurationRequest . type . method ,
443
+ params,
444
+ } ;
445
+ send ( req ) ;
446
+ }
447
+
415
448
function semanticTokens ( msg : p . RequestMessage ) {
416
449
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_semanticTokens
417
450
let params = msg . params as p . SemanticTokensParams ;
@@ -434,7 +467,6 @@ function completion(msg: p.RequestMessage) {
434
467
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
435
468
let params = msg . params as p . ReferenceParams ;
436
469
let filePath = fileURLToPath ( params . textDocument . uri ) ;
437
- let extension = path . extname ( params . textDocument . uri ) ;
438
470
let code = getOpenedFileContent ( params . textDocument . uri ) ;
439
471
let tmpname = utils . createFileInTempDir ( ) ;
440
472
fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
@@ -743,7 +775,6 @@ function onMessage(msg: m.Message) {
743
775
}
744
776
} else if ( msg . method === DidOpenTextDocumentNotification . method ) {
745
777
let params = msg . params as p . DidOpenTextDocumentParams ;
746
- let extName = path . extname ( params . textDocument . uri ) ;
747
778
openedFile ( params . textDocument . uri , params . textDocument . text ) ;
748
779
} else if ( msg . method === DidChangeTextDocumentNotification . method ) {
749
780
let params = msg . params as p . DidChangeTextDocumentParams ;
@@ -763,6 +794,9 @@ function onMessage(msg: m.Message) {
763
794
} else if ( msg . method === DidCloseTextDocumentNotification . method ) {
764
795
let params = msg . params as p . DidCloseTextDocumentParams ;
765
796
closedFile ( params . textDocument . uri ) ;
797
+ } else if ( msg . method === DidChangeConfigurationNotification . type . method ) {
798
+ // Can't seem to get this notification to trigger, but if it does this will be here and ensure we're synced up at the server.
799
+ askForAllCurrentConfiguration ( ) ;
766
800
}
767
801
} else if ( m . isRequestMessage ( msg ) ) {
768
802
// request message, aka client sent request and waits for our mandatory reply
@@ -820,6 +854,15 @@ function onMessage(msg: m.Message) {
820
854
result : result ,
821
855
} ;
822
856
initialized = true ;
857
+
858
+ // Periodically pull configuration from the client.
859
+ pullConfigurationInterval = setInterval ( ( ) => {
860
+ askForAllCurrentConfiguration ( ) ;
861
+ } , 10_000 ) ;
862
+
863
+ // Pull config right away as we've initied.
864
+ askForAllCurrentConfiguration ( ) ;
865
+
823
866
send ( response ) ;
824
867
} else if ( msg . method === "initialized" ) {
825
868
// sent from client after initialize. Nothing to do for now
@@ -847,6 +890,10 @@ function onMessage(msg: m.Message) {
847
890
stopWatchingCompilerLog ( ) ;
848
891
// TODO: delete bsb watchers
849
892
893
+ if ( pullConfigurationInterval != null ) {
894
+ clearInterval ( pullConfigurationInterval ) ;
895
+ }
896
+
850
897
let response : m . ResponseMessage = {
851
898
jsonrpc : c . jsonrpcVersion ,
852
899
id : msg . id ,
@@ -893,11 +940,19 @@ function onMessage(msg: m.Message) {
893
940
send ( response ) ;
894
941
}
895
942
} else if ( m . isResponseMessage ( msg ) ) {
896
- // response message. Currently the client should have only sent a response
897
- // for asking us to start the build (see window/showMessageRequest in this
898
- // file)
899
-
900
- if (
943
+ if ( msg . id === c . configurationRequestId ) {
944
+ if ( msg . result != null ) {
945
+ // This is a response from a request to get updated configuration. Note
946
+ // that it seems to return the configuration in a way that lets the
947
+ // current workspace settings override the user settings. This is good
948
+ // as we get started, but _might_ be problematic further down the line
949
+ // if we want to support having several projects open at the same time
950
+ // without their settings overriding eachother. Not a problem now though
951
+ // as we'll likely only have "global" settings starting out.
952
+ let [ configuration ] = msg . result as [ extensionConfiguration ] ;
953
+ extensionConfiguration = configuration ;
954
+ }
955
+ } else if (
901
956
msg . result != null &&
902
957
// @ts -ignore
903
958
msg . result . title != null &&
0 commit comments