Skip to content

Conversation

Gankra
Copy link
Contributor

@Gankra Gankra commented Aug 21, 2025

This introduces GotoTarget::Call that represents the kind of ambiguous/overloaded click of a callable-being-called:

x = mymodule.MyClass(1, 2)
             ^^^^^^^

This is equivalent to GotoTarget::Expression for the same span but enriched
with information about the actual callable implementation.

That is, if you click on MyClass in MyClass() it is both a
reference to the class and to the initializer of the class. Therefore
it would be ideal for goto-* and docstrings to be some intelligent
merging of both the class and the initializer.

In particular the callable-implementation (initializer) is prioritized over the callable-itself (class) so when showing docstrings we will preferentially show the docs of the initializer if it exists, and then fallback to the docs of the class.

For goto-definition/goto-declaration we will yield both the class and the initializer, requiring you to pick which you want (this is perhaps needlessly pedantic but...).

Fixes astral-sh/ty#898
Fixes astral-sh/ty#1010

@Gankra Gankra added the server Related to the LSP server label Aug 21, 2025
@Gankra Gankra added the ty Multi-file analysis & type inference label Aug 21, 2025
Copy link
Contributor

github-actions bot commented Aug 21, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

Copy link
Contributor

github-actions bot commented Aug 21, 2025

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@MichaReiser
Copy link
Member

MichaReiser commented Aug 21, 2025

For goto-definition/goto-declaration we will yield both the class and the initializer, requiring you to pick which you want (this is perhaps needlessly pedantic but...).

Pyright jumps to the definition of the class. I'm leaning towards aligning the behavior for now (although it is somewhat unexpected, so maybe what you have is best)

@Gankra
Copy link
Contributor Author

Gankra commented Aug 21, 2025

Something I've vaguely been considering is another variant of DefinitionsOrTargets that has two lists of definitions: one is the "right" answer and one is "fallback". So docstrings would consider both but goto-def would be opinionated and just pick one?

@AlexWaygood AlexWaygood removed their request for review August 21, 2025 18:13
@Gankra
Copy link
Contributor Author

Gankra commented Aug 21, 2025

Surprisingly a lot of reports of different IDEs actually making the ( of the call separately clickable as the ctor call!

@MichaReiser
Copy link
Member

Surprisingly a lot of reports of different IDEs actually making the ( of the call separately clickable as the ctor call!

This sounds nice

@Gankra
Copy link
Contributor Author

Gankra commented Sep 2, 2025

Ok I've rebased this on top of #20148 and minimized its intelligence, making this a reasonably safe change. I'm going to land this now (feedback is the best way to iterate on exact UX of this I think).

@Gankra Gankra merged commit ec55842 into main Sep 2, 2025
37 checks passed
@Gankra Gankra deleted the gankra/goto-init branch September 2, 2025 18:49
PieterCK pushed a commit to PieterCK/ruff that referenced this pull request Sep 9, 2025
This introduces `GotoTarget::Call` that represents the kind of
ambiguous/overloaded click of a callable-being-called:

```py
x = mymodule.MyClass(1, 2)
             ^^^^^^^
```

This is equivalent to `GotoTarget::Expression` for the same span but
enriched
with information about the actual callable implementation.

That is, if you click on `MyClass` in `MyClass()` it is *both* a
reference to the class and to the initializer of the class. Therefore
it would be ideal for goto-* and docstrings to be some intelligent
merging of both the class and the initializer.

In particular the callable-implementation (initializer) is prioritized
over the callable-itself (class) so when showing docstrings we will
preferentially show the docs of the initializer if it exists, and then
fallback to the docs of the class.

For goto-definition/goto-declaration we will yield both the class and
the initializer, requiring you to pick which you want (this is perhaps
needlessly pedantic but...).

Fixes astral-sh/ty#898
Fixes astral-sh/ty#1010
second-ed pushed a commit to second-ed/ruff that referenced this pull request Sep 9, 2025
This introduces `GotoTarget::Call` that represents the kind of
ambiguous/overloaded click of a callable-being-called:

```py
x = mymodule.MyClass(1, 2)
             ^^^^^^^
```

This is equivalent to `GotoTarget::Expression` for the same span but
enriched
with information about the actual callable implementation.

That is, if you click on `MyClass` in `MyClass()` it is *both* a
reference to the class and to the initializer of the class. Therefore
it would be ideal for goto-* and docstrings to be some intelligent
merging of both the class and the initializer.

In particular the callable-implementation (initializer) is prioritized
over the callable-itself (class) so when showing docstrings we will
preferentially show the docs of the initializer if it exists, and then
fallback to the docs of the class.

For goto-definition/goto-declaration we will yield both the class and
the initializer, requiring you to pick which you want (this is perhaps
needlessly pedantic but...).

Fixes astral-sh/ty#898
Fixes astral-sh/ty#1010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Related to the LSP server ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support initializer calls as GotoTargets Include class docstring in signature help for constructor calls
2 participants