Chromium Code Reviews| 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.dart.cache; | 5 library services.completion.dart.cache; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol_server.dart' | 10 import 'package:analysis_server/src/protocol_server.dart' |
| 11 hide Element, ElementKind; | 11 hide Element, ElementKind; |
| 12 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; | 12 import 'package:analysis_server/src/services/completion/completion_manager.dart' ; |
| 13 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; | 13 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; |
| 14 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' ; | 14 import 'package:analysis_server/src/services/completion/suggestion_builder.dart' ; |
| 15 import 'package:analysis_server/src/services/search/search_engine.dart'; | 15 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 16 import 'package:analyzer/src/generated/ast.dart'; | 16 import 'package:analyzer/src/generated/ast.dart'; |
| 17 import 'package:analyzer/src/generated/element.dart'; | 17 import 'package:analyzer/src/generated/element.dart'; |
| 18 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
| 19 import 'package:analyzer/src/generated/resolver.dart'; | 19 import 'package:analyzer/src/generated/resolver.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 21 import 'package:analyzer/src/generated/sdk.dart'; | |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * The `DartCompletionCache` contains cached information from a prior code | 24 * The `DartCompletionCache` contains cached information from a prior code |
| 24 * completion operation. | 25 * completion operation. |
| 25 */ | 26 */ |
| 26 class DartCompletionCache extends CompletionCache { | 27 class DartCompletionCache extends CompletionCache { |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * A hash of the import directives | 30 * A hash of the import directives |
| 30 * or `null` if nothing has been cached. | 31 * or `null` if nothing has been cached. |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 _importedCompletions.add(suggestion.completion); | 271 _importedCompletions.add(suggestion.completion); |
| 271 } | 272 } |
| 272 } | 273 } |
| 273 | 274 |
| 274 /** | 275 /** |
| 275 * Add suggestions for all top level elements in the context | 276 * Add suggestions for all top level elements in the context |
| 276 * excluding those elemnents for which suggestions have already been added. | 277 * excluding those elemnents for which suggestions have already been added. |
| 277 */ | 278 */ |
| 278 void _addNonImportedElementSuggestions( | 279 void _addNonImportedElementSuggestions( |
| 279 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { | 280 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { |
| 281 | |
| 282 // Exclude internal Dart SDK libraries | |
| 283 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) { | |
|
Paul Berry
2015/04/07 01:40:27
Please replace "var" with "SdkLibrary". I had to
| |
| 284 if (lib.isInternal) { | |
| 285 Source libUri = context.sourceFactory.forUri(lib.shortName); | |
| 286 if (libUri != null) { | |
| 287 LibraryElement libElem = context.getLibraryElement(libUri); | |
| 288 if (libElem != null) { | |
| 289 excludedLibs.add(libElem); | |
| 290 } | |
| 291 } | |
| 292 } | |
| 293 } | |
| 294 | |
| 280 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; | 295 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; |
| 281 matches.forEach((SearchMatch match) { | 296 matches.forEach((SearchMatch match) { |
| 282 if (match.kind == MatchKind.DECLARATION) { | 297 if (match.kind == MatchKind.DECLARATION) { |
| 283 Element element = match.element; | 298 Element element = match.element; |
| 284 if ((element.context == context || element.context == sdkContext) && | 299 if ((element.context == context || element.context == sdkContext) && |
| 285 element.isPublic && | 300 element.isPublic && |
| 286 !excludedLibs.contains(element.library) && | 301 !excludedLibs.contains(element.library) && |
| 287 !_importedCompletions.contains(element.displayName)) { | 302 !_importedCompletions.contains(element.displayName)) { |
| 288 _addSuggestion(element, DART_RELEVANCE_LOW); | 303 _addSuggestion(element, DART_RELEVANCE_LOW); |
| 289 } | 304 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 @override | 399 @override |
| 385 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { | 400 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { |
| 386 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | 401 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); |
| 387 } | 402 } |
| 388 | 403 |
| 389 @override | 404 @override |
| 390 void visitTopLevelVariableElement(TopLevelVariableElement element) { | 405 void visitTopLevelVariableElement(TopLevelVariableElement element) { |
| 391 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | 406 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); |
| 392 } | 407 } |
| 393 } | 408 } |
| OLD | NEW |