Skip to content
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

Improve hovers for patterns #59966

Open
DanTup opened this issue Jan 23, 2025 · 5 comments
Open

Improve hovers for patterns #59966

DanTup opened this issue Jan 23, 2025 · 5 comments
Labels
analyzer-hover Issues related to hovers analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request

Comments

@DanTup
Copy link
Collaborator

DanTup commented Jan 23, 2025

It would be great if hovering over patterns in the editors showed some documentation/explanation of the pattern (and maybe some links to the website).

Additionally, in code like:

if (instance case Class(:var myGetter)) {

The hover for myField doesn't show any information about the myGetter member on Class but it would be useful to (because there's no other code you can hover to get it), either directly in the tooltip (but clear that myGetter here is also a variable declaration), or some clickable link to get to the definition of Class.myGetter. There's some additional discussion about this here: #59943

@DanTup DanTup added analyzer-hover Issues related to hovers analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Jan 23, 2025
@FMorschel
Copy link
Contributor

FMorschel commented Jan 23, 2025

Can the hover appear differently (the same as today probably) if this code changed to the following? Also, would that be something we want to do?

if (instance case Class(myGetter: var myGetter)) {

@DanTup
Copy link
Collaborator Author

DanTup commented Jan 23, 2025

Yeah, in the case where the getter/variable are both explicitly written, I think their hovers should continue to be individual. I think only in the case where the same string in the source is doing double-duty (and therefore there's no way to hover the two of them separately) should there by some kind of "combined" tooltip.

(the same as today probably)

Today I don't think we show any information/documentation about patterns, so I think we should still improve what's there for your last code sample (for example explaining what kind of pattern this is and - if appropriate - a link to more detailed docs).

@bwilkerson bwilkerson added the P3 A lower priority bug or feature request label Jan 23, 2025
@bwilkerson
Copy link
Member

That sgtm.

As per #59943 (comment), I do think it would be beneficial to decide what information we want to show, and if we do that in this issue (rather than in a CL) then more of the community has the opportunity to weigh in.

@DanTup
Copy link
Collaborator Author

DanTup commented Jan 23, 2025

What about if we just tag some additional information to the end of existing hovers in the case where they are part of a pattern?

For example in:

if (instance case Class(:var myGetter)) {

Hovering over myGetter might show something like:

usual hover for the myGetter variable
----- separator -----
myGetter is a variable introduced by an Object Pattern and assigned the value of [Class.myGetter] from the expression.

For more information about Object Patterns, see https://dart.dev/language/pattern-types#object

I don't know if implementing "dynamic" messages like this for each kind of pattern would be simple, but I think it could be helpful when reading code if you're not familiar with patterns (sometimes I get confused by the patterns I have written myself 😄).

I don't know what such text would look like for something like this though:

if (json case {'user': [String name, int age]}) {
  print('User $name is $age years old.');
}

If I hover over name in the pattern here, it might be less trivial to construct a string that reasonable describes what it's matching 🤔

@FMorschel
Copy link
Contributor

FMorschel commented Jan 23, 2025

I like the idea. For the last example, with type-literals we could replace:

and assigned the value of [Class.myGetter] from the expression

For something like:

and assigned the respective value from the < Type > literal expression

If we can infer the type literal in here it would be great. I think the closer type literal would be better than Map in this case - thinking of really nested types where would be hard to visualize it all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-hover Issues related to hovers analyzer-server area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants