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

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

Issue 658053002: filter void methods when suggesting expression (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 fd0a63baef7755ba913701a1668cb02cce81bd86..8d9d2d23aaf0a4d58ef4ca8740c85af8b4146a6d 100644
--- a/pkg/analysis_server/lib/src/services/completion/local_computer.dart
+++ b/pkg/analysis_server/lib/src/services/completion/local_computer.dart
@@ -59,8 +59,11 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
final DartCompletionRequest request;
bool typesOnly = false;
+ bool excludeVoidReturn;
- _LocalVisitor(this.request);
+ _LocalVisitor(this.request) {
+ excludeVoidReturn = _computeExcludeVoidReturn(request.node);
+ }
@override
visitBlock(Block node) {
@@ -312,6 +315,9 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
if (typesOnly) {
return;
}
+ if (excludeVoidReturn && _isVoid(declaration.returnType)) {
+ return;
+ }
CompletionSuggestion suggestion = _addSuggestion(
declaration.name,
CompletionSuggestionKind.FUNCTION,
@@ -353,9 +359,15 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
kind = protocol.ElementKind.GETTER;
csKind = CompletionSuggestionKind.GETTER;
} else if (classMbr.isSetter) {
+ if (excludeVoidReturn) {
+ return;
+ }
kind = protocol.ElementKind.SETTER;
csKind = CompletionSuggestionKind.SETTER;
} else {
+ if (excludeVoidReturn && _isVoid(classMbr.returnType)) {
+ return;
+ }
kind = protocol.ElementKind.METHOD;
csKind = CompletionSuggestionKind.METHOD;
}
@@ -468,6 +480,16 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
}
}
+ bool _computeExcludeVoidReturn(AstNode node) {
+ if (node is Block) {
+ return false;
+ } else if (node is SimpleIdentifier) {
+ return node.parent is ExpressionStatement ? false : true;
+ } else {
+ return true;
+ }
+ }
+
/**
* Create a new protocol Element for inclusion in a completion suggestion.
*/
@@ -493,6 +515,16 @@ class _LocalVisitor extends GeneralizingAstVisitor<dynamic> {
metadata.any(
(Annotation a) => a.name is SimpleIdentifier && a.name.name == 'deprecated');
+ bool _isVoid(TypeName returnType) {
+ if (returnType != null) {
+ Identifier id = returnType.name;
+ if (id != null && id.name == 'void') {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Return the name for the given type.
*/

Powered by Google App Engine
This is Rietveld 408576698