Skip to content

Improve representation of static/declared types in getHover response from analysis server #34196

Closed

Description

@DanTup

Given some code like this:

final a = _getAnimal();

if (a is Horse) {
  print(a.showSize);
}

Inside the if block the variable a has a static type of Horse (yay!). However, the elementDescription returned by the server is just Animal a so it's not clear from the tooltip that analysis is treating this as a Horse.

The actual server response looks something like this:

{
	"id": "36",
	"result": {
		"hovers": [
			{
				"offset": 6559,
				"length": 6,
				"elementDescription": "Animal a",
				"elementKind": "local variable",
				"isDeprecated": false,
				"staticType": "Horse"
			}
		]
	}

The staticType is available here. However in the case where matches the declared type (for ex. a standard String) the field is still populated. Since the declared type is embedded inside the elementDescription property it's hard for an editor to display this information well (to avoid redundancy, we'd have to parse elementDescription up).

Some possible options suggested by @bwilkerson in Dart-Code/Dart-Code#1160 (comment) are:

  1. Split elementDescription into its two parts (declared type and name)
  2. A single "description" field that combines all of this information to display to the user
  3. Omit the staticType if it's redundant (already in elementDescription)

Also:

We need to think about cases where there is no declared type (such as var x = ...), cases like the one above where the declared and static type are significantly different (Object vs Instance), and cases where the static type is just a refinement (List vs List<String>). And, of course, we shouldn't forget the cases where the variable isn't declared at all.

Activity

  1. added
    type-enhancementA request for a change that isn't a bug
    devexp-serverIssues related to some aspect of the analysis server
    on Aug 28, 2018
  2. added
    contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)
    on May 20, 2022
  3. DanTup commented on Jun 6, 2023

    @DanTup
    CollaboratorAuthor

    5bf643b added the static type to the hover:

    static type in tooltip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)devexp-serverIssues related to some aspect of the analysis serverlegacy-area-analyzerUse area-devexp instead.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions