Conversation
011421e to
c711129
Compare
There was a problem hiding this comment.
Pull request overview
Adds CodeLens-based reference counts for Python symbols in the Pyrefly LSP when indexing is enabled, backed by the existing global references engine, and introduces an LSP interaction test to validate the behavior.
Changes:
- Advertise
textDocument/codeLenscapability when indexing is enabled and handleCodeLensRequeston the server. - Generate CodeLens entries for class/function/method definitions with
editor.action.showReferenceswired up. - Add LSP interaction tests and test fixtures validating CodeLens reference counts.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pyrefly/lib/lsp/non_wasm/server.rs | Advertises CodeLens capability and implements textDocument/codeLens request handling to return reference-count lenses. |
| pyrefly/lib/lsp/non_wasm/workspace.rs | Adds code_lens flag to disabled-language-services gating for textDocument/codeLens. |
| pyrefly/lib/test/lsp/lsp_interaction/object_model.rs | Adds a test client helper to send CodeLensRequest. |
| pyrefly/lib/test/lsp/lsp_interaction/mod.rs | Registers new code_lens LSP interaction test module. |
| pyrefly/lib/test/lsp/lsp_interaction/code_lens.rs | Adds tests verifying capability advertisement and reference-count CodeLens results. |
| pyrefly/lib/test/lsp/lsp_interaction/test_files/code_lens_references/{symbols.py,usage.py} | Adds small fixtures used by the new CodeLens tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.find_reference_queue.queue_task( | ||
| TelemetryEventKind::FindFromDefinition, | ||
| Box::new(move |server, _telemetry, telemetry_event| { | ||
| telemetry_event.set_activity_key(activity_key); |
There was a problem hiding this comment.
find_reference_queue.queue_task expects a closure with signature FnOnce(&Server, &dyn Telemetry, &mut TelemetryEvent), but this new task closure takes 5 parameters (|server, _telemetry, telemetry_event, _, _|). This will not compile; update the closure to accept only the three expected arguments (and adjust captures accordingly).
| for (info, ranges) in local_results { | ||
| if let Some(uri) = module_info_to_uri(&info, path_remapper.as_ref()) { | ||
| for range in ranges { | ||
| locations.push(Location { | ||
| uri: uri.clone(), | ||
| range: info.to_lsp_range(range), | ||
| }); | ||
| } |
There was a problem hiding this comment.
When building locations for the editor.action.showReferences command, notebook cell references aren’t remapped to cell URIs (unlike the existing references implementation, which maps file URIs to notebook cell URIs via snapshot_open_notebooks / to_cell_for_lsp). This will cause CodeLens “show references” to point at the notebook file path instead of the correct cell, or fail to navigate in notebook scenarios. Consider reusing the same notebook remapping logic used in async_find_references_helper when translating ModuleInfo + TextRange into LSP Locations.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Summary
Fixes #2194
The server now advertises
textDocument/codeLenswhen indexing is enabled and returns CodeLens entries for class/function/method definitions using the existing global references engine.Each lens shows N reference(s) and wires to VS Code’s built-in
editor.action.showReferences, so clicking the count opens the references UI.Test Plan
add LSP interaction test