| 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/task/dart.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 * A hash of the import directives | 29 * A hash of the import directives |
| 29 * or `null` if nothing has been cached. | 30 * or `null` if nothing has been cached. |
| 30 */ | 31 */ |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 * or `null` if nothing has been cached. | 80 * or `null` if nothing has been cached. |
| 80 */ | 81 */ |
| 81 String get importKey => _importKey; | 82 String get importKey => _importKey; |
| 82 | 83 |
| 83 /** | 84 /** |
| 84 * Return the [ClassElement] for Object. | 85 * Return the [ClassElement] for Object. |
| 85 */ | 86 */ |
| 86 ClassElement get objectClassElement { | 87 ClassElement get objectClassElement { |
| 87 if (_objectClassElement == null) { | 88 if (_objectClassElement == null) { |
| 88 Source coreUri = context.sourceFactory.forUri('dart:core'); | 89 Source coreUri = context.sourceFactory.forUri('dart:core'); |
| 89 LibraryElement coreLib = context.getLibraryElement(coreUri); | 90 LibraryElement coreLib = context.getResult(coreUri, LIBRARY_ELEMENT8); |
| 90 _objectClassElement = coreLib.getType('Object'); | 91 _objectClassElement = coreLib.getType('Object'); |
| 91 } | 92 } |
| 92 return _objectClassElement; | 93 return _objectClassElement; |
| 93 } | 94 } |
| 94 | 95 |
| 95 /** | 96 /** |
| 96 * Given a resolved compilation unit, compute suggestions based upon the | 97 * Given a resolved compilation unit, compute suggestions based upon the |
| 97 * imports and other dart files (e.g. "part" files) in the library containing | 98 * imports and other dart files (e.g. "part" files) in the library containing |
| 98 * the given compilation unit. The returned future completes when the cache | 99 * the given compilation unit. The returned future completes when the cache |
| 99 * is populated. | 100 * is populated. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 } | 188 } |
| 188 } | 189 } |
| 189 | 190 |
| 190 /** | 191 /** |
| 191 * Add suggestions for implicitly imported elements in dart:core. | 192 * Add suggestions for implicitly imported elements in dart:core. |
| 192 */ | 193 */ |
| 193 void _addDartCoreSuggestions() { | 194 void _addDartCoreSuggestions() { |
| 194 Source coreUri = context.sourceFactory.forUri('dart:core'); | 195 Source coreUri = context.sourceFactory.forUri('dart:core'); |
| 195 LibraryElement coreLib = context.getLibraryElement(coreUri); | 196 LibraryElement coreLib = context.getResult(coreUri, LIBRARY_ELEMENT8); |
| 196 if (coreLib == null) { | 197 if (coreLib == null) { |
| 197 // If the core library has not been analyzed yet, then we cannot add any | 198 // If the core library has not been analyzed yet, then we cannot add any |
| 198 // suggestions from it. | 199 // suggestions from it. |
| 199 return; | 200 return; |
| 200 } | 201 } |
| 201 Namespace coreNamespace = | 202 Namespace coreNamespace = |
| 202 new NamespaceBuilder().createPublicNamespaceForLibrary(coreLib); | 203 new NamespaceBuilder().createPublicNamespaceForLibrary(coreLib); |
| 203 coreNamespace.definedNames.forEach((String name, Element elem) { | 204 coreNamespace.definedNames.forEach((String name, Element elem) { |
| 204 if (elem is ClassElement) { | 205 if (elem is ClassElement) { |
| 205 importedClassMap[name] = elem; | 206 importedClassMap[name] = elem; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 * Add suggestions for all top level elements in the context | 256 * Add suggestions for all top level elements in the context |
| 256 * excluding those elemnents for which suggestions have already been added. | 257 * excluding those elemnents for which suggestions have already been added. |
| 257 */ | 258 */ |
| 258 void _addNonImportedElementSuggestions( | 259 void _addNonImportedElementSuggestions( |
| 259 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { | 260 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { |
| 260 // Exclude internal Dart SDK libraries | 261 // Exclude internal Dart SDK libraries |
| 261 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) { | 262 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) { |
| 262 if (lib.isInternal) { | 263 if (lib.isInternal) { |
| 263 Source libUri = context.sourceFactory.forUri(lib.shortName); | 264 Source libUri = context.sourceFactory.forUri(lib.shortName); |
| 264 if (libUri != null) { | 265 if (libUri != null) { |
| 265 LibraryElement libElem = context.getLibraryElement(libUri); | 266 LibraryElement libElem = context.getResult(libUri, LIBRARY_ELEMENT8); |
| 266 if (libElem != null) { | 267 if (libElem != null) { |
| 267 excludedLibs.add(libElem); | 268 excludedLibs.add(libElem); |
| 268 } | 269 } |
| 269 } | 270 } |
| 270 } | 271 } |
| 271 } | 272 } |
| 272 | 273 |
| 273 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; | 274 AnalysisContext sdkContext = context.sourceFactory.dartSdk.context; |
| 274 matches.forEach((SearchMatch match) { | 275 matches.forEach((SearchMatch match) { |
| 275 if (match.kind == MatchKind.DECLARATION) { | 276 if (match.kind == MatchKind.DECLARATION) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 @override | 387 @override |
| 387 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { | 388 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { |
| 388 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | 389 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); |
| 389 } | 390 } |
| 390 | 391 |
| 391 @override | 392 @override |
| 392 void visitTopLevelVariableElement(TopLevelVariableElement element) { | 393 void visitTopLevelVariableElement(TopLevelVariableElement element) { |
| 393 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | 394 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); |
| 394 } | 395 } |
| 395 } | 396 } |
| OLD | NEW |