mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 16:37:43 +00:00
Improve completion at the beginning of an index expression
This is almost identical to the fix for completing at the beginning of a method invocation. There's probably a more consistent way to do this, but I'm not sure what that is at the moment. (I think we used to do this in `completionNode` but were skipping some nodes we shouldn't have been.) Change-Id: I3f220e0e79a91721b0c1235fdfc0f511ee7400a9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/373902 Reviewed-by: Keerti Parthasarathy <keertip@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
85f9e45434
commit
8b8a15059c
|
@ -1671,6 +1671,13 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
|
|||
|
||||
@override
|
||||
void visitIndexExpression(IndexExpression node) {
|
||||
var beginToken = node.beginToken;
|
||||
if (offset <= beginToken.end && beginToken.isKeywordOrIdentifier) {
|
||||
// The user is completing at the beginning of the expression, so let the
|
||||
// parent node determine the right set of suggestions.
|
||||
node.parent?.accept(this);
|
||||
return;
|
||||
}
|
||||
if (offset >= node.leftBracket.end && offset <= node.rightBracket.offset) {
|
||||
collector.completionLocation = 'IndexExpression_index';
|
||||
_forExpression(node, mustBeNonVoid: true);
|
||||
|
|
|
@ -51,6 +51,33 @@ suggestions
|
|||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterComma_beforeIndexExpression() async {
|
||||
await computeSuggestions('''
|
||||
void f(List<int> l0) {
|
||||
g(0, ^l0[1]);
|
||||
}
|
||||
void g(int i, int j) {}
|
||||
''');
|
||||
|
||||
assertResponse(r'''
|
||||
replacement
|
||||
right: 2
|
||||
suggestions
|
||||
l0
|
||||
kind: parameter
|
||||
true
|
||||
kind: keyword
|
||||
false
|
||||
kind: keyword
|
||||
null
|
||||
kind: keyword
|
||||
const
|
||||
kind: keyword
|
||||
switch
|
||||
kind: keyword
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterComma_beforeMethodInvocation() async {
|
||||
allowedIdentifiers = {'random'};
|
||||
await computeSuggestions('''
|
||||
|
|
Loading…
Reference in a new issue