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' |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 DartCompletionRequestImpl._( | 84 DartCompletionRequestImpl._( |
85 AnalysisContext context, | 85 AnalysisContext context, |
86 ResourceProvider resourceProvider, | 86 ResourceProvider resourceProvider, |
87 SearchEngine searchEngine, | 87 SearchEngine searchEngine, |
88 Source source, | 88 Source source, |
89 int offset) | 89 int offset) |
90 : super(context, resourceProvider, searchEngine, source, offset); | 90 : super(context, resourceProvider, searchEngine, source, offset); |
91 | 91 |
92 @override | 92 @override |
| 93 CompletionTarget get target { |
| 94 if (_target == null) { |
| 95 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); |
| 96 _target = new CompletionTarget.forOffset(unit, offset); |
| 97 } |
| 98 return _target; |
| 99 } |
| 100 |
| 101 @override |
93 Future<CompilationUnit> resolveDeclarationsInScope() async { | 102 Future<CompilationUnit> resolveDeclarationsInScope() async { |
94 CompilationUnit unit = target.unit; | 103 CompilationUnit unit = target.unit; |
95 if (_haveResolveDeclarationsInScope) { | 104 if (_haveResolveDeclarationsInScope) { |
96 return unit; | 105 return unit; |
97 } | 106 } |
98 | 107 |
99 // Determine the library source | 108 // Determine the library source |
100 Source librarySource; | 109 Source librarySource; |
101 if (unit.directives.any((d) => d is PartOfDirective)) { | 110 if (unit.directives.any((d) => d is PartOfDirective)) { |
102 List<Source> libraries = context.getLibrariesContaining(source); | 111 List<Source> libraries = context.getLibrariesContaining(source); |
(...skipping 21 matching lines...) Expand all Loading... |
124 return null; | 133 return null; |
125 } | 134 } |
126 | 135 |
127 // Recompute the target for the newly resolved unit | 136 // Recompute the target for the newly resolved unit |
128 _target = new CompletionTarget.forOffset(resolvedUnit, offset); | 137 _target = new CompletionTarget.forOffset(resolvedUnit, offset); |
129 _haveResolveDeclarationsInScope = true; | 138 _haveResolveDeclarationsInScope = true; |
130 return resolvedUnit; | 139 return resolvedUnit; |
131 } | 140 } |
132 | 141 |
133 @override | 142 @override |
134 CompletionTarget get target { | 143 Future resolveIdentifier(SimpleIdentifier identifier) async { |
135 if (_target == null) { | 144 if (identifier.bestElement != null) { |
136 CompilationUnit unit = context.computeResult(source, PARSED_UNIT); | 145 return; |
137 _target = new CompletionTarget.forOffset(unit, offset); | |
138 } | 146 } |
139 return _target; | 147 |
| 148 //TODO(danrubel) resolve the expression or containing method |
| 149 // rather than the entire complilation unit |
| 150 |
| 151 CompilationUnit unit = target.unit; |
| 152 |
| 153 // Determine the library source |
| 154 Source librarySource; |
| 155 if (unit.directives.any((d) => d is PartOfDirective)) { |
| 156 List<Source> libraries = context.getLibrariesContaining(source); |
| 157 if (libraries.isEmpty) { |
| 158 return; |
| 159 } |
| 160 librarySource = libraries[0]; |
| 161 } else { |
| 162 librarySource = source; |
| 163 } |
| 164 |
| 165 // Resolve declarations in the target unit |
| 166 CompilationUnit resolvedUnit = |
| 167 await new AnalysisFutureHelper<CompilationUnit>( |
| 168 context, |
| 169 new LibrarySpecificUnit(librarySource, source), |
| 170 RESOLVED_UNIT).computeAsync(); |
| 171 |
| 172 // TODO(danrubel) determine if the underlying source has been modified |
| 173 // in a way that invalidates the completion request |
| 174 // and return null |
| 175 |
| 176 // Gracefully degrade if unit cannot be resolved |
| 177 if (resolvedUnit == null) { |
| 178 return; |
| 179 } |
| 180 |
| 181 // Recompute the target for the newly resolved unit |
| 182 _target = new CompletionTarget.forOffset(resolvedUnit, offset); |
| 183 _haveResolveDeclarationsInScope = true; |
140 } | 184 } |
141 } | 185 } |
OLD | NEW |