Don't suggest anything right after double or integer literals.

R=brianwilkerson@google.com, danrubel@google.com

Change-Id: Ib8b9091daedb1e1921ae3c454e83a5b96d94a71a
Reviewed-on: https://dart-review.googlesource.com/40471
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
This commit is contained in:
Konstantin Shcheglov 2018-02-12 01:18:35 +00:00
parent 456890cd2c
commit 7cffd55c41
5 changed files with 52 additions and 0 deletions

View file

@ -31,6 +31,12 @@ class KeywordContributor extends DartCompletionContributor {
Future<List<CompletionSuggestion>> computeSuggestions(
DartCompletionRequest request) async {
List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
// Don't suggest anything right after double or integer literals.
if (request.target.isDoubleOrIntLiteral()) {
return suggestions;
}
request.target.containingNode
.accept(new _KeywordVisitor(request, suggestions));
return suggestions;

View file

@ -1423,6 +1423,18 @@ class A {
relevance: DART_RELEVANCE_HIGH);
}
test_integerLiteral_inArgumentList() async {
addTestSource('main() { print(42^); }');
await computeSuggestions();
assertSuggestKeywords([]);
}
test_integerLiteral_inListLiteral() async {
addTestSource('main() { var items = [42^]; }');
await computeSuggestions();
assertSuggestKeywords([]);
}
test_is_expression() async {
addTestSource('main() {if (x is^)}');
await computeSuggestions();

View file

@ -313,6 +313,19 @@ class CompletionTarget {
return new SourceRange(requestOffset, 0);
}
/**
* Return `true` if the target is a double or int literal.
*/
bool isDoubleOrIntLiteral() {
var entity = this.entity;
if (entity is Token) {
TokenType previousTokenType = entity.previous?.type;
return previousTokenType == TokenType.DOUBLE ||
previousTokenType == TokenType.INT;
}
return false;
}
/**
* Return `true` if the target is a functional argument in an argument list.
* The target [AstNode] hierarchy *must* be resolved for this to work.

View file

@ -113,6 +113,12 @@ class OpType {
*/
factory OpType.forCompletion(CompletionTarget target, int offset) {
OpType optype = new OpType._();
// Don't suggest anything right after double or integer literals.
if (target.isDoubleOrIntLiteral()) {
return optype;
}
target.containingNode
.accept(new _OpTypeAstVisitor(optype, target.entity, offset));
var mthDecl =

View file

@ -1178,6 +1178,21 @@ class OpTypeTest extends AbstractContextTest {
await assertOpType(returnValue: true, typeNames: true);
}
test_IntegerLiteral_inArgumentList() async {
addTestSource('main() { print(1^); }');
await assertOpType();
}
test_IntegerLiteral_inListLiteral() async {
addTestSource('main() { var items = [1^]; }');
await assertOpType();
}
test_DoubleLiteral() async {
addTestSource('main() { print(1.2^); }');
await assertOpType();
}
test_IsExpression_type_partial() async {
// SimpleIdentifier TypeName IsExpression IfStatement
addTestSource('main(){var a; if (a is Obj^)}');