Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(807)

Unified Diff: pkg/analysis_server/lib/src/services/completion/local_computer.dart

Issue 635043002: show only type names in is expression RHS (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/completion/local_computer.dart
diff --git a/pkg/analysis_server/lib/src/services/completion/local_computer.dart b/pkg/analysis_server/lib/src/services/completion/local_computer.dart
index 77a186903bfbb05eb8e3bd4d031fe6db032b6eec..aedc167f74b32b7623a505036b2acf00f9d0aab2 100644
--- a/pkg/analysis_server/lib/src/services/completion/local_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/local_computer.dart
@@ -6,7 +6,8 @@ library services.completion.computer.dart.local;
import 'dart:async';
-import 'package:analysis_server/src/protocol.dart' as protocol show Element, ElementKind;
+import 'package:analysis_server/src/protocol.dart' as protocol show Element,
+ ElementKind;
import 'package:analysis_server/src/protocol.dart' hide Element, ElementKind;
import 'package:analysis_server/src/services/completion/dart_completion_manager.dart';
import 'package:analyzer/src/generated/ast.dart';
@@ -56,6 +57,7 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
null);
final DartCompletionRequest request;
+ bool typesOnly = false;
_LocalVisitor(this.request);
@@ -83,10 +85,19 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
@override
+ visitCascadeExpression(CascadeExpression node) {
+ Expression target = node.target;
+ // This computer handles the expression
+ // while InvocationComputer handles the cascade selector
+ if (target != null && request.offset <= target.end) {
+ visitNode(node);
+ }
+ }
+
+ @override
visitCatchClause(CatchClause node) {
_addParamSuggestion(node.exceptionParameter, node.exceptionType);
- CompletionSuggestion suggestion =
- _addParamSuggestion(node.stackTraceParameter, STACKTRACE_TYPE);
+ _addParamSuggestion(node.stackTraceParameter, STACKTRACE_TYPE);
visitNode(node);
}
@@ -159,16 +170,6 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
@override
- visitPrefixedIdentifier(PrefixedIdentifier node) {
- // InvocationComputer adds suggestions for prefixed elements
- // but this computer adds suggestions for the prefix itself
- SimpleIdentifier prefix = node.prefix;
- if (prefix == null || request.offset <= prefix.end) {
- visitNode(node);
- }
- }
-
- @override
visitForStatement(ForStatement node) {
var varList = node.variables;
if (varList != null) {
@@ -204,16 +205,24 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
@override
- visitCascadeExpression(CascadeExpression node) {
- Expression target = node.target;
- // This computer handles the expression
- // while InvocationComputer handles the cascade selector
- if (target != null && request.offset <= target.end) {
+ visitPrefixedIdentifier(PrefixedIdentifier node) {
+ // InvocationComputer adds suggestions for prefixed elements
+ // but this computer adds suggestions for the prefix itself
+ SimpleIdentifier prefix = node.prefix;
+ if (prefix == null || request.offset <= prefix.end) {
visitNode(node);
}
}
@override
+ visitTypeName(TypeName node) {
+ // If suggesting completions within a TypeName node
+ // then limit suggestions to only types
+ typesOnly = true;
+ return visitNode(node);
+ }
+
+ @override
visitVariableDeclaration(VariableDeclaration node) {
// Do not add suggestions if editing the name in a var declaration
SimpleIdentifier name = node.name;
@@ -238,6 +247,9 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
void _addFieldSuggestions(ClassDeclaration node, FieldDeclaration fieldDecl) {
+ if (typesOnly) {
+ return;
+ }
bool isDeprecated = _isDeprecated(fieldDecl.metadata);
fieldDecl.fields.variables.forEach((VariableDeclaration varDecl) {
CompletionSuggestion suggestion = _addSuggestion(
@@ -257,6 +269,9 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
void _addFunctionSuggestion(FunctionDeclaration declaration) {
+ if (typesOnly) {
+ return;
+ }
CompletionSuggestion suggestion = _addSuggestion(
declaration.name,
CompletionSuggestionKind.FUNCTION,
@@ -273,6 +288,9 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
void _addLocalVarSuggestion(SimpleIdentifier id, TypeName returnType) {
+ if (typesOnly) {
+ return;
+ }
CompletionSuggestion suggestion =
_addSuggestion(id, CompletionSuggestionKind.LOCAL_VARIABLE, returnType, null);
if (suggestion != null) {
@@ -286,6 +304,9 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
void _addMethodSuggestion(ClassDeclaration node, MethodDeclaration classMbr) {
+ if (typesOnly) {
+ return;
+ }
protocol.ElementKind kind;
CompletionSuggestionKind csKind;
if (classMbr.isGetter) {
@@ -309,6 +330,9 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
void _addParamListSuggestions(FormalParameterList paramList) {
+ if (typesOnly) {
+ return;
+ }
if (paramList != null) {
paramList.parameters.forEach((FormalParameter param) {
NormalFormalParameter normalParam;
@@ -330,15 +354,16 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
}
- CompletionSuggestion _addParamSuggestion(SimpleIdentifier identifier,
- TypeName type) {
+ void _addParamSuggestion(SimpleIdentifier identifier, TypeName type) {
+ if (typesOnly) {
+ return;
+ }
CompletionSuggestion suggestion =
_addSuggestion(identifier, CompletionSuggestionKind.PARAMETER, type, null);
if (suggestion != null) {
suggestion.element =
_createElement(protocol.ElementKind.PARAMETER, identifier, type, false, false);
}
- return suggestion;
}
CompletionSuggestion _addSuggestion(SimpleIdentifier id,
@@ -380,6 +405,9 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
void _addTopLevelVarSuggestions(VariableDeclarationList varList) {
+ if (typesOnly) {
+ return;
+ }
if (varList != null) {
bool isDeprecated = _isDeprecated(varList.metadata);
varList.variables.forEach((VariableDeclaration varDecl) {

Powered by Google App Engine
This is Rietveld 408576698