| 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' |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 }); | 233 }); |
| 234 } else { | 234 } else { |
| 235 // Exclude elements from prefixed imports | 235 // Exclude elements from prefixed imports |
| 236 // because they are provided by PrefixedElementContributor | 236 // because they are provided by PrefixedElementContributor |
| 237 // Suggested by LibraryPrefixContributor | 237 // Suggested by LibraryPrefixContributor |
| 238 // _addLibraryPrefixSuggestion(importElem); | 238 // _addLibraryPrefixSuggestion(importElem); |
| 239 // excludedLibs.add(importElem.importedLibrary); | 239 // excludedLibs.add(importElem.importedLibrary); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 } else if (directive is PartDirective) { | 242 } else if (directive is PartDirective) { |
| 243 CompilationUnitElement partElem = directive.element; | 243 // Suggested by LocalLibraryContributor |
| 244 if (partElem != null && partElem.source != source) { | 244 // CompilationUnitElement partElem = directive.element; |
| 245 partElem.accept(new _NonLocalElementCacheVisitor(this)); | 245 // if (partElem != null && partElem.source != source) { |
| 246 } | 246 // partElem.accept(new _NonLocalElementCacheVisitor(this)); |
| 247 // } |
| 247 } | 248 } |
| 248 }); | 249 }); |
| 249 if (libSource != source) { | 250 if (libSource != source) { |
| 250 libUnit.element.accept(new _NonLocalElementCacheVisitor(this)); | 251 // Suggested by LocalLibraryContributor |
| 252 // libUnit.element.accept(new _NonLocalElementCacheVisitor(this)); |
| 251 } | 253 } |
| 252 } | 254 } |
| 253 } | 255 } |
| 254 | 256 |
| 255 /** | 257 /** |
| 256 * Add suggestions for all top level elements in the context | 258 * Add suggestions for all top level elements in the context |
| 257 * excluding those elemnents for which suggestions have already been added. | 259 * excluding those elemnents for which suggestions have already been added. |
| 258 */ | 260 */ |
| 259 void _addNonImportedElementSuggestions( | 261 void _addNonImportedElementSuggestions( |
| 260 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { | 262 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 if (libSource == source) { | 348 if (libSource == source) { |
| 347 return new Future.value(unit); | 349 return new Future.value(unit); |
| 348 } | 350 } |
| 349 // If [source] is a part, then compute the library unit | 351 // If [source] is a part, then compute the library unit |
| 350 if (libSource != null) { | 352 if (libSource != null) { |
| 351 return context.computeResolvedCompilationUnitAsync(libSource, libSource); | 353 return context.computeResolvedCompilationUnitAsync(libSource, libSource); |
| 352 } | 354 } |
| 353 return new Future.value(null); | 355 return new Future.value(null); |
| 354 } | 356 } |
| 355 } | 357 } |
| 356 | |
| 357 /** | |
| 358 * A visitor for building suggestions based upon the elements defined by | |
| 359 * a source file contained in the same library but not the same as | |
| 360 * the source in which the completions are being requested. | |
| 361 */ | |
| 362 class _NonLocalElementCacheVisitor extends GeneralizingElementVisitor { | |
| 363 final DartCompletionCache cache; | |
| 364 | |
| 365 _NonLocalElementCacheVisitor(this.cache); | |
| 366 | |
| 367 @override | |
| 368 void visitClassElement(ClassElement element) { | |
| 369 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | |
| 370 } | |
| 371 | |
| 372 @override | |
| 373 void visitCompilationUnitElement(CompilationUnitElement element) { | |
| 374 element.visitChildren(this); | |
| 375 } | |
| 376 | |
| 377 @override | |
| 378 void visitElement(Element element) { | |
| 379 // ignored | |
| 380 } | |
| 381 | |
| 382 @override | |
| 383 void visitFunctionElement(FunctionElement element) { | |
| 384 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | |
| 385 } | |
| 386 | |
| 387 @override | |
| 388 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { | |
| 389 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | |
| 390 } | |
| 391 | |
| 392 @override | |
| 393 void visitTopLevelVariableElement(TopLevelVariableElement element) { | |
| 394 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); | |
| 395 } | |
| 396 } | |
| OLD | NEW |