Skip to content

Commit 8a1c020

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[analyzer] Handle null-aware elements in code completion
Part of #56989 Change-Id: Id02c049d0afb5cb6c3f1d94ee5bebf7ca532e2e2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392902 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 729c1c0 commit 8a1c020

File tree

3 files changed

+868
-0
lines changed

3 files changed

+868
-0
lines changed

pkg/analysis_server/lib/src/services/completion/dart/in_scope_completion_pass.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,21 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
18021802
void visitMapLiteralEntry(MapLiteralEntry node) {
18031803
if (offset == node.offset) {
18041804
node.parent?.accept(this);
1805+
} else if (node.keyQuestion != null && offset == node.key.offset) {
1806+
// This is the case of the marker standing after the null-aware marker
1807+
// '?', but before the key expression. It is a place where an expression
1808+
// is expected.
1809+
node.parent?.accept(this);
1810+
collector.completionLocation = 'NullAwareElement_value';
1811+
} else if (node.valueQuestion != null &&
1812+
(offset == node.separator.end ||
1813+
offset == node.valueQuestion!.offset ||
1814+
offset == node.value.offset)) {
1815+
// This is the case of the marker standing either before or after the
1816+
// null-aware marker '?' in the value. It is a place where an expression
1817+
// is expected.
1818+
node.parent?.accept(this);
1819+
collector.completionLocation = 'NullAwareElement_value';
18051820
} else if (offset >= node.separator.end) {
18061821
collector.completionLocation = 'MapLiteralEntry_value';
18071822
declarationHelper(mustBeStatic: node.inStaticContext)
@@ -2045,6 +2060,12 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
20452060
);
20462061
}
20472062

2063+
@override
2064+
void visitNullAwareElement(NullAwareElement node) {
2065+
collector.completionLocation = 'NullAwareElement_value';
2066+
_forExpression(node);
2067+
}
2068+
20482069
@override
20492070
void visitNullLiteral(NullLiteral node) {
20502071
_forExpression(node);

0 commit comments

Comments
 (0)