on main help sign in
bugfix: find references, double timeout
commit02ec5db4742886c1e81339c6fc18fa234a49c7c8 authorTai Groot <tai@taigrr.com> dateThu 26 Feb 2026, 15:40 (8 months ago) parentd3682ac
3 files changed+11−5
internal/agent/tools/diagnostics.go+1−4 internal/agent/tools/references.go+5−1 internal/lsp/client.go+5
internal/agent/tools/diagnostics.go+1−4
@@ -73,16 +73,13 @@ func waitForLSPDiagnostics(
7373 return
7474 }
7575
76− waitCtx, cancel := context.WithTimeout(ctx, timeout)
77− defer cancel()
78−
7976 var wg sync.WaitGroup
8077 for client := range manager.Clients().Seq() {
8178 if !client.HandlesFile(filepath) {
8279 continue
8380 }
8481 wg.Go(func() {
85− client.WaitForDiagnostics(waitCtx, timeout)
82+ client.WaitForDiagnostics(ctx, timeout)
8683 })
8784 }
8885 wg.Wait()
internal/agent/tools/references.go+5−1
@@ -71,7 +71,11 @@ func NewReferencesTool(lspManager *lsp.Manager) fantasy.AgentTool {
7171 continue
7272 }
7373 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+ }
7579 }
7680
7781 if len(allLocations) > 0 {
internal/lsp/client.go+5
@@ -533,6 +533,11 @@ func (c *Client) FindReferences(ctx context.Context, filepath string, line, char
533533 if err := c.OpenFileOnDemand(ctx, filepath); err != nil {
534534 return nil, err
535535 }
536+
537+ // Add timeout to prevent hanging on slow LSP servers.
538+ ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
539+ defer cancel()
540+
536541 // NOTE: line and character should be 0-based.
537542 // See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
538543 return c.client.FindReferences(ctx, filepath, line-1, character-1, includeDeclaration)