| 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.computer; | 5 library services.completion.computer; |
| 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/dart_completion_manager.
dart'; | 10 import 'package:analysis_server/src/services/completion/dart_completion_manager.
dart'; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 68 } |
| 69 if (AnalysisEngine.isHtmlFileName(source.shortName)) { | 69 if (AnalysisEngine.isHtmlFileName(source.shortName)) { |
| 70 //TODO (danrubel) implement | 70 //TODO (danrubel) implement |
| 71 // return new HtmlCompletionManager(context, searchEngine, source, offset
); | 71 // return new HtmlCompletionManager(context, searchEngine, source, offset
); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 return new NoOpCompletionManager(source); | 74 return new NoOpCompletionManager(source); |
| 75 } | 75 } |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * Compute and cache information in preparation for a possible code |
| 79 * completion request sometime in the future. The default implementation |
| 80 * of this method does nothing. Subclasses may override but should not |
| 81 * count on this method being called before [computeSuggestions]. |
| 82 */ |
| 83 void computeCache() { |
| 84 } |
| 85 |
| 86 /** |
| 78 * Compute completion results for the given reqeust and append them to the str
eam. | 87 * Compute completion results for the given reqeust and append them to the str
eam. |
| 79 * Clients should not call this method directly as it is automatically called | 88 * Clients should not call this method directly as it is automatically called |
| 80 * when a client listens to the stream returned by [results]. | 89 * when a client listens to the stream returned by [results]. |
| 81 * Subclasses should override this method, append at least one result | 90 * Subclasses should override this method, append at least one result |
| 82 * to the [controller], and close the controller stream once complete. | 91 * to the [controller], and close the controller stream once complete. |
| 83 */ | 92 */ |
| 84 void compute(CompletionRequest request); | 93 void computeSuggestions(CompletionRequest request); |
| 85 | 94 |
| 86 /** | 95 /** |
| 87 * Generate a stream of code completion results. | 96 * Generate a stream of code completion results. |
| 88 */ | 97 */ |
| 89 Stream<CompletionResult> results(CompletionRequest request) { | 98 Stream<CompletionResult> results(CompletionRequest request) { |
| 90 controller = new StreamController<CompletionResult>(onListen: () { | 99 controller = new StreamController<CompletionResult>(onListen: () { |
| 91 scheduleMicrotask(() { | 100 scheduleMicrotask(() { |
| 92 compute(request); | 101 computeSuggestions(request); |
| 93 }); | 102 }); |
| 94 }); | 103 }); |
| 95 return controller.stream; | 104 return controller.stream; |
| 96 } | 105 } |
| 97 } | 106 } |
| 98 | 107 |
| 99 /** | 108 /** |
| 100 * Overall performance of a code completion operation. | 109 * Overall performance of a code completion operation. |
| 101 */ | 110 */ |
| 102 class CompletionPerformance { | 111 class CompletionPerformance { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 200 |
| 192 CompletionResult(this.replacementOffset, this.replacementLength, | 201 CompletionResult(this.replacementOffset, this.replacementLength, |
| 193 this.suggestions, this.last); | 202 this.suggestions, this.last); |
| 194 } | 203 } |
| 195 | 204 |
| 196 class NoOpCompletionManager extends CompletionManager { | 205 class NoOpCompletionManager extends CompletionManager { |
| 197 | 206 |
| 198 NoOpCompletionManager(Source source) : super(null, source); | 207 NoOpCompletionManager(Source source) : super(null, source); |
| 199 | 208 |
| 200 @override | 209 @override |
| 201 void compute(CompletionRequest request) { | 210 void computeSuggestions(CompletionRequest request) { |
| 202 controller.add(new CompletionResult(request.offset, 0, [], true)); | 211 controller.add(new CompletionResult(request.offset, 0, [], true)); |
| 203 } | 212 } |
| 204 } | 213 } |
| 205 | 214 |
| 206 /** | 215 /** |
| 207 * The performance of an operation when computing code completion. | 216 * The performance of an operation when computing code completion. |
| 208 */ | 217 */ |
| 209 class OperationPerformance { | 218 class OperationPerformance { |
| 210 | 219 |
| 211 /** | 220 /** |
| 212 * The name of the operation | 221 * The name of the operation |
| 213 */ | 222 */ |
| 214 final String name; | 223 final String name; |
| 215 | 224 |
| 216 /** | 225 /** |
| 217 * The elapse time or `null` if undefined. | 226 * The elapse time or `null` if undefined. |
| 218 */ | 227 */ |
| 219 final Duration elapsed; | 228 final Duration elapsed; |
| 220 | 229 |
| 221 OperationPerformance(this.name, this.elapsed); | 230 OperationPerformance(this.name, this.elapsed); |
| 222 } | 231 } |
| OLD | NEW |