@@ -358,8 +358,15 @@ func (s *Server) dispatchLoop(ctx context.Context) error {
358
358
if r := recover (); r != nil {
359
359
stack := debug .Stack ()
360
360
s .Log ("panic handling request" , req .Method , r , string (stack ))
361
- // !!! send something back to client
362
- lspExit ()
361
+ if isBlockingMethod (req .Method ) {
362
+ lspExit ()
363
+ } else {
364
+ if req .ID != nil {
365
+ s .sendError (req .ID , fmt .Errorf ("%w: panic handling request %s: %v" , lsproto .ErrInternalError , req .Method , r ))
366
+ } else {
367
+ s .Log ("unhandled panic in notification" , req .Method , r )
368
+ }
369
+ }
363
370
}
364
371
}()
365
372
if err := s .handleRequestOrNotification (requestCtx , req ); err != nil {
@@ -684,15 +691,6 @@ func (s *Server) handleReferences(ctx context.Context, req *lsproto.RequestMessa
684
691
project := s .projectService .EnsureDefaultProjectForURI (params .TextDocument .Uri )
685
692
languageService , done := project .GetLanguageServiceForRequest (ctx )
686
693
defer done ()
687
- // !!! remove this after find all references is fully ported/tested
688
- defer func () {
689
- if r := recover (); r != nil {
690
- stack := debug .Stack ()
691
- s .Log ("panic obtaining references:" , r , string (stack ))
692
- s .sendResult (req .ID , []* lsproto.Location {})
693
- }
694
- }()
695
-
696
694
locations := languageService .ProvideReferences (params )
697
695
s .sendResult (req .ID , locations )
698
696
return nil
@@ -703,14 +701,6 @@ func (s *Server) handleCompletion(ctx context.Context, req *lsproto.RequestMessa
703
701
project := s .projectService .EnsureDefaultProjectForURI (params .TextDocument .Uri )
704
702
languageService , done := project .GetLanguageServiceForRequest (ctx )
705
703
defer done ()
706
- // !!! remove this after completions is fully ported/tested
707
- defer func () {
708
- if r := recover (); r != nil {
709
- stack := debug .Stack ()
710
- s .Log ("panic obtaining completions:" , r , string (stack ))
711
- s .sendResult (req .ID , & lsproto.CompletionList {})
712
- }
713
- }()
714
704
// !!! get user preferences
715
705
list , err := languageService .ProvideCompletion (
716
706
ctx ,
@@ -731,15 +721,6 @@ func (s *Server) handleDocumentFormat(ctx context.Context, req *lsproto.RequestM
731
721
project := s .projectService .EnsureDefaultProjectForURI (params .TextDocument .Uri )
732
722
languageService , done := project .GetLanguageServiceForRequest (ctx )
733
723
defer done ()
734
- // !!! remove this after formatting is fully ported/tested
735
- defer func () {
736
- if r := recover (); r != nil {
737
- stack := debug .Stack ()
738
- s .Log ("panic on document format:" , r , string (stack ))
739
- s .sendResult (req .ID , []* lsproto.TextEdit {})
740
- }
741
- }()
742
-
743
724
res , err := languageService .ProvideFormatDocument (
744
725
ctx ,
745
726
params .TextDocument .Uri ,
@@ -757,15 +738,6 @@ func (s *Server) handleDocumentRangeFormat(ctx context.Context, req *lsproto.Req
757
738
project := s .projectService .EnsureDefaultProjectForURI (params .TextDocument .Uri )
758
739
languageService , done := project .GetLanguageServiceForRequest (ctx )
759
740
defer done ()
760
- // !!! remove this after formatting is fully ported/tested
761
- defer func () {
762
- if r := recover (); r != nil {
763
- stack := debug .Stack ()
764
- s .Log ("panic on document range format:" , r , string (stack ))
765
- s .sendResult (req .ID , []* lsproto.TextEdit {})
766
- }
767
- }()
768
-
769
741
res , err := languageService .ProvideFormatDocumentRange (
770
742
ctx ,
771
743
params .TextDocument .Uri ,
@@ -784,15 +756,6 @@ func (s *Server) handleDocumentOnTypeFormat(ctx context.Context, req *lsproto.Re
784
756
project := s .projectService .EnsureDefaultProjectForURI (params .TextDocument .Uri )
785
757
languageService , done := project .GetLanguageServiceForRequest (ctx )
786
758
defer done ()
787
- // !!! remove this after formatting is fully ported/tested
788
- defer func () {
789
- if r := recover (); r != nil {
790
- stack := debug .Stack ()
791
- s .Log ("panic on type format:" , r , string (stack ))
792
- s .sendResult (req .ID , []* lsproto.TextEdit {})
793
- }
794
- }()
795
-
796
759
res , err := languageService .ProvideFormatDocumentOnType (
797
760
ctx ,
798
761
params .TextDocument .Uri ,
0 commit comments