Skip to content

Commit

Permalink
[analyzer] Handle null-aware elements in code completion
Browse files Browse the repository at this point in the history
Part of #56989

Change-Id: Id02c049d0afb5cb6c3f1d94ee5bebf7ca532e2e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392902
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
chloestefantsova authored and Commit Queue committed Nov 5, 2024
1 parent 729c1c0 commit 8a1c020
Show file tree
Hide file tree
Showing 3 changed files with 868 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,21 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
void visitMapLiteralEntry(MapLiteralEntry node) {
if (offset == node.offset) {
node.parent?.accept(this);
} else if (node.keyQuestion != null && offset == node.key.offset) {
// This is the case of the marker standing after the null-aware marker
// '?', but before the key expression. It is a place where an expression
// is expected.
node.parent?.accept(this);
collector.completionLocation = 'NullAwareElement_value';
} else if (node.valueQuestion != null &&
(offset == node.separator.end ||
offset == node.valueQuestion!.offset ||
offset == node.value.offset)) {
// This is the case of the marker standing either before or after the
// null-aware marker '?' in the value. It is a place where an expression
// is expected.
node.parent?.accept(this);
collector.completionLocation = 'NullAwareElement_value';
} else if (offset >= node.separator.end) {
collector.completionLocation = 'MapLiteralEntry_value';
declarationHelper(mustBeStatic: node.inStaticContext)
Expand Down Expand Up @@ -2045,6 +2060,12 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
);
}

@override
void visitNullAwareElement(NullAwareElement node) {
collector.completionLocation = 'NullAwareElement_value';
_forExpression(node);
}

@override
void visitNullLiteral(NullLiteral node) {
_forExpression(node);
Expand Down
Loading

0 comments on commit 8a1c020

Please sign in to comment.