[ty] Add call hierarchy support#25338
Conversation
|
Wow, nice! I agree, this is a feature that ty desperately needs and it's on our immediate roadmap. However, it may take us 1-2 weeks before I'll have a chance to review this, as there is one more fatal panic that I want to look into first. From skimming this code (and without having a concrete idea on how this should or is working in the PR), these are a few questions/comments that popped up:
|
|
@MichaReiser thanks for the initial feedback. No worries on the timeline, I am not in a rush. |
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134. |
Memory usage reportMemory usage unchanged ✅ |
|
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| ERA001 | 2 | 0 | 2 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+0 -2 violations, +0 -0 fixes in 1 projects; 55 projects unchanged)
zulip/zulip (+0 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --no-fix --output-format concise --preview --select ALL
- zproject/prod_settings_template.py:297:1: ERA001 Found commented-out code - zproject/prod_settings_template.py:298:1: ERA001 Found commented-out code
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| ERA001 | 2 | 0 | 2 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
ℹ️ ecosystem check encountered format errors. (no format changes; 1 project error)
openai/openai-cookbook (error)
ruff format --preview --exclude examples/mcp/databricks_mcp_cookbook.ipynb,examples/chatgpt/gpt_actions_library/gpt_action_google_drive.ipynb,examples/chatgpt/gpt_actions_library/gpt_action_redshift.ipynb,examples/chatgpt/gpt_actions_library/gpt_action_salesforce.ipynb,
warning: Detected debug build without --no-cache.
error: Encountered error: No such file or directory (os error 2)
|
|
||
| /// Helper for `callHierarchy/incomingCalls`. Iterates over all projects in the | ||
| /// session and merges results from whichever project owns the file. | ||
| pub(crate) fn incoming_calls_handler( |
There was a problem hiding this comment.
I'd move this into the incoming call request handler's file. Given that it's not used elsewhere
| /// Helper for `callHierarchy/outgoingCalls`. Same multi-project iteration as | ||
| /// the incoming variant, but `from_ranges` come from the *prepared* item's | ||
| /// file (the caller). | ||
| pub(crate) fn outgoing_calls_handler( |
| sites | ||
| } | ||
|
|
||
| struct CallSitesFinder<'a, 'db> { |
There was a problem hiding this comment.
Can you say more why this is an entirely new visitor. Could we use LocalReferencesFinder instead and either trim the results afterwards or have a mode parameter to drop references we don't care about?
| } | ||
|
|
||
| /// AST visitor that, for a single function/class body, records every callee. | ||
| struct OutgoingCallsFinder<'a, 'db> { |
There was a problem hiding this comment.
Same here. Could we reuse some of LocalReferencesFinder
|
This is awesome. Thank you! I did a few changes, mainly to how the test work and I split the implementation into multiple modules. I'll also remove the benchmark. While cool, I'm worried that it's noisy |
Merging this PR will degrade performance by 4.38%
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Co-authored-by: Micha Reiser <[email protected]>
|
Awesome thanks! Yes, the benchmark wasn't terribly helpful. Great, thanks for the time spent reviewing and updating the code. Do you have a rough timeline for a next release candidate of |
We do very frequent releases. It should go out in the next few days |
|
@mhuen could you update https://docs.astral.sh/ty/features/language-server/#feature-reference? Similar to what was done in https://github.com/astral-sh/ty/pull/3382/changes. You need to add Great job. |
I had opened astral-sh/ty#3592, but as @MichaReiser points out, it may not be necessary |
Summary
Adds support for LSP call hierarchy calls including:
textDocument/prepareCallHierarchycallHierarchy/incomingcallHierarchy/outgoingCloses astral-sh/ty#1976
Test Plan
crates/ty_ide/src/call_hierarchy.rscrates/ty_server/tests/e2e/call_hierarchy.rspyright(see known differences below)anyioKnown differences to pyright (version 1.1.408)
lambdabodies__init__'s body instead; reports nothing for classes without__init__def/class/lambdabodiesdefssuper().__init__()incoming reported once(file, caller selection range)@propertydispatched by access kindc.prop) matches getter only; write (c.prop = v) matches setter only;del(del c.prop) matches deleter onlydelunder getter+setter+deleterkindreflects the real symbol kindMethod(6),Class(5), orFunction(12) based on the caller's enclosing scopeFunction(12) regardless of caller typefrom x import f as g; g()reports as a caller offincomingCalls: null