microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.67k stars 770 forks source link

Show class attribute documentation on hover, similar to how parameter documentation is displayed #6017

Closed macintacos closed 1 week ago

macintacos commented 1 week ago

When hovering over a class attribute, it would be great if it showed documentation for that attribute, similar to how documentation hover works for parameters within a method.

Here's an example (using the syntax resolved in #3347 - I'm currently using the pre-release version of Pylance, v2024.6.100 (pre-release)):

class Foo:
    """Documentation for Foo.

    Parameters:
        bar (str): This is the docstring for `bar`.
        baz (int): This is the docstring for `baz`.
    """

    def __init__(self, bar: str, baz: int) -> None:
        self.bar = bar
        self.baz = baz

    def some_method(self, thing: str) -> None:
        """A summary for some_method.

        Args:
            thing (str): This is documentation for the `thing` param.
        """
        print(thing)

test = Foo(bar="something", baz=123)

print(test.bar)

Here's what I see when I hover my mouse over bar in the last print(test.bar) line:

CleanShot 2024-06-15 at 19 33 46@2x

And here's what I see when I hover my mouse over thing in Food.some_method:

CleanShot 2024-06-15 at 19 34 22@2x

I know that Pylance is "aware" of these parameters and their documentation, because it does get shown to me as I type:

CleanShot 2024-06-15 at 19 36 38@2x

As such, it would be great if that same documentation bits for class attributes could be shown in the hover window like parameters' documentation is shown for methods.

debonte commented 1 week ago

The bar parameter on Foo.__init__ and the Foo.bar instance attribute are technically two different things, but I can see that in many cases you'd want them to both have the same docstring.

Moving this issue to discussions as an enhancement request for comments and upvotes.