Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart_completion_cache.dart

Issue 1517693004: extract LibraryPrefixContributor from imported reference contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 * completion operation. 24 * completion operation.
25 */ 25 */
26 class DartCompletionCache extends CompletionCache { 26 class DartCompletionCache extends CompletionCache {
27 /** 27 /**
28 * A hash of the import directives 28 * A hash of the import directives
29 * or `null` if nothing has been cached. 29 * or `null` if nothing has been cached.
30 */ 30 */
31 String _importKey; 31 String _importKey;
32 32
33 /** 33 /**
34 * Library prefix suggestions based upon imports,
35 * or `null` if nothing has been cached.
36 */
37 List<CompletionSuggestion> libraryPrefixSuggestions;
38
39 /**
40 * Type suggestions based upon imports, 34 * Type suggestions based upon imports,
41 * or `null` if nothing has been cached. 35 * or `null` if nothing has been cached.
42 */ 36 */
43 List<CompletionSuggestion> importedTypeSuggestions; 37 List<CompletionSuggestion> importedTypeSuggestions;
44 38
45 /** 39 /**
46 * Suggestions for methods and functions that have void return type, 40 * Suggestions for methods and functions that have void return type,
47 * or `null` if nothing has been cached. 41 * or `null` if nothing has been cached.
48 */ 42 */
49 List<CompletionSuggestion> importedVoidReturnSuggestions; 43 List<CompletionSuggestion> importedVoidReturnSuggestions;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 * If [shouldWaitForLowPrioritySuggestions] is `true` then the returned 101 * If [shouldWaitForLowPrioritySuggestions] is `true` then the returned
108 * future will complete when the cache is fully populated. If `false`, 102 * future will complete when the cache is fully populated. If `false`,
109 * the returned future will complete sooner, but the cache will not include 103 * the returned future will complete sooner, but the cache will not include
110 * the lower priority suggestions added as a result of a global search. 104 * the lower priority suggestions added as a result of a global search.
111 * In this case, those lower priority suggestions will be added later 105 * In this case, those lower priority suggestions will be added later
112 * when the index has been updated and the global search completes. 106 * when the index has been updated and the global search completes.
113 */ 107 */
114 Future<bool> computeImportInfo(CompilationUnit unit, 108 Future<bool> computeImportInfo(CompilationUnit unit,
115 SearchEngine searchEngine, bool shouldWaitForLowPrioritySuggestions) { 109 SearchEngine searchEngine, bool shouldWaitForLowPrioritySuggestions) {
116 importedTypeSuggestions = <CompletionSuggestion>[]; 110 importedTypeSuggestions = <CompletionSuggestion>[];
117 libraryPrefixSuggestions = <CompletionSuggestion>[];
118 otherImportedSuggestions = <CompletionSuggestion>[]; 111 otherImportedSuggestions = <CompletionSuggestion>[];
119 importedConstructorSuggestions = <CompletionSuggestion>[]; 112 importedConstructorSuggestions = <CompletionSuggestion>[];
120 importedVoidReturnSuggestions = <CompletionSuggestion>[]; 113 importedVoidReturnSuggestions = <CompletionSuggestion>[];
121 importedClassMap = new Map<String, ClassElement>(); 114 importedClassMap = new Map<String, ClassElement>();
122 _importedCompletions = new HashSet<String>(); 115 _importedCompletions = new HashSet<String>();
123 116
124 // Assert that the compilation unit is resolved 117 // Assert that the compilation unit is resolved
125 // and represents the expected source 118 // and represents the expected source
126 assert(unit.element.source == source); 119 assert(unit.element.source == source);
127 120
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // Include top level elements 226 // Include top level elements
234 importNamespace.definedNames.forEach((String name, Element elem) { 227 importNamespace.definedNames.forEach((String name, Element elem) {
235 if (elem is ClassElement) { 228 if (elem is ClassElement) {
236 importedClassMap[name] = elem; 229 importedClassMap[name] = elem;
237 } 230 }
238 _addSuggestion(elem, DART_RELEVANCE_DEFAULT); 231 _addSuggestion(elem, DART_RELEVANCE_DEFAULT);
239 }); 232 });
240 } else { 233 } else {
241 // Exclude elements from prefixed imports 234 // Exclude elements from prefixed imports
242 // because they are provided by PrefixedElementContributor 235 // because they are provided by PrefixedElementContributor
243 _addLibraryPrefixSuggestion(importElem); 236 // Suggested by LibraryPrefixContributor
244 excludedLibs.add(importElem.importedLibrary); 237 // _addLibraryPrefixSuggestion(importElem);
238 // excludedLibs.add(importElem.importedLibrary);
245 } 239 }
246 } 240 }
247 } else if (directive is PartDirective) { 241 } else if (directive is PartDirective) {
248 CompilationUnitElement partElem = directive.element; 242 CompilationUnitElement partElem = directive.element;
249 if (partElem != null && partElem.source != source) { 243 if (partElem != null && partElem.source != source) {
250 partElem.accept(new _NonLocalElementCacheVisitor(this)); 244 partElem.accept(new _NonLocalElementCacheVisitor(this));
251 } 245 }
252 } 246 }
253 }); 247 });
254 if (libSource != source) { 248 if (libSource != source) {
255 libUnit.element.accept(new _NonLocalElementCacheVisitor(this)); 249 libUnit.element.accept(new _NonLocalElementCacheVisitor(this));
256 } 250 }
257 } 251 }
258 } 252 }
259 253
260 void _addLibraryPrefixSuggestion(ImportElement importElem) {
261 CompletionSuggestion suggestion = null;
262 String completion = importElem.prefix.displayName;
263 if (completion != null && completion.length > 0) {
264 suggestion = new CompletionSuggestion(
265 CompletionSuggestionKind.INVOCATION,
266 DART_RELEVANCE_DEFAULT,
267 completion,
268 completion.length,
269 0,
270 importElem.isDeprecated,
271 false);
272 LibraryElement lib = importElem.importedLibrary;
273 if (lib != null) {
274 suggestion.element = convertElement(lib);
275 }
276 libraryPrefixSuggestions.add(suggestion);
277 _importedCompletions.add(suggestion.completion);
278 }
279 }
280
281 /** 254 /**
282 * Add suggestions for all top level elements in the context 255 * Add suggestions for all top level elements in the context
283 * excluding those elemnents for which suggestions have already been added. 256 * excluding those elemnents for which suggestions have already been added.
284 */ 257 */
285 void _addNonImportedElementSuggestions( 258 void _addNonImportedElementSuggestions(
286 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) { 259 List<SearchMatch> matches, Set<LibraryElement> excludedLibs) {
287 // Exclude internal Dart SDK libraries 260 // Exclude internal Dart SDK libraries
288 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) { 261 for (var lib in context.sourceFactory.dartSdk.sdkLibraries) {
289 if (lib.isInternal) { 262 if (lib.isInternal) {
290 Source libUri = context.sourceFactory.forUri(lib.shortName); 263 Source libUri = context.sourceFactory.forUri(lib.shortName);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 @override 386 @override
414 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) { 387 void visitFunctionTypeAliasElement(FunctionTypeAliasElement element) {
415 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); 388 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT);
416 } 389 }
417 390
418 @override 391 @override
419 void visitTopLevelVariableElement(TopLevelVariableElement element) { 392 void visitTopLevelVariableElement(TopLevelVariableElement element) {
420 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT); 393 cache._addSuggestion(element, DART_RELEVANCE_DEFAULT);
421 } 394 }
422 } 395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698