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/resolution_accessors.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 = elementForCompilationUnit(result.unit).context; |
183 _coreLib = context.typeProvider.objectType.element.library; | 184 _coreLib = context.typeProvider.objectType.element.library; |
184 } else { | 185 } else { |
185 Source coreUri = sourceFactory.forUri('dart:core'); | 186 Source coreUri = sourceFactory.forUri('dart:core'); |
186 _coreLib = context.computeLibraryElement(coreUri); | 187 _coreLib = context.computeLibraryElement(coreUri); |
187 } | 188 } |
188 return _coreLib; | 189 return _coreLib; |
189 } | 190 } |
190 | 191 |
191 @override | 192 @override |
192 bool get includeIdentifiers { | 193 bool get includeIdentifiers { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return _resolvedImports; | 319 return _resolvedImports; |
319 } | 320 } |
320 | 321 |
321 @override | 322 @override |
322 Future<List<CompilationUnitElement>> resolveUnits() async { | 323 Future<List<CompilationUnitElement>> resolveUnits() async { |
323 checkAborted(); | 324 checkAborted(); |
324 if (_resolvedUnits != null) { | 325 if (_resolvedUnits != null) { |
325 return _resolvedUnits; | 326 return _resolvedUnits; |
326 } | 327 } |
327 if (result != null) { | 328 if (result != null) { |
328 _resolvedUnits = result.unit.element.library.units; | 329 _resolvedUnits = elementForCompilationUnit(result.unit).library.units; |
329 return _resolvedUnits; | 330 return _resolvedUnits; |
330 } | 331 } |
331 LibraryElement libElem = libraryElement; | 332 LibraryElement libElem = libraryElement; |
332 if (libElem == null) { | 333 if (libElem == null) { |
333 return null; | 334 return null; |
334 } | 335 } |
335 _resolvedUnits = <CompilationUnitElement>[]; | 336 _resolvedUnits = <CompilationUnitElement>[]; |
336 for (CompilationUnitElement unresolvedUnit in libElem.units) { | 337 for (CompilationUnitElement unresolvedUnit in libElem.units) { |
337 CompilationUnit unit = await _computeAsync( | 338 CompilationUnit unit = await _computeAsync( |
338 this, | 339 this, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 CompletionPerformance performance = | 390 CompletionPerformance performance = |
390 (request as CompletionRequestImpl).performance; | 391 (request as CompletionRequestImpl).performance; |
391 const BUILD_REQUEST_TAG = 'build DartCompletionRequest'; | 392 const BUILD_REQUEST_TAG = 'build DartCompletionRequest'; |
392 performance.logStartTime(BUILD_REQUEST_TAG); | 393 performance.logStartTime(BUILD_REQUEST_TAG); |
393 | 394 |
394 Source libSource; | 395 Source libSource; |
395 CompilationUnit unit; | 396 CompilationUnit unit; |
396 if (request.context == null) { | 397 if (request.context == null) { |
397 unit = request.result.unit; | 398 unit = request.result.unit; |
398 // TODO(scheglov) support for parts | 399 // TODO(scheglov) support for parts |
399 libSource = unit.element.source; | 400 libSource = elementForCompilationUnit(unit).source; |
400 } else { | 401 } else { |
401 Source source = request.source; | 402 Source source = request.source; |
402 AnalysisContext context = request.context; | 403 AnalysisContext context = request.context; |
403 | 404 |
404 const PARSE_TAG = 'parse unit'; | 405 const PARSE_TAG = 'parse unit'; |
405 performance.logStartTime(PARSE_TAG); | 406 performance.logStartTime(PARSE_TAG); |
406 unit = request.context.computeResult(source, PARSED_UNIT); | 407 unit = request.context.computeResult(source, PARSED_UNIT); |
407 performance.logElapseTime(PARSE_TAG); | 408 performance.logElapseTime(PARSE_TAG); |
408 | 409 |
409 if (unit.directives.any((d) => d is PartOfDirective)) { | 410 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) { | 529 if (start <= requestOffset && requestOffset <= end) { |
529 // Replacement range for import URI | 530 // Replacement range for import URI |
530 return new ReplacementRange(start, end - start); | 531 return new ReplacementRange(start, end - start); |
531 } | 532 } |
532 } | 533 } |
533 } | 534 } |
534 } | 535 } |
535 return new ReplacementRange(requestOffset, 0); | 536 return new ReplacementRange(requestOffset, 0); |
536 } | 537 } |
537 } | 538 } |
OLD | NEW |