| 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 domain.completion; | 5 library domain.completion; |
| 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/analysis_server.dart'; | 10 import 'package:analysis_server/src/analysis_server.dart'; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 ' but found ${params.offset}'); | 200 ' but found ${params.offset}'); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // schedule completion analysis | 203 // schedule completion analysis |
| 204 recordRequest(performance, context, source, params.offset); | 204 recordRequest(performance, context, source, params.offset); |
| 205 if (manager == null) { | 205 if (manager == null) { |
| 206 manager = completionManagerFor(context, source); | 206 manager = completionManagerFor(context, source); |
| 207 } | 207 } |
| 208 CompletionRequest completionRequest = new CompletionRequestImpl(context, | 208 CompletionRequest completionRequest = new CompletionRequestImpl(context, |
| 209 server.resourceProvider, server.searchEngine, source, params.offset); | 209 server.resourceProvider, server.searchEngine, source, params.offset); |
| 210 int notificationCount = 0; | |
| 211 String completionId = (_nextCompletionId++).toString(); | 210 String completionId = (_nextCompletionId++).toString(); |
| 212 manager.results(completionRequest).listen((CompletionResult result) { | 211 manager |
| 213 ++notificationCount; | 212 .computeSuggestions(completionRequest) |
| 214 bool isLast = result is CompletionResultImpl ? result.isLast : true; | 213 .then((CompletionResult result) { |
| 215 performance.logElapseTime("notification $notificationCount send", () { | 214 const SEND_NOTIFICATION_TAG = 'send notification'; |
| 216 sendCompletionNotification(completionId, result.replacementOffset, | 215 performance.logStartTime(SEND_NOTIFICATION_TAG); |
| 217 result.replacementLength, result.suggestions, isLast); | 216 sendCompletionNotification(completionId, result.replacementOffset, |
| 218 }); | 217 result.replacementLength, result.suggestions); |
| 219 if (notificationCount == 1) { | 218 performance.logElapseTime(SEND_NOTIFICATION_TAG); |
| 220 performance.logFirstNotificationComplete('notification 1 complete'); | 219 |
| 221 performance.suggestionCountFirst = result.suggestions.length; | 220 performance.notificationCount = 1; |
| 222 } | 221 performance.logFirstNotificationComplete('notification 1 complete'); |
| 223 if (isLast) { | 222 performance.suggestionCountFirst = result.suggestions.length; |
| 224 performance.notificationCount = notificationCount; | 223 performance.suggestionCountLast = result.suggestions.length; |
| 225 performance.suggestionCountLast = result.suggestions.length; | 224 performance.complete(); |
| 226 performance.complete(); | |
| 227 } | |
| 228 }); | 225 }); |
| 229 // initial response without results | 226 // initial response without results |
| 230 return new CompletionGetSuggestionsResult(completionId) | 227 return new CompletionGetSuggestionsResult(completionId) |
| 231 .toResponse(request.id); | 228 .toResponse(request.id); |
| 232 } | 229 } |
| 233 | 230 |
| 234 /** | 231 /** |
| 235 * If tracking code completion performance over time, then | 232 * If tracking code completion performance over time, then |
| 236 * record addition information about the request in the performance record. | 233 * record addition information about the request in the performance record. |
| 237 */ | 234 */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 248 performance.setContentsAndOffset(data.data, offset); | 245 performance.setContentsAndOffset(data.data, offset); |
| 249 while (performanceList.length >= performanceListMaxLength) { | 246 while (performanceList.length >= performanceListMaxLength) { |
| 250 performanceList.removeAt(0); | 247 performanceList.removeAt(0); |
| 251 } | 248 } |
| 252 performanceList.add(performance); | 249 performanceList.add(performance); |
| 253 } | 250 } |
| 254 | 251 |
| 255 /** | 252 /** |
| 256 * Send completion notification results. | 253 * Send completion notification results. |
| 257 */ | 254 */ |
| 258 void sendCompletionNotification( | 255 void sendCompletionNotification(String completionId, int replacementOffset, |
| 259 String completionId, | 256 int replacementLength, Iterable<CompletionSuggestion> results) { |
| 260 int replacementOffset, | |
| 261 int replacementLength, | |
| 262 Iterable<CompletionSuggestion> results, | |
| 263 bool isLast) { | |
| 264 server.sendNotification(new CompletionResultsParams( | 257 server.sendNotification(new CompletionResultsParams( |
| 265 completionId, replacementOffset, replacementLength, results, isLast) | 258 completionId, replacementOffset, replacementLength, results, true) |
| 266 .toNotification()); | 259 .toNotification()); |
| 267 } | 260 } |
| 268 | 261 |
| 269 /** | 262 /** |
| 270 * Discard the cache if a source other than the source referenced by | 263 * Discard the cache if a source other than the source referenced by |
| 271 * the cache changes or if any source is added, removed, or deleted. | 264 * the cache changes or if any source is added, removed, or deleted. |
| 272 */ | 265 */ |
| 273 void sourcesChanged(SourcesChangedEvent event) { | 266 void sourcesChanged(SourcesChangedEvent event) { |
| 274 bool shouldDiscardManager(SourcesChangedEvent event) { | 267 bool shouldDiscardManager(SourcesChangedEvent event) { |
| 275 if (_manager == null) { | 268 if (_manager == null) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 296 if (_sourcesChangedSubscription != null) { | 289 if (_sourcesChangedSubscription != null) { |
| 297 _sourcesChangedSubscription.cancel(); | 290 _sourcesChangedSubscription.cancel(); |
| 298 _sourcesChangedSubscription = null; | 291 _sourcesChangedSubscription = null; |
| 299 } | 292 } |
| 300 if (_manager != null) { | 293 if (_manager != null) { |
| 301 _manager.dispose(); | 294 _manager.dispose(); |
| 302 _manager = null; | 295 _manager = null; |
| 303 } | 296 } |
| 304 } | 297 } |
| 305 } | 298 } |
| OLD | NEW |