Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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; | 5 library services.completion.dart; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/completion/arglist_computer.dart'; | 10 import 'package:analysis_server/src/services/completion/arglist_computer.dart'; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 request.replacementLength, | 170 request.replacementLength, |
| 171 request.suggestions, | 171 request.suggestions, |
| 172 last)); | 172 last)); |
| 173 if (last) { | 173 if (last) { |
| 174 controller.close(); | 174 controller.close(); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * Return a future that completes when analysis is complete. | 179 * Return a future that completes when analysis is complete. |
| 180 * Return `true` if the compilation unit is be resolved. | |
| 181 */ | 180 */ |
| 182 Future<CompilationUnit> waitForAnalysis() { | 181 Future<CompilationUnit> waitForAnalysis([int waitCount = 10000]) { |
| 182 //TODO (danrubel) replace this when new API is ready. | |
| 183 // I expect the new API to be either a stream of resolution events | |
| 184 // or a future that completes when the resolved library element is available | |
| 183 LibraryElement library = context.getLibraryElement(source); | 185 LibraryElement library = context.getLibraryElement(source); |
| 184 if (library != null) { | 186 if (library != null) { |
| 185 CompilationUnit unit = | 187 CompilationUnit unit = |
| 186 context.getResolvedCompilationUnit(source, library); | 188 context.getResolvedCompilationUnit(source, library); |
| 187 if (unit != null) { | 189 if (unit != null) { |
| 188 return new Future.value(unit); | 190 return new Future.value(unit); |
| 189 } | 191 } |
| 190 } | 192 } |
| 191 //TODO (danrubel) Determine if analysis is complete but unit not resolved | 193 //TODO (danrubel) Remove this HACK |
| 192 return new Future(waitForAnalysis); | 194 if (waitCount > 0) { |
| 195 return new Future(() { | |
| 196 waitForAnalysis(waitCount - 1); | |
|
Paul Berry
2014/12/09 19:24:08
I believe this needs to be "return waitForAnalysis
danrubel
2014/12/09 23:51:52
Good catch. Done.
| |
| 197 }); | |
| 198 } | |
| 193 } | 199 } |
| 194 } | 200 } |
| 195 | 201 |
| 196 /** | 202 /** |
| 197 * The context in which the completion is requested. | 203 * The context in which the completion is requested. |
| 198 */ | 204 */ |
| 199 class DartCompletionRequest extends CompletionRequest { | 205 class DartCompletionRequest extends CompletionRequest { |
| 200 /** | 206 /** |
| 201 * The analysis context in which the completion is requested. | 207 * The analysis context in which the completion is requested. |
| 202 */ | 208 */ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 _ReplacementOffsetBuilder(this.request) { | 273 _ReplacementOffsetBuilder(this.request) { |
| 268 request.replacementOffset = request.offset; | 274 request.replacementOffset = request.offset; |
| 269 request.replacementLength = 0; | 275 request.replacementLength = 0; |
| 270 } | 276 } |
| 271 | 277 |
| 272 visitSimpleIdentifier(SimpleIdentifier node) { | 278 visitSimpleIdentifier(SimpleIdentifier node) { |
| 273 request.replacementOffset = node.offset; | 279 request.replacementOffset = node.offset; |
| 274 request.replacementLength = node.length; | 280 request.replacementLength = node.length; |
| 275 } | 281 } |
| 276 } | 282 } |
| OLD | NEW |