| 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 | 21 |
| 22 /** | 22 /** |
| 23 * The `DartCompletionCache` contains cached information from a prior code | 23 * The `DartCompletionCache` contains cached information from a prior code |
| 24 * completion operation. | 24 * completion operation. |
| 25 */ | 25 */ |
| 26 class DartCompletionCache extends CompletionCache { | 26 class DartCompletionCache extends CompletionCache { |
| 27 | |
| 28 /** | 27 /** |
| 29 * A hash of the import directives | 28 * A hash of the import directives |
| 30 * or `null` if nothing has been cached. | 29 * or `null` if nothing has been cached. |
| 31 */ | 30 */ |
| 32 String _importKey; | 31 String _importKey; |
| 33 | 32 |
| 34 /** | 33 /** |
| 35 * Library prefix suggestions based upon imports, | 34 * Library prefix suggestions based upon imports, |
| 36 * or `null` if nothing has been cached. | 35 * or `null` if nothing has been cached. |
| 37 */ | 36 */ |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (libSource != source) { | 254 if (libSource != source) { |
| 256 libUnit.element.accept(new _NonLocalElementCacheVisitor(this)); | 255 libUnit.element.accept(new _NonLocalElementCacheVisitor(this)); |
| 257 } | 256 } |
| 258 } | 257 } |
| 259 } | 258 } |
| 260 | 259 |
| 261 void _addLibraryPrefixSuggestion(ImportElement importElem) { | 260 void _addLibraryPrefixSuggestion(ImportElement importElem) { |
| 262 CompletionSuggestion suggestion = null; | 261 CompletionSuggestion suggestion = null; |
| 263 String completion = importElem.prefix.displayName; | 262 String completion = importElem.prefix.displayName; |
| 264 if (completion != null && completion.length > 0) { | 263 if (completion != null && completion.length > 0) { |
| 265 suggestion = new CompletionSuggestion(CompletionSuggestionKind.INVOCATION, | 264 suggestion = new CompletionSuggestion( |
| 266 DART_RELEVANCE_DEFAULT, completion, completion.length, 0, | 265 CompletionSuggestionKind.INVOCATION, |
| 267 importElem.isDeprecated, false); | 266 DART_RELEVANCE_DEFAULT, |
| 267 completion, |
| 268 completion.length, |
| 269 0, |
| 270 importElem.isDeprecated, |
| 271 false); |
| 268 LibraryElement lib = importElem.importedLibrary; | 272 LibraryElement lib = importElem.importedLibrary; |
| 269 if (lib != null) { | 273 if (lib != null) { |
| 270 suggestion.element = newElement_fromEngine(lib); | 274 suggestion.element = newElement_fromEngine(lib); |
| 271 } | 275 } |
| 272 libraryPrefixSuggestions.add(suggestion); | 276 libraryPrefixSuggestions.add(suggestion); |
| 273 _importedCompletions.add(suggestion.completion); | 277 _importedCompletions.add(suggestion.completion); |
| 274 } | 278 } |
| 275 } | 279 } |
| 276 | 280 |
| 277 /** | 281 /** |
| 278 * Add suggestions for all top level elements in the context | 282 * Add suggestions for all top level elements in the context |
| 279 * excluding those elemnents for which suggestions have already been added. | 283 * excluding those elemnents for which suggestions have already been added. |
| 280 */ | 284 */ |
| 281 void _addNonImportedElementSuggestions( | 285 void _addNonImportedElementSuggestions( |
| 282 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { | 286 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { |
| 283 | |
| 284 // Exclude internal Dart SDK libraries | 287 // Exclude internal Dart SDK libraries |
| 285 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) { | 288 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) { |
| 286 if (lib.isInternal) { | 289 if (lib.isInternal) { |
| 287 Source libUri = context.sourceFactory.forUri(lib.shortName); | 290 Source libUri = context.sourceFactory.forUri(lib.shortName); |
| 288 if (libUri != null) { | 291 if (libUri != null) { |
| 289 LibraryElement libElem = context.getLibraryElement(libUri); | 292 LibraryElement libElem = context.getLibraryElement(libUri); |
| 290 if (libElem != null) { | 293 if (libElem != null) { |
| 291 excludedLibs.add(libElem); | 294 excludedLibs.add(libElem); |
| 292 } | 295 } |
| 293 } | 296 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 @override | 413 @override |
| 411 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { | 414 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { |
| 412 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | 415 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); |
| 413 } | 416 } |
| 414 | 417 |
| 415 @override | 418 @override |
| 416 void visitTopLevelVariableElement(TopLevelVariableElement element) { | 419 void visitTopLevelVariableElement(TopLevelVariableElement element) { |
| 417 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | 420 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); |
| 418 } | 421 } |
| 419 } | 422 } |
| OLD | NEW |