dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.12k stars 1.57k forks source link

Feature Request - include the data of a constant when hovering over a constant. #45777

Open ghost opened 3 years ago

ghost commented 3 years ago

@atreeon commented on Apr 10, 2021, 1:31 PM UTC:

In other languages and IDEs when a constant variable is hovered over the data of the constant is shown in the popup help box. Would this be possible in flutter intellij idea?

const MY_CONST = const MyClass(5);

class MyClass {
  final int value;
  const MyClass(this.value);
}

Screenshot 2021-04-10 at 14 30 31

This issue was moved by helin24 from flutter/flutter-intellij#5392.

ghost commented 3 years ago

move[bot] commented on Apr 15, 2021, 3:58 PM UTC:

⚠️ You must have write permission for the target repository.
ghost commented 3 years ago

@jwren commented on Apr 15, 2021, 7:46 PM UTC:

I created a tracking issue in YouTrack: https://youtrack.jetbrains.com/issue/WEB-50553

bwilkerson commented 3 years ago

As the YouTrack issue notes, this support would be in the analysis server.

The analysis server has performed a symbolic execution of the constant, so it does know the value of the constant. The problem is that the analysis server does not have the ability to execute code other than that allowed in constant expressions, so it can't execute the toString method of an arbitrary object. We could nicely display "primitive" objects (ints, booleans, strings, etc.), but we'd need to figure out how to display instances of user defined classes.

It might be worthwhile to display the value of constants when they are primitive types even if we can't display user defined types.

annagrin commented 3 years ago

Related: https://github.com/dart-lang/sdk/issues/41999

annagrin commented 3 years ago

@helin24 @bwilkerson is this request for displaying values during debugging?

bwilkerson commented 3 years ago

My assumption is that the request is for values to be displayed when not debugging, but @atreeon can answer that better than I can. It's my understanding that IntelliJ already displays values of both constants and non-constants while debugging.

helin24 commented 3 years ago

This is my understanding as well - looking to see values of constants on mouseover in editor, for example.

annagrin commented 3 years ago

@bwilkerson @atreeon it does not for web platform, so I wonder if the request is the same as the issue I linked above.

jwren commented 3 years ago

@annagrin that is correct, this is not when debugging, but from the static analysis of the source

atreeon commented 3 years ago

Hi, thanks for updating this. Apologies for not specifying whether in debug or outside of debug. Can we have this outside of debug too?

srawlins commented 3 years ago

This would be a pretty neat feature, and I suspect not wildly difficult. 😄

bwilkerson commented 3 years ago

See my comments above regarding executing toString (https://github.com/dart-lang/sdk/issues/45777#issuecomment-824201597). Do you have ideas for how to display readable values without executing user code? The only alternative I've thought of would be a basic object dump, something like MyClass(value: 5) (using the example from the OP). Maybe most constant values would be simple enough for this form, but there is at least an edge case where this form would be unreadable. For example, consider something like one of our error codes (https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/error/codes.dart#L71). I think that would be difficult to display nicely in a hover.

(There are also extreme cases such as https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/lib/src/services/correction/fix_internal.dart#L320, but we'd probably need to have some kind of cut-off so that all we displayed in a case like that was a notice that the value is too large.)

jwren commented 3 years ago

Echoing what you said above Brian:

It might be worthwhile to display the value of constants when they are primitive types even if we can't display user defined types.

"Just" having the values for final primitives would go along way.

bwilkerson commented 3 years ago

If we're talking about final rather than const then that's a different issue. The analyzer computed values for all const fields because doing so is required to be spec compliant. But it doesn't compute values for final fields, so we wouldn't have any value to display. But adding support for const fields of primitive types might be useful and we can always expand the support in the future.