Skip to content

Commit 1dffc4a

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Fixes nested pattern keyword completion
Fixes: #60917 Change-Id: I711dd50383f73f5a59eea5ebf659dcef72e3c76f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435400 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Auto-Submit: Felipe Morschel <[email protected]>
1 parent 70b691e commit 1dffc4a

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2242,7 +2242,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
22422242
_forVariablePattern();
22432243
}
22442244
var isKeywordNeeded = false;
2245-
if (node.parent?.parent is GuardedPattern) {
2245+
if (node.thisOrAncestorOfType<GuardedPattern>() != null) {
22462246
isKeywordNeeded = true;
22472247
}
22482248
_forPatternFieldName(

pkg/analysis_server/test/lsp/completion_dart_test.dart

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,47 @@ void f() {
255255
expectDocumentation(resolved, contains('Enum Member.'));
256256
}
257257

258+
Future<void> test_innerPatternKeyword() async {
259+
content = '''
260+
class A {
261+
A([this.value]);
262+
A? value;
263+
}
264+
265+
void main() {
266+
final value = A(A(A()));
267+
if (value case A(value: A(:^))) {}
268+
}
269+
''';
270+
await initializeServer();
271+
272+
var code = TestCode.parse(content);
273+
var completion = await getCompletionItem('value');
274+
expect(completion, isNotNull);
275+
276+
// Resolve the completion item to get its edits.
277+
var resolved = await resolveCompletion(completion);
278+
279+
// Apply all current-document edits.
280+
var newContent = applyTextEdits(code.code, [
281+
toTextEdit(resolved.textEdit!),
282+
]);
283+
expect(
284+
newContent,
285+
equals('''
286+
class A {
287+
A([this.value]);
288+
A? value;
289+
}
290+
291+
void main() {
292+
final value = A(A(A()));
293+
if (value case A(value: A(:var value))) {}
294+
}
295+
'''),
296+
);
297+
}
298+
258299
/// We should not show `var`, `final` or the member type on the display text.
259300
Future<void> test_pattern_member_name_only() async {
260301
content = '''

0 commit comments

Comments
 (0)