Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to show expanded type instead of type alias on hover #847

Closed
vishwa-raj opened this issue Jan 17, 2021 · 14 comments
Closed

Option to show expanded type instead of type alias on hover #847

vishwa-raj opened this issue Jan 17, 2021 · 14 comments
Labels
enhancement New feature or request

Comments

@vishwa-raj
Copy link

vishwa-raj commented Jan 17, 2021

Can we have an option to show the expanded types instead of the type alias on hover ?

If one uses type aliases to shorten and reuse type hint definitions and there are nested type alias definitions across files, then it becomes very difficult to track down the actual type values.

@vishwa-raj vishwa-raj changed the title Option to show expanded type instead of type alias Option to show expanded type instead of type alias on hover Jan 18, 2021
@judej judej added the enhancement New feature or request label Jan 19, 2021
@github-actions github-actions bot removed the triage label Jan 19, 2021
@judej
Copy link
Contributor

judej commented Jan 19, 2021

This is similar to #562. Will look at adding a toggle depending on upvotes

@jakebailey
Copy link
Member

See my comment here: #562 (comment)

This current behavior is pretty deliberate.

@vishwa-raj
Copy link
Author

@jakebailey Yes, I did realize that this behavior is deliberate after going through other related issues (though missed 562).
Hence I requested to make it optional instead of a complete change.

@judej Thanks. Waiting for sufficient upvotes then on 562.

@jakebailey
Copy link
Member

This issue (that you opened) would be the place to vote; #562 actually turned out to reveal a bug and has since been fixed.

@vishwa-raj
Copy link
Author

@jakebailey Ah, thanks for clarifying.

@vishwa-raj
Copy link
Author

@jakebailey I just realised that type aliases do expand on hover or in suggestions when they are part of a Union.
If only there was an option to expand them otherwise as well 🙂

image

image

@jakebailey
Copy link
Member

They expand because Unions are normalized and type alias names get lost.

TypeScript recently changed this behavior themselves (as they used to do what we do), but we had been pondering adopting their method to preserve type names as much as possible (which is probably the opposite direction you were hoping for).

@vishwa-raj
Copy link
Author

vishwa-raj commented Jun 29, 2021

@jakebailey Think about it this way:

A type alias allows us to define a large and complex type annotation once and use it multiple times throughout our code, helping to keep it concise and clear.

Now say I import the function func, in the above screenshot, in a file and try to call it by providing the arguments.
The tooltip, like in the second screenshot, will show me ANIMAL_T instead of the actual values, and to know the actual values I'll have to navigate to the source file and check the definition for ANIMAL_T.
And if I have to navigate to the source file to get that info, what's the point of having the suggestion tooltips in the first place ?

@vishwa-raj
Copy link
Author

In PyCharm too we get the expanded view in tooltips.

@judej judej added the icebox label Sep 23, 2021
@macintacos
Copy link

To share my experience with this, I find it to be a little abrasive from a "developer experience" point of view to need to go-to-def on a type alias that I created more-so to save me from typing out a complicated type, not to "hide" the type.

Granted, at some point one must realize that you're probably just abusing the type system and should refactor 😅 but occasionally I stop myself from creating an alias simply so that I can still see the type information at a glance (or, at-least easier than doing a go-to-def on the alias itself). I'd really appreciate the ability to just see the whole type when hovering, or perhaps show the alias and the type it expands to side-by-side when I hover on a variable that uses the alias. The current implementation seems to actively want to discourage type aliasing because of the reasons previously stated (and the reasons other folks have mentioned in this thread).

All of this to just say - I'd really like for this to be implemented 🙂

@erictraut
Copy link
Contributor

Type aliases are a way to manage and hide complexity. A good alias name should reflect its usage. Can you share an example of a type alias that you've defined where its meaning is not clear from its name?

If you hover over a type alias name (e.g. within a type annotation), pylance will expand it to show you its definition. In other contexts, the type alias name will stand in for the full type that it represents.

We put a lot of effort into retaining and displaying the type alias name because we received feedback from many users that they were overwhelmed by the complexity of the full type, especially when large unions were involved.

I'll note that the current hover behavior in pylance is consistent with the behavior of other language servers like TypeScript and C#.

@macintacos
Copy link

Yep, understood that you can hover over the alias name itself in the annotation, but if you're dealing with a variable that's getting passed around, you'll have to go to the variable's definition and then hover over the alias definition - an extra step.

This is definitely a minor inconvenience for sure, and I agree that aliases themselves should have better naming schemes so that their names make their usage obvious. However, sometimes I've been dealing with code where someone has gotten a bit overzealous with how much heavy lifting the alias is actually doing (where the alias is a nested dict type def that can get quite nasty) and it's not really practical in the short term to break it out into "good" aliases, and in those situations being able to see the full complex type you're dealing with is helpful.

I can definitely understand how the complexity of a full type can overwhelm and distract users, hence why I also agree with the premise of this feature request which is to make this an option that users like myself could enable. I for one would appreciate if I could see the alias with it's definition in-line when I hover over a variable that uses that alias.

@judej judej removed the longterm label Mar 22, 2022
@bland328
Copy link

bland328 commented Apr 5, 2022

I can definitely understand how the complexity of a full type can overwhelm and distract users, hence why I also agree with the premise of this feature request which is to make this an option that users like myself could enable.

Agreed strongly. It seems to me there are (at least) two primary motivations for aliasing types:

  1. A desire to "abstract away" a complex and frequently-used type, in which case a user might reasonably be annoyed/distracted by the full definition continuing to appear ("I created that alias for a reason, dammit!").
  2. A desire to save the all the typing and/or screen real estate of a complex type definition that may be infrequently used, in which case best naming practices may well not be a reasonable substitute for a peek at the definition. ("Uh…how does thing work again?")

On top of that, there are some users who spend all day living inside a single code base with which they are intimately familiar, some users who poke around inside code bases they've never seen before, and some "low-volume" users who infrequently revisit code they once knew intimately.

With all that in mind, I'd argue that for a given user and/or situation, less might be more, or more might be more.

No software can reasonably be expected to be everything to everyone at all times, but given that VS Code is largely a software development tool, I humbly suggest that if it is going to "err on the side" of something, it should err on the side of showing the user more than they wish to see, rather than on the side of abstracting too much away.

@judej
Copy link
Contributor

judej commented Apr 20, 2022

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

@microsoft microsoft locked and limited conversation to collaborators Apr 20, 2022
@judej judej converted this issue into discussion #2715 Apr 20, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants