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

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

Issue 1693933002: rework completion request resolve imports (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: sort methods Created 4 years, 10 months 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.manager; 5 library services.completion.dart.manager;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:analysis_server/src/provisional/completion/completion_core.dart' 10 import 'package:analysis_server/src/provisional/completion/completion_core.dart'
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 * The [LibraryElement] representing dart:core 133 * The [LibraryElement] representing dart:core
134 */ 134 */
135 LibraryElement _coreLib; 135 LibraryElement _coreLib;
136 136
137 /** 137 /**
138 * The [DartType] for Object in dart:core 138 * The [DartType] for Object in dart:core
139 */ 139 */
140 InterfaceType _objectType; 140 InterfaceType _objectType;
141 141
142 /** 142 /**
143 * A list of resolved [ImportElement]s for the imported libraries
144 * or `null` if not computed.
145 */
146 List<ImportElement> _resolvedImports;
147
148 /**
143 * The resolved [CompilationUnitElement]s comprising the library 149 * The resolved [CompilationUnitElement]s comprising the library
144 * or `null` if not computed. 150 * or `null` if not computed.
145 */ 151 */
146 List<CompilationUnitElement> _resolvedUnits; 152 List<CompilationUnitElement> _resolvedUnits;
147 153
148 OpType _opType; 154 OpType _opType;
149 155
150 final CompletionRequest _originalRequest; 156 final CompletionRequest _originalRequest;
151 157
152 final CompletionPerformance performance; 158 final CompletionPerformance performance;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return _opType; 217 return _opType;
212 } 218 }
213 219
214 /** 220 /**
215 * Throw [AbortCompletion] if the completion request has been aborted. 221 * Throw [AbortCompletion] if the completion request has been aborted.
216 */ 222 */
217 void checkAborted() { 223 void checkAborted() {
218 _originalRequest.checkAborted(); 224 _originalRequest.checkAborted();
219 } 225 }
220 226
221 // For internal use only
222 @override
223 Future<List<Directive>> resolveDirectives() async {
224 checkAborted();
225
226 CompilationUnit libUnit;
227 if (librarySource != null) {
228 // TODO(danrubel) only resolve the directives
229 libUnit = await _computeAsync(
230 this,
231 new LibrarySpecificUnit(librarySource, librarySource),
232 RESOLVED_UNIT3,
233 performance,
234 'resolve directives');
235 }
236 return libUnit?.directives;
237 }
238
239 @override 227 @override
240 Future resolveExpression(Expression expression) async { 228 Future resolveExpression(Expression expression) async {
241 checkAborted(); 229 checkAborted();
242 230
243 // Return immediately if the expression has already been resolved 231 // Return immediately if the expression has already been resolved
244 if (expression.propagatedType != null) { 232 if (expression.propagatedType != null) {
245 return; 233 return;
246 } 234 }
247 235
248 // Gracefully degrade if librarySource cannot be determined 236 // Gracefully degrade if librarySource cannot be determined
(...skipping 18 matching lines...) Expand all
267 // Gracefully degrade if unit cannot be resolved 255 // Gracefully degrade if unit cannot be resolved
268 if (resolvedUnit == null) { 256 if (resolvedUnit == null) {
269 return; 257 return;
270 } 258 }
271 259
272 // Recompute the target for the newly resolved unit 260 // Recompute the target for the newly resolved unit
273 _updateTargets(resolvedUnit); 261 _updateTargets(resolvedUnit);
274 } 262 }
275 263
276 @override 264 @override
265 Future<List<ImportElement>> resolveImports() async {
266 checkAborted();
267 if (_resolvedImports != null) {
268 return _resolvedImports;
269 }
270 LibraryElement libElem = libraryElement;
271 if (libElem == null) {
272 return null;
273 }
274 _resolvedImports = <ImportElement>[];
275 for (ImportElement importElem in libElem.imports) {
276 if (importElem.importedLibrary.exportNamespace == null) {
277 await _computeAsync(this, importElem.importedLibrary.source,
278 LIBRARY_ELEMENT4, performance, 'resolve imported library');
279 checkAborted();
280 }
281 _resolvedImports.add(importElem);
282 }
283 return _resolvedImports;
284 }
285
286 @override
277 Future<List<CompilationUnitElement>> resolveUnits() async { 287 Future<List<CompilationUnitElement>> resolveUnits() async {
278 checkAborted(); 288 checkAborted();
279 if (_resolvedUnits != null) { 289 if (_resolvedUnits != null) {
280 return _resolvedUnits; 290 return _resolvedUnits;
281 } 291 }
282 LibraryElement libElem = libraryElement; 292 LibraryElement libElem = libraryElement;
283 if (libElem == null) { 293 if (libElem == null) {
284 return null; 294 return null;
285 } 295 }
286 _resolvedUnits = <CompilationUnitElement>[]; 296 _resolvedUnits = <CompilationUnitElement>[];
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 dotTarget = node.prefix; 337 dotTarget = node.prefix;
328 } 338 }
329 } 339 }
330 } 340 }
331 341
332 /** 342 /**
333 * Return a [Future] that completes with a newly created completion request 343 * Return a [Future] that completes with a newly created completion request
334 * based on the given [request]. This method will throw [AbortCompletion] 344 * based on the given [request]. This method will throw [AbortCompletion]
335 * if the completion request has been aborted. 345 * if the completion request has been aborted.
336 */ 346 */
337 static Future<DartCompletionRequest> from(CompletionRequest request) async { 347 static Future<DartCompletionRequest> from(CompletionRequest request,
348 {ResultDescriptor resultDescriptor}) async {
338 request.checkAborted(); 349 request.checkAborted();
339 CompletionPerformance performance = 350 CompletionPerformance performance =
340 (request as CompletionRequestImpl).performance; 351 (request as CompletionRequestImpl).performance;
341 const BUILD_REQUEST_TAG = 'build DartCompletionRequest'; 352 const BUILD_REQUEST_TAG = 'build DartCompletionRequest';
342 performance.logStartTime(BUILD_REQUEST_TAG); 353 performance.logStartTime(BUILD_REQUEST_TAG);
343 354
344 Source source = request.source; 355 Source source = request.source;
345 AnalysisContext context = request.context; 356 AnalysisContext context = request.context;
346 357
347 const PARSE_TAG = 'parse unit'; 358 const PARSE_TAG = 'parse unit';
348 performance.logStartTime(PARSE_TAG); 359 performance.logStartTime(PARSE_TAG);
349 CompilationUnit unit = request.context.computeResult(source, PARSED_UNIT); 360 CompilationUnit unit = request.context.computeResult(source, PARSED_UNIT);
350 performance.logElapseTime(PARSE_TAG); 361 performance.logElapseTime(PARSE_TAG);
351 362
352 Source libSource; 363 Source libSource;
353 if (unit.directives.any((d) => d is PartOfDirective)) { 364 if (unit.directives.any((d) => d is PartOfDirective)) {
354 List<Source> libraries = context.getLibrariesContaining(source); 365 List<Source> libraries = context.getLibrariesContaining(source);
355 if (libraries.isNotEmpty) { 366 if (libraries.isNotEmpty) {
356 libSource = libraries[0]; 367 libSource = libraries[0];
357 } 368 }
358 } else { 369 } else {
359 libSource = source; 370 libSource = source;
360 } 371 }
361 372
362 // Most (all?) contributors need declarations in scope to be resolved 373 // Most (all?) contributors need declarations in scope to be resolved
363 if (libSource != null) { 374 if (libSource != null) {
364 unit = await _computeAsync( 375 unit = await _computeAsync(
365 request, 376 request,
366 new LibrarySpecificUnit(libSource, source), 377 new LibrarySpecificUnit(libSource, source),
367 RESOLVED_UNIT3, 378 resultDescriptor ?? RESOLVED_UNIT3,
368 performance, 379 performance,
369 'resolve declarations'); 380 'resolve declarations');
370 } 381 }
371 382
372 DartCompletionRequestImpl dartRequest = new DartCompletionRequestImpl._( 383 DartCompletionRequestImpl dartRequest = new DartCompletionRequestImpl._(
373 request.context, 384 request.context,
374 request.resourceProvider, 385 request.resourceProvider,
375 request.searchEngine, 386 request.searchEngine,
376 libSource, 387 libSource,
377 request.source, 388 request.source,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // Replacement range for import URI 483 // Replacement range for import URI
473 return new ReplacementRange(start, end - start); 484 return new ReplacementRange(start, end - start);
474 } 485 }
475 } 486 }
476 } 487 }
477 } 488 }
478 } 489 }
479 return new ReplacementRange(requestOffset, 0); 490 return new ReplacementRange(requestOffset, 0);
480 } 491 }
481 } 492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698