File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
lib/src/services/completion/dart Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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 = '''
You can’t perform that action at this time.
0 commit comments