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

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

Issue 1692273003: rework LocalLibraryContributor to resolve referenced units (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 /** 132 /**
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 /**
143 * The resolved [CompilationUnitElement]s comprising the library
144 * or `null` if not computed.
145 */
146 List<CompilationUnitElement> _resolvedUnits;
147
142 OpType _opType; 148 OpType _opType;
143 149
144 final CompletionRequest _originalRequest; 150 final CompletionRequest _originalRequest;
145 151
146 final CompletionPerformance performance; 152 final CompletionPerformance performance;
147 153
148 DartCompletionRequestImpl._( 154 DartCompletionRequestImpl._(
149 this.context, 155 this.context,
150 this.resourceProvider, 156 this.resourceProvider,
151 this.searchEngine, 157 this.searchEngine,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 266
261 // Gracefully degrade if unit cannot be resolved 267 // Gracefully degrade if unit cannot be resolved
262 if (resolvedUnit == null) { 268 if (resolvedUnit == null) {
263 return; 269 return;
264 } 270 }
265 271
266 // Recompute the target for the newly resolved unit 272 // Recompute the target for the newly resolved unit
267 _updateTargets(resolvedUnit); 273 _updateTargets(resolvedUnit);
268 } 274 }
269 275
276 @override
277 Future<List<CompilationUnitElement>> resolveUnits() async {
278 checkAborted();
279 if (_resolvedUnits != null) {
280 return _resolvedUnits;
281 }
282 LibraryElement libElem = libraryElement;
283 if (libElem == null) {
284 return null;
285 }
286 _resolvedUnits = <CompilationUnitElement>[];
287 for (CompilationUnitElement unresolvedUnit in libElem.units) {
288 CompilationUnit unit = await _computeAsync(
289 this,
290 new LibrarySpecificUnit(libElem.source, unresolvedUnit.source),
291 RESOLVED_UNIT3,
292 performance,
293 'resolve library unit');
294 checkAborted();
295 CompilationUnitElement resolvedUnit = unit?.element;
296 if (resolvedUnit != null) {
297 _resolvedUnits.add(resolvedUnit);
298 }
299 }
300 return _resolvedUnits;
301 }
302
270 /** 303 /**
271 * Update the completion [target] and [dotTarget] based on the given [unit]. 304 * Update the completion [target] and [dotTarget] based on the given [unit].
272 */ 305 */
273 void _updateTargets(CompilationUnit unit) { 306 void _updateTargets(CompilationUnit unit) {
274 _opType = null; 307 _opType = null;
275 dotTarget = null; 308 dotTarget = null;
276 target = new CompletionTarget.forOffset(unit, offset); 309 target = new CompletionTarget.forOffset(unit, offset);
277 AstNode node = target.containingNode; 310 AstNode node = target.containingNode;
278 if (node is MethodInvocation) { 311 if (node is MethodInvocation) {
279 if (identical(node.methodName, target.entity)) { 312 if (identical(node.methodName, target.entity)) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 await dartRequest.resolveExpression(node); 391 await dartRequest.resolveExpression(node);
359 performance.logElapseTime(FUNCTIONAL_ARG_TAG); 392 performance.logElapseTime(FUNCTIONAL_ARG_TAG);
360 dartRequest.checkAborted(); 393 dartRequest.checkAborted();
361 } 394 }
362 } 395 }
363 396
364 performance.logElapseTime(BUILD_REQUEST_TAG); 397 performance.logElapseTime(BUILD_REQUEST_TAG);
365 return dartRequest; 398 return dartRequest;
366 } 399 }
367 400
368 static Future _computeAsync(CompletionRequest request, AnalysisTarget target, 401 static Future _computeAsync(
369 ResultDescriptor descriptor, CompletionPerformance performance, String per fTag) async { 402 CompletionRequest request,
403 AnalysisTarget target,
404 ResultDescriptor descriptor,
405 CompletionPerformance performance,
406 String perfTag) async {
370 request.checkAborted(); 407 request.checkAborted();
371 performance.logStartTime(perfTag); 408 performance.logStartTime(perfTag);
372 var result; 409 var result;
373 try { 410 try {
374 result = 411 result =
375 await new AnalysisFutureHelper(request.context, target, descriptor) 412 await new AnalysisFutureHelper(request.context, target, descriptor)
376 .computeAsync(); 413 .computeAsync();
377 } catch (e, s) { 414 } catch (e, s) {
378 if (e is AnalysisNotScheduledError) { 415 if (e is AnalysisNotScheduledError) {
379 request.checkAborted(); 416 request.checkAborted();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // Replacement range for import URI 472 // Replacement range for import URI
436 return new ReplacementRange(start, end - start); 473 return new ReplacementRange(start, end - start);
437 } 474 }
438 } 475 }
439 } 476 }
440 } 477 }
441 } 478 }
442 return new ReplacementRange(requestOffset, 0); 479 return new ReplacementRange(requestOffset, 0);
443 } 480 }
444 } 481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698