| 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 } | 69 } |
| 70 return new NoOpCompletionManager(source); | 70 return new NoOpCompletionManager(source); |
| 71 } | 71 } |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * Compute and cache information in preparation for a possible code | 74 * Compute and cache information in preparation for a possible code |
| 75 * completion request sometime in the future. The default implementation | 75 * completion request sometime in the future. The default implementation |
| 76 * of this method does nothing. Subclasses may override but should not | 76 * of this method does nothing. Subclasses may override but should not |
| 77 * count on this method being called before [computeSuggestions]. | 77 * count on this method being called before [computeSuggestions]. |
| 78 * Return a future that completes when the cache is computed with a bool |
| 79 * indicating success. |
| 78 */ | 80 */ |
| 79 void computeCache() { | 81 Future<bool> computeCache() { |
| 82 return new Future.value(true); |
| 80 } | 83 } |
| 81 | 84 |
| 82 /** | 85 /** |
| 83 * Compute completion results for the given reqeust and append them to the str
eam. | 86 * Compute completion results for the given reqeust and append them to the str
eam. |
| 84 * Clients should not call this method directly as it is automatically called | 87 * Clients should not call this method directly as it is automatically called |
| 85 * when a client listens to the stream returned by [results]. | 88 * when a client listens to the stream returned by [results]. |
| 86 * Subclasses should override this method, append at least one result | 89 * Subclasses should override this method, append at least one result |
| 87 * to the [controller], and close the controller stream once complete. | 90 * to the [controller], and close the controller stream once complete. |
| 88 */ | 91 */ |
| 89 void computeSuggestions(CompletionRequest request); | 92 void computeSuggestions(CompletionRequest request); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 } | 105 } |
| 103 | 106 |
| 104 /** | 107 /** |
| 105 * Overall performance of a code completion operation. | 108 * Overall performance of a code completion operation. |
| 106 */ | 109 */ |
| 107 class CompletionPerformance { | 110 class CompletionPerformance { |
| 108 final Map<String, Duration> _startTimes = new Map<String, Duration>(); | 111 final Map<String, Duration> _startTimes = new Map<String, Duration>(); |
| 109 final Stopwatch _stopwatch = new Stopwatch(); | 112 final Stopwatch _stopwatch = new Stopwatch(); |
| 110 final List<OperationPerformance> operations = <OperationPerformance>[]; | 113 final List<OperationPerformance> operations = <OperationPerformance>[]; |
| 111 | 114 |
| 115 Source source; |
| 116 int offset; |
| 117 String contents; |
| 118 int notificationCount = -1; |
| 119 int suggestionCount = -1; |
| 120 |
| 112 CompletionPerformance() { | 121 CompletionPerformance() { |
| 113 _stopwatch.start(); | 122 _stopwatch.start(); |
| 114 } | 123 } |
| 115 | 124 |
| 116 void complete() { | 125 int get elapsedInMilliseconds => |
| 126 operations.length > 0 ? operations.last.elapsed.inMilliseconds : 0; |
| 127 |
| 128 String get snippet { |
| 129 if (contents == null || offset < 0 || contents.length < offset) { |
| 130 return '???'; |
| 131 } |
| 132 int start = offset; |
| 133 while (start > 0) { |
| 134 String ch = contents[start - 1]; |
| 135 if (ch == '\r' || ch == '\n') { |
| 136 break; |
| 137 } |
| 138 --start; |
| 139 } |
| 140 int end = offset; |
| 141 while (end < contents.length) { |
| 142 String ch = contents[end]; |
| 143 if (ch == '\r' || ch == '\n') { |
| 144 break; |
| 145 } |
| 146 ++end; |
| 147 } |
| 148 String prefix = contents.substring(start, offset); |
| 149 String suffix = contents.substring(offset, end); |
| 150 return '$prefix^$suffix'; |
| 151 } |
| 152 |
| 153 void complete([String tag = null]) { |
| 117 _stopwatch.stop(); | 154 _stopwatch.stop(); |
| 118 _logDuration('total time', _stopwatch.elapsed); | 155 _logDuration(tag != null ? tag : 'total time', _stopwatch.elapsed); |
| 119 } | 156 } |
| 120 | 157 |
| 121 logElapseTime(String tag, [f() = null]) { | 158 logElapseTime(String tag, [f() = null]) { |
| 122 Duration start; | 159 Duration start; |
| 123 Duration end = _stopwatch.elapsed; | 160 Duration end = _stopwatch.elapsed; |
| 124 var result; | 161 var result; |
| 125 if (f == null) { | 162 if (f == null) { |
| 126 start = _startTimes[tag]; | 163 start = _startTimes[tag]; |
| 127 if (start == null) { | 164 if (start == null) { |
| 128 _logDuration(tag, null); | 165 _logDuration(tag, null); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 */ | 255 */ |
| 219 final String name; | 256 final String name; |
| 220 | 257 |
| 221 /** | 258 /** |
| 222 * The elapse time or `null` if undefined. | 259 * The elapse time or `null` if undefined. |
| 223 */ | 260 */ |
| 224 final Duration elapsed; | 261 final Duration elapsed; |
| 225 | 262 |
| 226 OperationPerformance(this.name, this.elapsed); | 263 OperationPerformance(this.name, this.elapsed); |
| 227 } | 264 } |
| OLD | NEW |