Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: pkg/analysis_server/lib/src/services/completion/dart_completion_manager.dart

Issue 800723002: Allow completions to wait for analysis without requiring a busy wait loop. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 request.replacementOffset, 175 request.replacementOffset,
176 request.replacementLength, 176 request.replacementLength,
177 request.suggestions, 177 request.suggestions,
178 last)); 178 last));
179 if (last) { 179 if (last) {
180 controller.close(); 180 controller.close();
181 } 181 }
182 } 182 }
183 183
184 /** 184 /**
185 * Return a future that completes when analysis is complete. 185 * Return a future that either (a) completes with the resolved compilation
186 * unit when analysis is complete, or (b) completes with null if the
187 * compilation unit is never going to be resolved.
186 */ 188 */
187 Future<CompilationUnit> waitForAnalysis([int waitCount = 10000]) { 189 Future<CompilationUnit> waitForAnalysis() {
188 //TODO (danrubel) replace this when new API is ready. 190 return context.getLibraryElementFuture(
189 // I expect the new API to be either a stream of resolution events 191 source).then((LibraryElement library) {
190 // or a future that completes when the resolved library element is available 192 return context.getResolvedCompilationUnitFuture(source, library);
191 LibraryElement library = context.getLibraryElement(source); 193 }).catchError((_) {
192 if (library != null) { 194 // This source file is not scheduled for analysis, so a resolved
193 CompilationUnit unit = 195 // compilation unit is never going to get computed.
194 context.getResolvedCompilationUnit(source, library); 196 return null;
195 if (unit != null) { 197 }, test: (e) => e is AnalysisNotScheduledError);
196 return new Future.value(unit);
197 }
198 }
199 //TODO (danrubel) Remove this HACK
200 if (waitCount > 0) {
201 return new Future(() {
202 return waitForAnalysis(waitCount - 1);
203 });
204 }
205 return new Future.value(null);
206 } 198 }
207 } 199 }
208 200
209 /** 201 /**
210 * The context in which the completion is requested. 202 * The context in which the completion is requested.
211 */ 203 */
212 class DartCompletionRequest extends CompletionRequest { 204 class DartCompletionRequest extends CompletionRequest {
213 /** 205 /**
214 * The analysis context in which the completion is requested. 206 * The analysis context in which the completion is requested.
215 */ 207 */
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 * containing the cursor is to be replaced when the suggestion is applied 250 * containing the cursor is to be replaced when the suggestion is applied
259 * (that is, the number of characters in the existing identifier). 251 * (that is, the number of characters in the existing identifier).
260 */ 252 */
261 int replacementLength; 253 int replacementLength;
262 254
263 /** 255 /**
264 * The list of suggestions to be sent to the client. 256 * The list of suggestions to be sent to the client.
265 */ 257 */
266 final List<CompletionSuggestion> suggestions = <CompletionSuggestion>[]; 258 final List<CompletionSuggestion> suggestions = <CompletionSuggestion>[];
267 259
260 DartCompletionRequest(this.context, this.searchEngine, this.source,
261 int offset, this.cache, CompletionPerformance performance)
262 : super(offset, performance);
263
268 /** 264 /**
269 * Return the original text from the [replacementOffset] to the [offset] 265 * Return the original text from the [replacementOffset] to the [offset]
270 * that can be used to filter the suggestions on the server side. 266 * that can be used to filter the suggestions on the server side.
271 */ 267 */
272 String get filterText { 268 String get filterText {
273 return context.getContents(source).data.substring(replacementOffset, offset) ; 269 return context.getContents(
270 source).data.substring(replacementOffset, offset);
274 } 271 }
275
276 DartCompletionRequest(this.context, this.searchEngine, this.source,
277 int offset, this.cache, CompletionPerformance performance)
278 : super(offset, performance);
279 } 272 }
280 273
281 /** 274 /**
282 * Visitor used to determine the replacement offset and length 275 * Visitor used to determine the replacement offset and length
283 * based upon the cursor location. 276 * based upon the cursor location.
284 */ 277 */
285 class _ReplacementOffsetBuilder extends SimpleAstVisitor { 278 class _ReplacementOffsetBuilder extends SimpleAstVisitor {
286 final DartCompletionRequest request; 279 final DartCompletionRequest request;
287 280
288 _ReplacementOffsetBuilder(this.request) { 281 _ReplacementOffsetBuilder(this.request) {
289 request.replacementOffset = request.offset; 282 request.replacementOffset = request.offset;
290 request.replacementLength = 0; 283 request.replacementLength = 0;
291 } 284 }
292 285
293 visitSimpleIdentifier(SimpleIdentifier node) { 286 visitSimpleIdentifier(SimpleIdentifier node) {
294 request.replacementOffset = node.offset; 287 request.replacementOffset = node.offset;
295 request.replacementLength = node.length; 288 request.replacementLength = node.length;
296 } 289 }
297 } 290 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/completion_test.dart » ('j') | pkg/analyzer/lib/src/generated/engine.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698