feat(context): optional LSP-backed find-references under --deep (closes #255) - #288
Merged
Conversation
#255) trace-up under --deep + active LSP uses lsp_client.find_references as precision source (annotated trace_source=lsp); zero-config/graph path unchanged (trace_source=graph). Reuses HybridEngine find_references/_find_symbol_definition/_find_symbol_char + _filter_external_references; no new LSP infra. Adds HybridEngine.find_references_for_symbol + commands.trace._apply_lsp_trace_up + tests.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Approach
When
--deepis active and an LSP server is available,context --check trace --direction up(and--direction both) uses LSPtextDocument/referencesas the precision source for callers, annotatedtrace_source: "lsp". Otherwise (no--deep, no live LSP, or symbol unresolvable) the existing graph path is used unchanged, annotatedtrace_source: "graph". Zero-config keeps working with no regression and no LSP dependency.Reuses existing infra only (issue constraint):
lsp_client.find_references,hybrid_engine._find_symbol_definition/_find_symbol_char/_filter_external_references. No new LSP plumbing; LSP never becomes a hard dependency.Changes
scripts/hybrid_engine.py— newHybridEngine.find_references_for_symbol(): resolves symbol → def(file,line,char), callsfind_references(include_declaration=False), filters the def site, returns 1-indexed refs (orNonewhen LSP inactive / unresolved). Never raises.scripts/commands/trace.py—execute()applies the opt-in LSP overlay only whendeep+direction in (up, both);_apply_lsp_trace_up()rewriteschains.upto LSP entries +trace_source: lsp+graph/lsp_callers_found, else keeps graph. Alwayscleanup()s.trace_engine.pyuntouched — graph/flat backend + output shape unchanged; the overlay sits at the command boundary.docs/design/0255-lsp-find-references.md.Verification: live vs mock (explicit)
Live-verified (real CLI, this environment):
--deep→trace_source: graph, callers found — zero-config unaffected.--deep→lsp_available: true, but the live server returned no usable references for the symbol, so it degraded totrace_source: graph— no hang, no error, exit 0.--deep).Mock-verified only (NOT claimed live): the LSP happy path (
trace_source: lspwith real references). Mirrors #253 / PR #259 — rust-analyzer (only server installed) does not respond toinitializewithin 60s, so the happy path is covered by mockedcreate_hybrid_engine/find_references, not a live server.Test output
tests/test_issue255_lsp_references.py— 8 passed (2 live degradation, 6 mocked happy-path/resolution).No regression to the graph trace path (golden accuracy harness green). Pre-existing unrelated failures in
test_compact_format.py(search/path-stripping) exist onmainand are untouched by this diff (diff is scoped tohybrid_engine.py,commands/trace.py, the new test, and the design doc).🤖 Generated with Claude Code