[ty] Display docs for matching parameter when hovering over the name of an argument passed by keyword.#25283
Conversation
689d747 to
f20d2dd
Compare
19392c3 to
adf04b1
Compare
|
I only skimmed the code, but I wonder whether this works with overloads where the parameter is only documented in the implementation? Can you also say a little more on the taken implementation approach for the argument/parameter "matching"? Like what was your thinking behind adding a new matching vs extending |
|
Related (but also somewhat different) astral-sh/ty#3538 |
|
|
||
| fn parameter_hover_label(label: &str, is_keyword_variadic: bool) -> String { | ||
| let kind = if is_keyword_variadic { | ||
| "variadic keyword parameter" |
There was a problem hiding this comment.
It is, but on the other hand it is accurate and helps explain the difference between the name of the parameter and the name of the hover target in this case. Can you think of another way to express the same idea? Or would you prefer that we didn't try and just left this as plain "parameter"?
I won't block on this, but I will plan to address this in a follow-up if you have further thoughts.
Yes it does, because it reuses the existing doc lookup helpers (which already handle that type of fallback). For the same reason however, it does not handle the edge case where the overload contains a general docstring but only the implementation contains parameter specific docs: in that case we will show the parameter information from the selected overload but no docs. I think that's acceptable as a first pass, but in the future we might consider a further, parameter-specific extension to doc lookup. I will add a few regression tests to demonstrate these behaviours.
I'm not sure what you mean by I see an adjacent concept called |
Yes, precisely. |
I think that issue will also be addressed by this PR: hovering over the argument name will show both parameter info (as requested) and docs, and hovering over the argument value will still display inferred type information. |
adf04b1 to
436728c
Compare
…of an argument passed by keyword. (astral-sh#25283) <!-- Thank you for contributing to Ruff/ty! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? (Please prefix with `[ty]` for ty pull requests.) - Does this pull request include references to any relevant issues? - Does this PR follow our AI policy (https://github.com/astral-sh/.github/blob/main/AI_POLICY.md)? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> This makes it so that hovering over the name of an argument passed by keyword shows the matching parameter label and documentation rather than the inferred type of the argument value: ```py def test(ab: int): """my cool test Args: ab: a nice little integer """ return 0 test(ab=123) ^ ``` ````txt (parameter) ab: int --------------------------------------------- a nice little integer ```` Two additional notes on this new behaviour: - For a parameter without any documentation, we will show just the parameter label: `(parameter) ab: int`. - We will also show the documentation for a variadic keyword parameter (i.e., `**kwargs`) when the argument name maps to that type of parameter. By contrast, nothing changes when hovering over the argument value: it will continue to show the inferred type of the value: ```py value = 123 def test(ab: int): """my cool test Args: ab: a nice little integer """ return 0 test(ab=value) ^ ``` ````txt Literal[123] ```` Closes astral-sh/ty#1350. Closes astral-sh/ty#3538. ## Test Plan Please see included tests. <!-- How was it tested? -->
Summary
This makes it so that hovering over the name of an argument passed by keyword shows the matching parameter label and documentation rather than the inferred type of the argument value:
Two additional notes on this new behaviour:
(parameter) ab: int.**kwargs) when the argument name maps to that type of parameter.By contrast, nothing changes when hovering over the argument value: it will continue to show the inferred type of the value:
Closes astral-sh/ty#1350.
Closes astral-sh/ty#3538.
Test Plan
Please see included tests.