@@ -161,6 +161,11 @@ func (s *Server) initialized(ctx context.Context, params *protocol.InitializedPa
161
161
s .state = serverInitialized
162
162
s .stateMu .Unlock ()
163
163
164
+ for _ , not := range s .notifications {
165
+ s .client .ShowMessage (ctx , not )
166
+ }
167
+ s .notifications = nil
168
+
164
169
options := s .session .Options ()
165
170
defer func () { s .session .SetOptions (options ) }()
166
171
@@ -421,30 +426,42 @@ func (s *Server) fetchConfig(ctx context.Context, name string, folder span.URI,
421
426
return nil
422
427
}
423
428
429
+ func (s * Server ) eventuallyShowMessage (ctx context.Context , msg * protocol.ShowMessageParams ) error {
430
+ s .stateMu .Lock ()
431
+ defer s .stateMu .Unlock ()
432
+ if s .state == serverInitialized {
433
+ return s .client .ShowMessage (ctx , msg )
434
+ }
435
+ s .notifications = append (s .notifications , msg )
436
+ return nil
437
+ }
438
+
424
439
func (s * Server ) handleOptionResults (ctx context.Context , results source.OptionResults ) error {
425
440
for _ , result := range results {
426
441
if result .Error != nil {
427
- if err := s . client . ShowMessage ( ctx , & protocol.ShowMessageParams {
442
+ msg := & protocol.ShowMessageParams {
428
443
Type : protocol .Error ,
429
444
Message : result .Error .Error (),
430
- }); err != nil {
445
+ }
446
+ if err := s .eventuallyShowMessage (ctx , msg ); err != nil {
431
447
return err
432
448
}
433
449
}
434
450
switch result .State {
435
451
case source .OptionUnexpected :
436
- if err := s . client . ShowMessage ( ctx , & protocol.ShowMessageParams {
452
+ msg := & protocol.ShowMessageParams {
437
453
Type : protocol .Error ,
438
454
Message : fmt .Sprintf ("unexpected gopls setting %q" , result .Name ),
439
- }); err != nil {
455
+ }
456
+ if err := s .eventuallyShowMessage (ctx , msg ); err != nil {
440
457
return err
441
458
}
442
459
case source .OptionDeprecated :
443
460
msg := fmt .Sprintf ("gopls setting %q is deprecated" , result .Name )
444
461
if result .Replacement != "" {
445
462
msg = fmt .Sprintf ("%s, use %q instead" , msg , result .Replacement )
446
463
}
447
- if err := s .client . ShowMessage (ctx , & protocol.ShowMessageParams {
464
+ if err := s .eventuallyShowMessage (ctx , & protocol.ShowMessageParams {
448
465
Type : protocol .Warning ,
449
466
Message : msg ,
450
467
}); err != nil {
0 commit comments