on main help sign in
bugfix: find references, double timeout
02ec5dbTai Groot
internal/agent/tools/diagnostics.go+1−4
@@ -73,16 +73,13 @@ func waitForLSPDiagnostics(
73 return
73 return
74 }
74 }
75
75
76− waitCtx, cancel := context.WithTimeout(ctx, timeout)
77− defer cancel()
78−
79 var wg sync.WaitGroup
76 var wg sync.WaitGroup
80 for client := range manager.Clients().Seq() {
77 for client := range manager.Clients().Seq() {
81 if !client.HandlesFile(filepath) {
78 if !client.HandlesFile(filepath) {
82 continue
79 continue
83 }
80 }
84 wg.Go(func() {
81 wg.Go(func() {
85− client.WaitForDiagnostics(waitCtx, timeout)
82+ client.WaitForDiagnostics(ctx, timeout)
86 })
83 })
87 }
84 }
88 wg.Wait()
85 wg.Wait()
internal/agent/tools/references.go+5−1
@@ -71,7 +71,11 @@ func NewReferencesTool(lspManager *lsp.Manager) fantasy.AgentTool {
71 continue
71 continue
72 }
72 }
73 allLocations = append(allLocations, locations...)
73 allLocations = append(allLocations, locations...)
74− // XXX: should we break here or look for all results?
74+ // Once we have results, we're done - LSP returns all references
75+ // for the symbol, not just from this file.
76+ if len(locations) > 0 {
77+ break
78+ }
75 }
79 }
76
80
77 if len(allLocations) > 0 {
81 if len(allLocations) > 0 {
internal/lsp/client.go+5
@@ -533,6 +533,11 @@ func (c *Client) FindReferences(ctx context.Context, filepath string, line, char
533 if err := c.OpenFileOnDemand(ctx, filepath); err != nil {
533 if err := c.OpenFileOnDemand(ctx, filepath); err != nil {
534 return nil, err
534 return nil, err
535 }
535 }
536+
537+ // Add timeout to prevent hanging on slow LSP servers.
538+ ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
539+ defer cancel()
540+
536 // NOTE: line and character should be 0-based.
541 // NOTE: line and character should be 0-based.
537 // See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
542 // See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
538 return c.client.FindReferences(ctx, filepath, line-1, character-1, includeDeclaration)
543 return c.client.FindReferences(ctx, filepath, line-1, character-1, includeDeclaration)