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/search/search_engine.dart'; | 16 import 'package:analysis_server/src/services/search/search_engine.dart'; |
17 import 'package:analyzer/file_system/file_system.dart'; | 17 import 'package:analyzer/file_system/file_system.dart'; |
18 import 'package:analyzer/src/context/context.dart' | 18 import 'package:analyzer/src/context/context.dart' |
19 show AnalysisFutureHelper, AnalysisContextImpl; | 19 show AnalysisFutureHelper, AnalysisContextImpl; |
20 import 'package:analyzer/src/generated/ast.dart'; | 20 import 'package:analyzer/src/generated/ast.dart'; |
21 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; | 21 import 'package:analyzer/src/generated/engine.dart' hide AnalysisContextImpl; |
22 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
23 import 'package:analyzer/src/task/dart.dart'; | 23 import 'package:analyzer/src/task/dart.dart'; |
24 import 'package:analyzer/task/dart.dart'; | 24 import 'package:analyzer/task/dart.dart'; |
25 import 'package:analyzer/src/generated/element.dart'; | |
25 | 26 |
26 /** | 27 /** |
27 * [DartCompletionManager] determines if a completion request is Dart specific | 28 * [DartCompletionManager] determines if a completion request is Dart specific |
28 * and forwards those requests to all [DartCompletionContributor]s. | 29 * and forwards those requests to all [DartCompletionContributor]s. |
29 */ | 30 */ |
30 class DartCompletionManager implements CompletionContributor { | 31 class DartCompletionManager implements CompletionContributor { |
31 @override | 32 @override |
32 Future<List<CompletionSuggestion>> computeSuggestions( | 33 Future<List<CompletionSuggestion>> computeSuggestions( |
33 CompletionRequest request) { | 34 CompletionRequest request) { |
34 if (AnalysisEngine.isDartFileName(request.source.shortName)) { | 35 if (AnalysisEngine.isDartFileName(request.source.shortName)) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 @override | 93 @override |
93 CompletionTarget get target { | 94 CompletionTarget get target { |
94 if (_target == null) { | 95 if (_target == null) { |
95 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); | 96 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); |
96 _target = new CompletionTarget.forOffset(unit, offset); | 97 _target = new CompletionTarget.forOffset(unit, offset); |
97 } | 98 } |
98 return _target; | 99 return _target; |
99 } | 100 } |
100 | 101 |
101 @override | 102 @override |
103 Future<LibraryElement> resolveContainingLibrary() async { | |
scheglov
2015/12/07 16:16:15
It seems that the documentation for the method and
danrubel
2015/12/07 16:59:38
Good point. This is not meant to resolve the libra
| |
104 //TODO(danrubel) resolve the library element | |
105 // rather than all the declarations | |
106 CompilationUnit unit = await resolveDeclarationsInScope(); | |
107 if (unit != null) { | |
108 CompilationUnitElement elem = unit.element; | |
109 if (elem != null) { | |
110 return elem.library; | |
111 } | |
112 } | |
113 return null; | |
114 } | |
115 | |
116 @override | |
102 Future<CompilationUnit> resolveDeclarationsInScope() async { | 117 Future<CompilationUnit> resolveDeclarationsInScope() async { |
103 CompilationUnit unit = target.unit; | 118 CompilationUnit unit = target.unit; |
104 if (_haveResolveDeclarationsInScope) { | 119 if (_haveResolveDeclarationsInScope) { |
105 return unit; | 120 return unit; |
106 } | 121 } |
107 | 122 |
108 // Determine the library source | 123 // Determine the library source |
109 Source librarySource; | 124 Source librarySource; |
110 if (unit.directives.any((d) => d is PartOfDirective)) { | 125 if (unit.directives.any((d) => d is PartOfDirective)) { |
111 List<Source> libraries = context.getLibrariesContaining(source); | 126 List<Source> libraries = context.getLibrariesContaining(source); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 // Gracefully degrade if unit cannot be resolved | 191 // Gracefully degrade if unit cannot be resolved |
177 if (resolvedUnit == null) { | 192 if (resolvedUnit == null) { |
178 return; | 193 return; |
179 } | 194 } |
180 | 195 |
181 // Recompute the target for the newly resolved unit | 196 // Recompute the target for the newly resolved unit |
182 _target = new CompletionTarget.forOffset(resolvedUnit, offset); | 197 _target = new CompletionTarget.forOffset(resolvedUnit, offset); |
183 _haveResolveDeclarationsInScope = true; | 198 _haveResolveDeclarationsInScope = true; |
184 } | 199 } |
185 } | 200 } |
OLD | NEW |