Completion. Issue 54231. Fix suggesting through import prefix, when there is another identifier after it.
Bug: https://github.com/dart-lang/sdk/issues/54231 Change-Id: I06a5eb3763814fde99e2e2ba583679cc27c1a4b6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355546 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
Commit Queue
parent
59ad7082cc
commit
d976ce5b13
@@ -133,6 +133,22 @@ class DeclarationHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/// Add suggestions for declarations through [prefixElement].
|
||||
void addDeclarationsThroughImportPrefix(PrefixElement prefixElement) {
|
||||
for (var importElement in prefixElement.imports) {
|
||||
var importedLibrary = importElement.importedLibrary;
|
||||
if (importedLibrary == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
_addDeclarationsImportedFrom(
|
||||
library: importedLibrary,
|
||||
namespace: importElement.namespace,
|
||||
prefix: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Add any fields that can be initialized in the initializer list of the
|
||||
/// given [constructor]. If a [fieldToInclude] is provided, then it should not
|
||||
/// be skipped because the cursor is inside that field's name.
|
||||
|
||||
@@ -1525,6 +1525,22 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
|
||||
|
||||
@override
|
||||
void visitNamedType(NamedType node) {
|
||||
var importPrefix = node.importPrefix;
|
||||
var prefixElement = importPrefix?.element;
|
||||
|
||||
// `prefix.x^ print(0);` is recovered as `prefix.x print; (0);`.
|
||||
if (prefixElement is PrefixElement) {
|
||||
if (node.parent case VariableDeclarationList variableList) {
|
||||
if (variableList.parent case VariableDeclarationStatement statement) {
|
||||
if (statement.semicolon.isSynthetic) {
|
||||
declarationHelper()
|
||||
.addDeclarationsThroughImportPrefix(prefixElement);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_forTypeAnnotation(node);
|
||||
}
|
||||
|
||||
|
||||
+25
@@ -55,6 +55,31 @@ suggestions
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterIdentifier_beforeIdentifier_partial() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
void v01() {}
|
||||
void g01() {}
|
||||
''');
|
||||
|
||||
// There should be no `void`, we use `v` to verify this.
|
||||
await computeSuggestions('''
|
||||
import 'a.dart' as prefix;
|
||||
|
||||
void f() {
|
||||
prefix.v^
|
||||
print(0);
|
||||
}
|
||||
''');
|
||||
|
||||
assertResponse(r'''
|
||||
replacement
|
||||
left: 1
|
||||
suggestions
|
||||
v01
|
||||
kind: functionInvocation
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterIdentifier_partial() async {
|
||||
await computeSuggestions('''
|
||||
class A { foo() {bar.as^}}
|
||||
|
||||
Reference in New Issue
Block a user