Analyzer API: Could the potential types of an AstNode/Element property be documented? #50675
Labels
analyzer-api
Issues that impact the public API of the analyzer package
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
P4
type-enhancement
A request for a change that isn't a bug
Hello!
Problem
This is general feedback about the Analyzer API. It's working great, but I believe there's some usability concerns related to knowing what are the potential types of a given property.
More specifically, the Analyzer API largely relies on subclasses. For example
Element
vsExpression
vsAssignmentExpression
.And due to the power of Dart, there a lot of options.
The issue is, when we look at a specific variable exposed by the Analyzer, it is often typed as a lowr-level interface.
For example,
AssignmentExpression.leftHandSide
is typed asExpression
. But that's not very clear. Because there are a ton of subclasses forExpression
, but many of which will never be used byleftHandSide
. One case could be:leftHandSide
will never be aListLiterral
, As[] = value
is not a valid Dart syntaxCurrently, we can only make an educated guess about what the concrete types for a variable is.
For example, my assumption is that
AssignmentExpression.leftHandSide
is in factIdentifier | IndexExpression
, respectively forvariable = 42
vslist[0] = 42
. But that's only my guess, and it's very likely I missed one option.Proposal
Would it be possible to list the potential concrete types in the dartdoc of any given property?
For example, the doc of
AssignmentExpression.leftHandSide
could be:Alternatively, but also involving a lot more work and possibly breaking, an option would be to avoid using shared interfaces like
Expression
and instead define new unique interfaces likeLefHandSideExpression
. Such that we'd have:Then, it becomes possible to use search options like "Search all references"/"Search all implementations".
With such an approach, instead of having the list of all Expressions pop up, only the ones that we are concerned with would show up.
This could also later be adapted to use the upcoming pattern-matching feature. Using some form of sealed class, it could become possible to write an exhaustive check like:
But of course, the dartdoc option is probably faster to implement for now.
The text was updated successfully, but these errors were encountered: