| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library services.completion.computer.dart.toplevel; | 5 library services.completion.computer.dart.toplevel; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart' hide Element; | 9 import 'package:analysis_server/src/protocol.dart' hide Element; |
| 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; | 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 node.getAncestor((parent) => parent is NamespaceDirective); | 49 node.getAncestor((parent) => parent is NamespaceDirective); |
| 50 if (directive != null) { | 50 if (directive != null) { |
| 51 LibraryElement library = directive.uriElement; | 51 LibraryElement library = directive.uriElement; |
| 52 LibraryElementSuggestionBuilder.suggestionsFor(request, library); | 52 LibraryElementSuggestionBuilder.suggestionsFor(request, library); |
| 53 return new Future.value(true); | 53 return new Future.value(true); |
| 54 } | 54 } |
| 55 return new Future.value(false); | 55 return new Future.value(false); |
| 56 } | 56 } |
| 57 | 57 |
| 58 @override | 58 @override |
| 59 Future<bool> visitExpressionStatement(ExpressionStatement node) { |
| 60 Expression expression = node.expression; |
| 61 if (expression is SimpleIdentifier) { |
| 62 if (expression.end < request.offset) { |
| 63 // Don't suggest imported elements for local var name |
| 64 return new Future.value(false); |
| 65 } |
| 66 } |
| 67 return visitNode(node); |
| 68 } |
| 69 |
| 70 @override |
| 59 Future<bool> visitNode(AstNode node) { | 71 Future<bool> visitNode(AstNode node) { |
| 60 return _addImportedElements(); | 72 return _addImportedElements(); |
| 61 } | 73 } |
| 62 | 74 |
| 63 @override | 75 @override |
| 64 Future<bool> visitSimpleIdentifier(SimpleIdentifier node) { | 76 Future<bool> visitSimpleIdentifier(SimpleIdentifier node) { |
| 65 return node.parent.accept(this); | 77 return node.parent.accept(this); |
| 66 } | 78 } |
| 67 | 79 |
| 68 @override | 80 @override |
| (...skipping 26 matching lines...) Expand all Loading... |
| 95 | 107 |
| 96 // Build the set of visible and excluded libraries | 108 // Build the set of visible and excluded libraries |
| 97 // and the list of names that should be shown or hidden | 109 // and the list of names that should be shown or hidden |
| 98 request.unit.directives.forEach((Directive directive) { | 110 request.unit.directives.forEach((Directive directive) { |
| 99 if (directive is ImportDirective) { | 111 if (directive is ImportDirective) { |
| 100 LibraryElement lib = directive.element.importedLibrary; | 112 LibraryElement lib = directive.element.importedLibrary; |
| 101 if (directive.prefix == null) { | 113 if (directive.prefix == null) { |
| 102 visibleLibs.add(lib); | 114 visibleLibs.add(lib); |
| 103 directive.combinators.forEach((Combinator combinator) { | 115 directive.combinators.forEach((Combinator combinator) { |
| 104 if (combinator is ShowCombinator) { | 116 if (combinator is ShowCombinator) { |
| 105 showNames[lib] = combinator.shownNames.map( | 117 showNames[lib] = |
| 106 (SimpleIdentifier id) => id.name).toSet(); | 118 combinator.shownNames.map((SimpleIdentifier id) => id.name).
toSet(); |
| 107 } else if (combinator is HideCombinator) { | 119 } else if (combinator is HideCombinator) { |
| 108 hideNames[lib] = combinator.hiddenNames.map( | 120 hideNames[lib] = |
| 109 (SimpleIdentifier id) => id.name).toSet(); | 121 combinator.hiddenNames.map((SimpleIdentifier id) => id.name)
.toSet(); |
| 110 } | 122 } |
| 111 }); | 123 }); |
| 112 } else { | 124 } else { |
| 113 excludedLibs.add(lib); | 125 excludedLibs.add(lib); |
| 114 } | 126 } |
| 115 } | 127 } |
| 116 }); | 128 }); |
| 117 | 129 |
| 118 // Compute the set of possible classes, functions, and top level variables | 130 // Compute the set of possible classes, functions, and top level variables |
| 119 matches.forEach((SearchMatch match) { | 131 matches.forEach((SearchMatch match) { |
| 120 if (match.kind == MatchKind.DECLARATION) { | 132 if (match.kind == MatchKind.DECLARATION) { |
| 121 Element element = match.element; | 133 Element element = match.element; |
| 122 LibraryElement lib = element.library; | 134 LibraryElement lib = element.library; |
| 123 if (element.isPublic && !excludedLibs.contains(lib)) { | 135 if (element.isPublic && !excludedLibs.contains(lib)) { |
| 124 String completion = element.displayName; | 136 String completion = element.displayName; |
| 125 Set<String> show = showNames[lib]; | 137 Set<String> show = showNames[lib]; |
| 126 Set<String> hide = hideNames[lib]; | 138 Set<String> hide = hideNames[lib]; |
| 127 if ((show == null || show.contains(completion)) && | 139 if ((show == null || show.contains(completion)) && |
| 128 (hide == null || !hide.contains(completion))) { | 140 (hide == null || !hide.contains(completion))) { |
| 129 request.suggestions.add( | 141 |
| 130 new CompletionSuggestion( | 142 CompletionSuggestionKind kind = |
| 131 new CompletionSuggestionKind.fromElementKind(element.kind)
, | 143 new CompletionSuggestionKind.fromElementKind(element.kind); |
| 132 visibleLibs.contains(lib) || lib.isDartCore ? | 144 |
| 133 CompletionRelevance.DEFAULT : | 145 CompletionRelevance relevance; |
| 134 CompletionRelevance.LOW, | 146 if (visibleLibs.contains(lib) || lib.isDartCore) { |
| 135 completion, | 147 relevance = CompletionRelevance.DEFAULT; |
| 136 completion.length, | 148 } else { |
| 137 0, | 149 relevance = CompletionRelevance.LOW; |
| 138 element.isDeprecated, | 150 } |
| 139 false)); | 151 |
| 152 CompletionSuggestion suggestion = new CompletionSuggestion( |
| 153 kind, |
| 154 relevance, |
| 155 completion, |
| 156 completion.length, |
| 157 0, |
| 158 element.isDeprecated, |
| 159 false); |
| 160 |
| 161 DartType type; |
| 162 if (element is TopLevelVariableElement) { |
| 163 type = element.type; |
| 164 } else if (element is FunctionElement) { |
| 165 type = element.returnType; |
| 166 } |
| 167 if (type != null) { |
| 168 String name = type.displayName; |
| 169 if (name != null && name.length > 0 && name != 'dynamic') { |
| 170 suggestion.returnType = name; |
| 171 } |
| 172 } |
| 173 |
| 174 request.suggestions.add(suggestion); |
| 140 } | 175 } |
| 141 } | 176 } |
| 142 } | 177 } |
| 143 }); | 178 }); |
| 144 return true; | 179 return true; |
| 145 }); | 180 }); |
| 146 } | 181 } |
| 147 } | 182 } |
| 148 | |
| OLD | NEW |