OLD | NEW |
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' |
11 show CompletionContributor, CompletionRequest; | 11 show CompletionContributor, CompletionRequest; |
12 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; | 12 import 'package:analysis_server/src/provisional/completion/dart/completion_dart.
dart'; |
13 import 'package:analysis_server/src/provisional/completion/dart/completion_plugi
n.dart'; | 13 import 'package:analysis_server/src/provisional/completion/dart/completion_plugi
n.dart'; |
14 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; | 14 import 'package:analysis_server/src/provisional/completion/dart/completion_targe
t.dart'; |
15 import 'package:analysis_server/src/services/completion/completion_core.dart'; | 15 import 'package:analysis_server/src/services/completion/completion_core.dart'; |
16 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; | 16 import 'package:analysis_server/src/services/completion/completion_performance.d
art'; |
17 import 'package:analysis_server/src/services/completion/dart/common_usage_sorter
.dart'; | 17 import 'package:analysis_server/src/services/completion/dart/common_usage_sorter
.dart'; |
18 import 'package:analysis_server/src/services/completion/dart/contribution_sorter
.dart'; | 18 import 'package:analysis_server/src/services/completion/dart/contribution_sorter
.dart'; |
19 import 'package:analysis_server/src/services/completion/dart/optype.dart'; | 19 import 'package:analysis_server/src/services/completion/dart/optype.dart'; |
20 import 'package:analysis_server/src/services/search/search_engine.dart'; | 20 import 'package:analysis_server/src/services/search/search_engine.dart'; |
21 import 'package:analyzer/dart/ast/ast.dart'; | 21 import 'package:analyzer/dart/ast/ast.dart'; |
| 22 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
22 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 23 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
23 import 'package:analyzer/dart/ast/token.dart'; | 24 import 'package:analyzer/dart/ast/token.dart'; |
24 import 'package:analyzer/dart/element/element.dart'; | 25 import 'package:analyzer/dart/element/element.dart'; |
25 import 'package:analyzer/dart/element/type.dart'; | 26 import 'package:analyzer/dart/element/type.dart'; |
26 import 'package:analyzer/exception/exception.dart'; | 27 import 'package:analyzer/exception/exception.dart'; |
27 import 'package:analyzer/file_system/file_system.dart'; | 28 import 'package:analyzer/file_system/file_system.dart'; |
28 import 'package:analyzer/src/context/context.dart' show AnalysisFutureHelper; | 29 import 'package:analyzer/src/context/context.dart' show AnalysisFutureHelper; |
29 import 'package:analyzer/src/dart/analysis/driver.dart'; | 30 import 'package:analyzer/src/dart/analysis/driver.dart'; |
30 import 'package:analyzer/src/dart/ast/token.dart'; | 31 import 'package:analyzer/src/dart/ast/token.dart'; |
31 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; | 32 import 'package:analyzer/src/generated/engine.dart' hide AnalysisResult; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 this.offset, | 173 this.offset, |
173 CompilationUnit unit, | 174 CompilationUnit unit, |
174 this._originalRequest, | 175 this._originalRequest, |
175 this.performance) { | 176 this.performance) { |
176 _updateTargets(unit); | 177 _updateTargets(unit); |
177 } | 178 } |
178 | 179 |
179 @override | 180 @override |
180 LibraryElement get coreLib { | 181 LibraryElement get coreLib { |
181 if (result != null) { | 182 if (result != null) { |
182 AnalysisContext context = result.unit.element.context; | 183 AnalysisContext context = |
| 184 resolutionMap.elementForCompilationUnit(result.unit).context; |
183 _coreLib = context.typeProvider.objectType.element.library; | 185 _coreLib = context.typeProvider.objectType.element.library; |
184 } else { | 186 } else { |
185 Source coreUri = sourceFactory.forUri('dart:core'); | 187 Source coreUri = sourceFactory.forUri('dart:core'); |
186 _coreLib = context.computeLibraryElement(coreUri); | 188 _coreLib = context.computeLibraryElement(coreUri); |
187 } | 189 } |
188 return _coreLib; | 190 return _coreLib; |
189 } | 191 } |
190 | 192 |
191 @override | 193 @override |
192 bool get includeIdentifiers { | 194 bool get includeIdentifiers { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return _resolvedImports; | 320 return _resolvedImports; |
319 } | 321 } |
320 | 322 |
321 @override | 323 @override |
322 Future<List<CompilationUnitElement>> resolveUnits() async { | 324 Future<List<CompilationUnitElement>> resolveUnits() async { |
323 checkAborted(); | 325 checkAborted(); |
324 if (_resolvedUnits != null) { | 326 if (_resolvedUnits != null) { |
325 return _resolvedUnits; | 327 return _resolvedUnits; |
326 } | 328 } |
327 if (result != null) { | 329 if (result != null) { |
328 _resolvedUnits = result.unit.element.library.units; | 330 _resolvedUnits = |
| 331 resolutionMap.elementForCompilationUnit(result.unit).library.units; |
329 return _resolvedUnits; | 332 return _resolvedUnits; |
330 } | 333 } |
331 LibraryElement libElem = libraryElement; | 334 LibraryElement libElem = libraryElement; |
332 if (libElem == null) { | 335 if (libElem == null) { |
333 return null; | 336 return null; |
334 } | 337 } |
335 _resolvedUnits = <CompilationUnitElement>[]; | 338 _resolvedUnits = <CompilationUnitElement>[]; |
336 for (CompilationUnitElement unresolvedUnit in libElem.units) { | 339 for (CompilationUnitElement unresolvedUnit in libElem.units) { |
337 CompilationUnit unit = await _computeAsync( | 340 CompilationUnit unit = await _computeAsync( |
338 this, | 341 this, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 CompletionPerformance performance = | 392 CompletionPerformance performance = |
390 (request as CompletionRequestImpl).performance; | 393 (request as CompletionRequestImpl).performance; |
391 const BUILD_REQUEST_TAG = 'build DartCompletionRequest'; | 394 const BUILD_REQUEST_TAG = 'build DartCompletionRequest'; |
392 performance.logStartTime(BUILD_REQUEST_TAG); | 395 performance.logStartTime(BUILD_REQUEST_TAG); |
393 | 396 |
394 Source libSource; | 397 Source libSource; |
395 CompilationUnit unit; | 398 CompilationUnit unit; |
396 if (request.context == null) { | 399 if (request.context == null) { |
397 unit = request.result.unit; | 400 unit = request.result.unit; |
398 // TODO(scheglov) support for parts | 401 // TODO(scheglov) support for parts |
399 libSource = unit.element.source; | 402 libSource = resolutionMap.elementForCompilationUnit(unit).source; |
400 } else { | 403 } else { |
401 Source source = request.source; | 404 Source source = request.source; |
402 AnalysisContext context = request.context; | 405 AnalysisContext context = request.context; |
403 | 406 |
404 const PARSE_TAG = 'parse unit'; | 407 const PARSE_TAG = 'parse unit'; |
405 performance.logStartTime(PARSE_TAG); | 408 performance.logStartTime(PARSE_TAG); |
406 unit = request.context.computeResult(source, PARSED_UNIT); | 409 unit = request.context.computeResult(source, PARSED_UNIT); |
407 performance.logElapseTime(PARSE_TAG); | 410 performance.logElapseTime(PARSE_TAG); |
408 | 411 |
409 if (unit.directives.any((d) => d is PartOfDirective)) { | 412 if (unit.directives.any((d) => d is PartOfDirective)) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 if (start <= requestOffset && requestOffset <= end) { | 531 if (start <= requestOffset && requestOffset <= end) { |
529 // Replacement range for import URI | 532 // Replacement range for import URI |
530 return new ReplacementRange(start, end - start); | 533 return new ReplacementRange(start, end - start); |
531 } | 534 } |
532 } | 535 } |
533 } | 536 } |
534 } | 537 } |
535 return new ReplacementRange(requestOffset, 0); | 538 return new ReplacementRange(requestOffset, 0); |
536 } | 539 } |
537 } | 540 } |
OLD | NEW |