| 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 'package:analysis_server/src/analysis_server.dart'; | 7 import 'package:analysis_server/src/analysis_server.dart'; |
| 8 import 'package:analysis_server/src/constants.dart'; | 8 import 'package:analysis_server/src/constants.dart'; |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; | 10 import 'package:analysis_server/src/services/completion/completion_manager.dart'
; |
| 11 | 11 |
| 12 export 'package:analysis_server/src/services/completion/completion_manager.dart' |
| 13 show CompletionPerformance, OperationPerformance; |
| 14 |
| 12 /** | 15 /** |
| 13 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] | 16 * Instances of the class [CompletionDomainHandler] implement a [RequestHandler] |
| 14 * that handles requests in the search domain. | 17 * that handles requests in the search domain. |
| 15 */ | 18 */ |
| 16 class CompletionDomainHandler implements RequestHandler { | 19 class CompletionDomainHandler implements RequestHandler { |
| 17 /** | 20 /** |
| 18 * The analysis server that is using this handler to process requests. | 21 * The analysis server that is using this handler to process requests. |
| 19 */ | 22 */ |
| 20 final AnalysisServer server; | 23 final AnalysisServer server; |
| 21 | 24 |
| 22 /** | 25 /** |
| 23 * The next completion response id. | 26 * The next completion response id. |
| 24 */ | 27 */ |
| 25 int _nextCompletionId = 0; | 28 int _nextCompletionId = 0; |
| 26 | 29 |
| 27 /** | 30 /** |
| 31 * Cached information from a prior completion operation. |
| 32 * The type of cached information depends upon the completion operation. |
| 33 */ |
| 34 // TODO (danrubel) clear cache if either source or context changes |
| 35 CompletionCache _cache; |
| 36 |
| 37 /** |
| 28 * Code completion peformance for the last completion operation. | 38 * Code completion peformance for the last completion operation. |
| 29 */ | 39 */ |
| 30 CompletionPerformance performance; | 40 CompletionPerformance performance; |
| 31 | 41 |
| 32 /** | 42 /** |
| 33 * Initialize a new request handler for the given [server]. | 43 * Initialize a new request handler for the given [server]. |
| 34 */ | 44 */ |
| 35 CompletionDomainHandler(this.server); | 45 CompletionDomainHandler(this.server); |
| 36 | 46 |
| 37 @override | 47 @override |
| (...skipping 12 matching lines...) Expand all Loading... |
| 50 /** | 60 /** |
| 51 * Process a `completion.getSuggestions` request. | 61 * Process a `completion.getSuggestions` request. |
| 52 */ | 62 */ |
| 53 Response processRequest(Request request) { | 63 Response processRequest(Request request) { |
| 54 performance = new CompletionPerformance(); | 64 performance = new CompletionPerformance(); |
| 55 // extract params | 65 // extract params |
| 56 CompletionGetSuggestionsParams params = | 66 CompletionGetSuggestionsParams params = |
| 57 new CompletionGetSuggestionsParams.fromRequest(request); | 67 new CompletionGetSuggestionsParams.fromRequest(request); |
| 58 // schedule completion analysis | 68 // schedule completion analysis |
| 59 String completionId = (_nextCompletionId++).toString(); | 69 String completionId = (_nextCompletionId++).toString(); |
| 60 CompletionManager.create( | 70 CompletionManager manager = new CompletionManager.create( |
| 61 server.getAnalysisContext(params.file), | 71 server.getAnalysisContext(params.file), |
| 62 server.getSource(params.file), | 72 server.getSource(params.file), |
| 63 params.offset, | 73 params.offset, |
| 64 server.searchEngine, | 74 server.searchEngine, |
| 65 performance).results().listen((CompletionResult result) { | 75 _cache, |
| 76 performance); |
| 77 manager.results().listen((CompletionResult result) { |
| 66 sendCompletionNotification( | 78 sendCompletionNotification( |
| 67 completionId, | 79 completionId, |
| 68 result.replacementOffset, | 80 result.replacementOffset, |
| 69 result.replacementLength, | 81 result.replacementLength, |
| 70 result.suggestions, | 82 result.suggestions, |
| 71 result.last); | 83 result.last); |
| 72 if (result.last) { | 84 if (result.last) { |
| 73 performance.complete(); | 85 performance.complete(); |
| 86 _cache = manager.completionCache; |
| 74 } | 87 } |
| 75 }); | 88 }); |
| 76 // initial response without results | 89 // initial response without results |
| 77 return new CompletionGetSuggestionsResult( | 90 return new CompletionGetSuggestionsResult( |
| 78 completionId).toResponse(request.id); | 91 completionId).toResponse(request.id); |
| 79 } | 92 } |
| 80 | 93 |
| 81 /** | 94 /** |
| 82 * Send completion notification results. | 95 * Send completion notification results. |
| 83 */ | 96 */ |
| 84 void sendCompletionNotification(String completionId, int replacementOffset, | 97 void sendCompletionNotification(String completionId, int replacementOffset, |
| 85 int replacementLength, Iterable<CompletionSuggestion> results, bool isLast
) { | 98 int replacementLength, Iterable<CompletionSuggestion> results, bool isLast
) { |
| 86 server.sendNotification( | 99 server.sendNotification( |
| 87 new CompletionResultsParams( | 100 new CompletionResultsParams( |
| 88 completionId, | 101 completionId, |
| 89 replacementOffset, | 102 replacementOffset, |
| 90 replacementLength, | 103 replacementLength, |
| 91 results, | 104 results, |
| 92 isLast).toNotification()); | 105 isLast).toNotification()); |
| 93 } | 106 } |
| 94 } | 107 } |
| OLD | NEW |