@@ -217,6 +217,101 @@ func (s *Server) RefreshDiagnostics(ctx context.Context) error {
217
217
return nil
218
218
}
219
219
220
+ func (s * Server ) Configure (ctx context.Context ) (* ls.UserPreferences , error ) {
221
+ result , err := s .sendRequest (ctx , lsproto .MethodWorkspaceConfiguration , & lsproto.ConfigurationParams {
222
+ Items : []* lsproto.ConfigurationItem {
223
+ {
224
+ Section : ptrTo ("typescript" ),
225
+ },
226
+ },
227
+ })
228
+ if err != nil {
229
+ return nil , fmt .Errorf ("configure request failed: %w" , err )
230
+ }
231
+ configs := result .([]any )
232
+ userPreferences := & ls.UserPreferences {}
233
+ for _ , config := range configs {
234
+ if config == nil {
235
+ continue
236
+ }
237
+ if item , ok := config .(map [string ]any ); ok {
238
+ for name , values := range item {
239
+ switch name {
240
+ case "inlayHints" :
241
+ inlayHintsPreferences := values .(map [string ]any )
242
+ if v , ok := inlayHintsPreferences ["parameterNames" ].(map [string ]any ); ok && v != nil {
243
+ if enabled , ok := v ["enabled" ]; ok {
244
+ if enabledStr , ok := enabled .(string ); ok {
245
+ userPreferences .IncludeInlayParameterNameHints = enabledStr
246
+ } else {
247
+ userPreferences .IncludeInlayParameterNameHints = ""
248
+ }
249
+ }
250
+ if supressWhenArgumentMatchesName , ok := v ["suppressWhenArgumentMatchesName" ]; ok {
251
+ userPreferences .IncludeInlayParameterNameHintsWhenArgumentMatchesName = ptrTo (! supressWhenArgumentMatchesName .(bool ))
252
+ }
253
+ }
254
+ if v , ok := inlayHintsPreferences ["parameterTypes" ].(map [string ]any ); ok && v != nil {
255
+ if enabled , ok := v ["enabled" ]; ok {
256
+ userPreferences .IncludeInlayFunctionParameterTypeHints = ptrTo (enabled .(bool ))
257
+ }
258
+ }
259
+ if v , ok := inlayHintsPreferences ["variableTypes" ].(map [string ]any ); ok && v != nil {
260
+ if enabled , ok := v ["enabled" ]; ok {
261
+ userPreferences .IncludeInlayVariableTypeHints = ptrTo (enabled .(bool ))
262
+ }
263
+ if supressWhenTypeMatchesName , ok := v ["suppressWhenTypeMatchesName" ]; ok {
264
+ userPreferences .IncludeInlayVariableTypeHintsWhenTypeMatchesName = ptrTo (! supressWhenTypeMatchesName .(bool ))
265
+ }
266
+ }
267
+ if v , ok := inlayHintsPreferences ["propertyDeclarationTypes" ].(map [string ]any ); ok && v != nil {
268
+ if enabled , ok := v ["enabled" ]; ok {
269
+ userPreferences .IncludeInlayPropertyDeclarationTypeHints = ptrTo (enabled .(bool ))
270
+ }
271
+ }
272
+ if v , ok := inlayHintsPreferences ["functionLikeReturnTypes" ].(map [string ]any ); ok && v != nil {
273
+ if enabled , ok := v ["enabled" ]; ok {
274
+ userPreferences .IncludeInlayFunctionLikeReturnTypeHints = ptrTo (enabled .(bool ))
275
+ }
276
+ }
277
+ if v , ok := inlayHintsPreferences ["enumMemberValues" ].(map [string ]any ); ok && v != nil {
278
+ if enabled , ok := v ["enabled" ]; ok {
279
+ userPreferences .IncludeInlayEnumMemberValueHints = ptrTo (enabled .(bool ))
280
+ }
281
+ }
282
+ userPreferences .InteractiveInlayHints = ptrTo (true )
283
+ case "tsserver" :
284
+ // !!!
285
+ case "unstable" :
286
+ // !!!
287
+ case "tsc" :
288
+ // !!!
289
+ case "updateImportsOnFileMove" :
290
+ // !!! moveToFile
291
+ case "preferences" :
292
+ // !!!
293
+ case "experimental" :
294
+ // !!!
295
+ case "organizeImports" :
296
+ // !!!
297
+ case "importModuleSpecifierEnding" :
298
+ // !!!
299
+ }
300
+ }
301
+ continue
302
+ }
303
+ if item , ok := config .(ls.UserPreferences ); ok {
304
+ // case for fourslash
305
+ userPreferences = & item
306
+ break
307
+ }
308
+ }
309
+ // !!! set defaults for services, remove after extension is updated
310
+ userPreferences .IncludeCompletionsForModuleExports = ptrTo (true )
311
+ userPreferences .IncludeCompletionsForImportStatements = ptrTo (true )
312
+ return userPreferences , nil
313
+ }
314
+
220
315
func (s * Server ) Run () error {
221
316
ctx , stop := signal .NotifyContext (context .Background (), os .Interrupt , syscall .SIGTERM )
222
317
defer stop ()
@@ -440,6 +535,7 @@ var handlers = sync.OnceValue(func() handlerMap {
440
535
registerRequestHandler (handlers , lsproto .ShutdownInfo , (* Server ).handleShutdown )
441
536
registerNotificationHandler (handlers , lsproto .ExitInfo , (* Server ).handleExit )
442
537
538
+ registerNotificationHandler (handlers , lsproto .WorkspaceDidChangeConfigurationInfo , (* Server ).handleDidChangeWorkspaceConfiguration )
443
539
registerNotificationHandler (handlers , lsproto .TextDocumentDidOpenInfo , (* Server ).handleDidOpen )
444
540
registerNotificationHandler (handlers , lsproto .TextDocumentDidChangeInfo , (* Server ).handleDidChange )
445
541
registerNotificationHandler (handlers , lsproto .TextDocumentDidSaveInfo , (* Server ).handleDidSave )
@@ -638,7 +734,6 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali
638
734
if shouldEnableWatch (s .initializeParams ) {
639
735
s .watchEnabled = true
640
736
}
641
-
642
737
s .session = project .NewSession (& project.SessionInit {
643
738
Options : & project.SessionOptions {
644
739
CurrentDirectory : s .cwd ,
@@ -655,6 +750,11 @@ func (s *Server) handleInitialized(ctx context.Context, params *lsproto.Initiali
655
750
NpmExecutor : s ,
656
751
ParseCache : s .parseCache ,
657
752
})
753
+ userPreferences , err := s .Configure (ctx )
754
+ if err != nil {
755
+ return err
756
+ }
757
+ s .session .Configure (userPreferences )
658
758
// !!! temporary; remove when we have `handleDidChangeConfiguration`/implicit project config support
659
759
if s .compilerOptionsForInferredProjects != nil {
660
760
s .session .DidChangeCompilerOptionsForInferredProjects (ctx , s .compilerOptionsForInferredProjects )
@@ -672,6 +772,16 @@ func (s *Server) handleExit(ctx context.Context, params any) error {
672
772
return io .EOF
673
773
}
674
774
775
+ func (s * Server ) handleDidChangeWorkspaceConfiguration (ctx context.Context , params * lsproto.DidChangeConfigurationParams ) error {
776
+ // !!! update user preferences
777
+ // !!! only usable by fourslash
778
+ if item , ok := params .Settings .(* ls.UserPreferences ); ok {
779
+ // case for fourslash
780
+ s .session .Configure (item )
781
+ }
782
+ return nil
783
+ }
784
+
675
785
func (s * Server ) handleDidOpen (ctx context.Context , params * lsproto.DidOpenTextDocumentParams ) error {
676
786
s .session .DidOpenFile (ctx , params .TextDocument .Uri , params .TextDocument .Version , params .TextDocument .Text , params .TextDocument .LanguageId )
677
787
return nil
@@ -757,10 +867,8 @@ func (s *Server) handleCompletion(ctx context.Context, languageService *ls.Langu
757
867
params .Position ,
758
868
params .Context ,
759
869
getCompletionClientCapabilities (s .initializeParams ),
760
- & ls.UserPreferences {
761
- IncludeCompletionsForModuleExports : ptrTo (true ),
762
- IncludeCompletionsForImportStatements : ptrTo (true ),
763
- })
870
+ languageService .UserPreferences (),
871
+ )
764
872
}
765
873
766
874
func (s * Server ) handleCompletionItemResolve (ctx context.Context , params * lsproto.CompletionItem , reqMsg * lsproto.RequestMessage ) (lsproto.CompletionResolveResponse , error ) {
@@ -778,10 +886,7 @@ func (s *Server) handleCompletionItemResolve(ctx context.Context, params *lsprot
778
886
params ,
779
887
data ,
780
888
getCompletionClientCapabilities (s .initializeParams ),
781
- & ls.UserPreferences {
782
- IncludeCompletionsForModuleExports : ptrTo (true ),
783
- IncludeCompletionsForImportStatements : ptrTo (true ),
784
- },
889
+ languageService .UserPreferences (),
785
890
)
786
891
}
787
892
@@ -812,6 +917,13 @@ func (s *Server) handleDocumentOnTypeFormat(ctx context.Context, ls *ls.Language
812
917
)
813
918
}
814
919
920
+ func (s * Server ) handleInlayHints (ctx context.Context , ls * ls.LanguageService , params * lsproto.InlayHintParams ) (lsproto.InlayHintResponse , error ) {
921
+ // !!!
922
+ // userPreferences, _ := s.Configure(ctx)
923
+ // return ls.ProvideInlayHints(ctx, params, userPreferences), nil
924
+ panic ("unimplemented" )
925
+ }
926
+
815
927
func (s * Server ) handleWorkspaceSymbol (ctx context.Context , params * lsproto.WorkspaceSymbolParams , reqMsg * lsproto.RequestMessage ) (lsproto.WorkspaceSymbolResponse , error ) {
816
928
snapshot , release := s .session .Snapshot ()
817
929
defer release ()
@@ -855,7 +967,9 @@ func isBlockingMethod(method lsproto.Method) bool {
855
967
lsproto .MethodTextDocumentDidChange ,
856
968
lsproto .MethodTextDocumentDidSave ,
857
969
lsproto .MethodTextDocumentDidClose ,
858
- lsproto .MethodWorkspaceDidChangeWatchedFiles :
970
+ lsproto .MethodWorkspaceDidChangeWatchedFiles ,
971
+ lsproto .MethodWorkspaceDidChangeConfiguration ,
972
+ lsproto .MethodWorkspaceConfiguration :
859
973
return true
860
974
}
861
975
return false
0 commit comments