Skip to content

Commit 61388d6

Browse files
committed
Fix recover
1 parent ad49351 commit 61388d6

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

internal/ls/crossproject.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type CrossProjectOrchestrator interface {
3838
GetLanguageServiceForProjectWithFile(ctx context.Context, project Project, uri lsproto.DocumentUri) *LanguageService
3939
GetProjectsForFile(ctx context.Context, uri lsproto.DocumentUri) ([]Project, error)
4040
GetProjectsLoadingProjectTree(ctx context.Context, requestedProjectTrees *collections.Set[tspath.Path]) iter.Seq[Project]
41-
Recover()
41+
RecoverWith(r any)
4242
}
4343

4444
func handleCrossProject[Req lsproto.HasTextDocumentPosition, Resp any](
@@ -81,7 +81,11 @@ func handleCrossProject[Req lsproto.HasTextDocumentPosition, Resp any](
8181
if ctx.Err() != nil {
8282
return
8383
}
84-
defer orchestrator.Recover()
84+
defer func() {
85+
if r := recover(); r != nil {
86+
orchestrator.RecoverWith(r)
87+
}
88+
}()
8589
// Process the item
8690
ls := item.ls
8791
if ls == nil {

internal/lsp/server.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -695,19 +695,23 @@ func (c *crossProjectOrchestrator) GetProjectsLoadingProjectTree(ctx context.Con
695695
}
696696
}
697697

698-
func (c *crossProjectOrchestrator) Recover() {
699-
c.server.recover(c.req)
698+
func (c *crossProjectOrchestrator) RecoverWith(r any) {
699+
c.server.recoverWith(c.req, r)
700+
}
701+
702+
func (s *Server) recoverWith(req *lsproto.RequestMessage, r any) {
703+
stack := debug.Stack()
704+
s.Log("panic handling request", req.Method, r, string(stack))
705+
if req.ID != nil {
706+
s.sendError(req.ID, fmt.Errorf("%w: panic handling request %s: %v", lsproto.ErrorCodeInternalError, req.Method, r))
707+
} else {
708+
s.Log("unhandled panic in notification", req.Method, r)
709+
}
700710
}
701711

702712
func (s *Server) recover(req *lsproto.RequestMessage) {
703713
if r := recover(); r != nil {
704-
stack := debug.Stack()
705-
s.Log("panic handling request", req.Method, r, string(stack))
706-
if req.ID != nil {
707-
s.sendError(req.ID, fmt.Errorf("%w: panic handling request %s: %v", lsproto.ErrorCodeInternalError, req.Method, r))
708-
} else {
709-
s.Log("unhandled panic in notification", req.Method, r)
710-
}
714+
s.recoverWith(req, r)
711715
}
712716
}
713717

0 commit comments

Comments
 (0)