mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:36:59 +00:00
[analysis_server] Handle prefixed Flutter widget creation expressions for assists
Fixes https://github.com/Dart-Code/Dart-Code/issues/4169. Change-Id: I3b462c69520593cbb9db2dc30ae19b8c93deed20 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260601 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
eb17780ef1
commit
3e9a99df6a
|
@ -231,21 +231,23 @@ class Flutter {
|
||||||
|
|
||||||
/// Return the instance creation expression that surrounds the given
|
/// Return the instance creation expression that surrounds the given
|
||||||
/// [node], if any, else null. The [node] may be the instance creation
|
/// [node], if any, else null. The [node] may be the instance creation
|
||||||
/// expression itself or the identifier that names the constructor.
|
/// expression itself or an (optionally prefixed) identifier that names the
|
||||||
|
/// constructor.
|
||||||
InstanceCreationExpression? identifyNewExpression(AstNode? node) {
|
InstanceCreationExpression? identifyNewExpression(AstNode? node) {
|
||||||
InstanceCreationExpression? newExpr;
|
InstanceCreationExpression? newExpr;
|
||||||
if (node is SimpleIdentifier) {
|
if (node is SimpleIdentifier) {
|
||||||
var parent = node.parent;
|
node = node.parent;
|
||||||
var grandParent = parent?.parent;
|
}
|
||||||
var greatGrandParent = grandParent?.parent;
|
if (node is PrefixedIdentifier) {
|
||||||
if (parent is ConstructorName &&
|
node = node.parent;
|
||||||
grandParent is InstanceCreationExpression) {
|
}
|
||||||
newExpr = grandParent;
|
if (node is NamedType) {
|
||||||
} else if (grandParent is ConstructorName &&
|
node = node.parent;
|
||||||
greatGrandParent is InstanceCreationExpression) {
|
}
|
||||||
newExpr = greatGrandParent;
|
if (node is ConstructorName) {
|
||||||
}
|
node = node.parent;
|
||||||
} else if (node is InstanceCreationExpression) {
|
}
|
||||||
|
if (node is InstanceCreationExpression) {
|
||||||
newExpr = node;
|
newExpr = node;
|
||||||
}
|
}
|
||||||
return newExpr;
|
return newExpr;
|
||||||
|
|
|
@ -301,6 +301,52 @@ void f() {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> test_prefixedConstructor_onConstructor() async {
|
||||||
|
await resolveTestCode('''
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/material.dart' as m;
|
||||||
|
void f() {
|
||||||
|
Center(
|
||||||
|
child: m./*caret*/Center(
|
||||||
|
child: Text(''),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
await assertHasAssist('''
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/material.dart' as m;
|
||||||
|
void f() {
|
||||||
|
Center(
|
||||||
|
child: Text(''),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> test_prefixedConstructor_onPrefix() async {
|
||||||
|
await resolveTestCode('''
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/material.dart' as m;
|
||||||
|
void f() {
|
||||||
|
Center(
|
||||||
|
child: /*caret*/m.Center(
|
||||||
|
child: Text(''),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
''');
|
||||||
|
await assertHasAssist('''
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/material.dart' as m;
|
||||||
|
void f() {
|
||||||
|
Center(
|
||||||
|
child: Text(''),
|
||||||
|
);
|
||||||
|
}
|
||||||
''');
|
''');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue