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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 manager.computeCache().then((bool success) { | 151 manager.computeCache().then((bool success) { |
152 performance.logElapseTime(computeTag); | 152 performance.logElapseTime(computeTag); |
153 performance.complete('priorityChanged caching: $success'); | 153 performance.complete('priorityChanged caching: $success'); |
154 }); | 154 }); |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 /** | 158 /** |
159 * Process a `completion.getSuggestions` request. | 159 * Process a `completion.getSuggestions` request. |
160 */ | 160 */ |
161 Response processRequest(Request request) { | 161 Response processRequest(Request request, [CompletionManager manager]) { |
162 performance = new CompletionPerformance(); | 162 performance = new CompletionPerformance(); |
163 // extract params | 163 // extract params |
164 CompletionGetSuggestionsParams params = | 164 CompletionGetSuggestionsParams params = |
165 new CompletionGetSuggestionsParams.fromRequest(request); | 165 new CompletionGetSuggestionsParams.fromRequest(request); |
166 // schedule completion analysis | 166 // schedule completion analysis |
167 String completionId = (_nextCompletionId++).toString(); | 167 String completionId = (_nextCompletionId++).toString(); |
168 AnalysisContext context = server.getAnalysisContext(params.file); | 168 AnalysisContext context = server.getAnalysisContext(params.file); |
169 Source source = server.getSource(params.file); | 169 Source source = server.getSource(params.file); |
170 recordRequest(performance, context, source, params.offset); | 170 recordRequest(performance, context, source, params.offset); |
171 CompletionManager manager = completionManagerFor(context, source); | 171 if (manager == null) { |
| 172 manager = completionManagerFor(context, source); |
| 173 } |
172 CompletionRequest completionRequest = | 174 CompletionRequest completionRequest = |
173 new CompletionRequest(params.offset, performance); | 175 new CompletionRequest(params.offset, performance); |
174 int notificationCount = 0; | 176 int notificationCount = 0; |
175 manager.results(completionRequest).listen((CompletionResult result) { | 177 manager.results(completionRequest).listen((CompletionResult result) { |
176 ++notificationCount; | 178 ++notificationCount; |
177 performance.logElapseTime("notification $notificationCount send", () { | 179 performance.logElapseTime("notification $notificationCount send", () { |
178 sendCompletionNotification( | 180 sendCompletionNotification( |
179 completionId, | 181 completionId, |
180 result.replacementOffset, | 182 result.replacementOffset, |
181 result.replacementLength, | 183 result.replacementLength, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 if (_sourcesChangedSubscription != null) { | 264 if (_sourcesChangedSubscription != null) { |
263 _sourcesChangedSubscription.cancel(); | 265 _sourcesChangedSubscription.cancel(); |
264 _sourcesChangedSubscription = null; | 266 _sourcesChangedSubscription = null; |
265 } | 267 } |
266 if (_manager != null) { | 268 if (_manager != null) { |
267 _manager.dispose(); | 269 _manager.dispose(); |
268 _manager = null; | 270 _manager = null; |
269 } | 271 } |
270 } | 272 } |
271 } | 273 } |
OLD | NEW |