| 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/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 /** | 46 /** |
| 47 * Code completion peformance for the last completion operation. | 47 * Code completion peformance for the last completion operation. |
| 48 */ | 48 */ |
| 49 CompletionPerformance performance; | 49 CompletionPerformance performance; |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * Initialize a new request handler for the given [server]. | 52 * Initialize a new request handler for the given [server]. |
| 53 */ | 53 */ |
| 54 CompletionDomainHandler(this.server) { | 54 CompletionDomainHandler(this.server) { |
| 55 server.onContextsChanged.listen(contextsChanged); | 55 server.onContextsChanged.listen(contextsChanged); |
| 56 server.onPriorityChange.listen(priorityChanged); |
| 56 } | 57 } |
| 57 | 58 |
| 58 /** | 59 /** |
| 59 * Return the completion manager for most recent [Source] and [AnalysisContext
], | 60 * Return the completion manager for most recent [Source] and [AnalysisContext
], |
| 60 * or `null` if none. | 61 * or `null` if none. |
| 61 */ | 62 */ |
| 62 CompletionManager get manager => _manager; | 63 CompletionManager get manager => _manager; |
| 63 | 64 |
| 64 /** | 65 /** |
| 65 * Return the [CompletionManager] for the given [context] and [source], | 66 * Return the [CompletionManager] for the given [context] and [source], |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 if (requestName == COMPLETION_GET_SUGGESTIONS) { | 108 if (requestName == COMPLETION_GET_SUGGESTIONS) { |
| 108 return processRequest(request); | 109 return processRequest(request); |
| 109 } | 110 } |
| 110 } on RequestFailure catch (exception) { | 111 } on RequestFailure catch (exception) { |
| 111 return exception.response; | 112 return exception.response; |
| 112 } | 113 } |
| 113 return null; | 114 return null; |
| 114 } | 115 } |
| 115 | 116 |
| 116 /** | 117 /** |
| 118 * If the set the priority files has changed, then pre-cache completion |
| 119 * information related to the first priority file. |
| 120 */ |
| 121 void priorityChanged(PriorityChangeEvent event) { |
| 122 Source source = event.firstSource; |
| 123 if (source == null) { |
| 124 return; |
| 125 } |
| 126 AnalysisContext context = server.getAnalysisContextForSource(source); |
| 127 if (context == null) { |
| 128 return; |
| 129 } |
| 130 completionManagerFor(context, source).computeCache(); |
| 131 } |
| 132 |
| 133 /** |
| 117 * Process a `completion.getSuggestions` request. | 134 * Process a `completion.getSuggestions` request. |
| 118 */ | 135 */ |
| 119 Response processRequest(Request request) { | 136 Response processRequest(Request request) { |
| 120 performance = new CompletionPerformance(); | 137 performance = new CompletionPerformance(); |
| 121 // extract params | 138 // extract params |
| 122 CompletionGetSuggestionsParams params = | 139 CompletionGetSuggestionsParams params = |
| 123 new CompletionGetSuggestionsParams.fromRequest(request); | 140 new CompletionGetSuggestionsParams.fromRequest(request); |
| 124 // schedule completion analysis | 141 // schedule completion analysis |
| 125 String completionId = (_nextCompletionId++).toString(); | 142 String completionId = (_nextCompletionId++).toString(); |
| 126 CompletionManager manager = completionManagerFor( | 143 CompletionManager manager = completionManagerFor( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 * Discard the sourcesChanged subscription if any | 202 * Discard the sourcesChanged subscription if any |
| 186 */ | 203 */ |
| 187 void _discardManager() { | 204 void _discardManager() { |
| 188 if (_sourcesChangedSubscription != null) { | 205 if (_sourcesChangedSubscription != null) { |
| 189 _sourcesChangedSubscription.cancel(); | 206 _sourcesChangedSubscription.cancel(); |
| 190 _sourcesChangedSubscription = null; | 207 _sourcesChangedSubscription = null; |
| 191 } | 208 } |
| 192 _manager = null; | 209 _manager = null; |
| 193 } | 210 } |
| 194 } | 211 } |
| OLD | NEW |