Chromium Code Reviews| 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 analysis.server; | 5 library analysis.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/analysis_logger.dart'; | 10 import 'package:analysis_server/src/analysis_logger.dart'; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 operationQueue = new ServerOperationQueue(this); | 140 operationQueue = new ServerOperationQueue(this); |
| 141 contextDirectoryManager = new AnalysisServerContextDirectoryManager(this, re sourceProvider); | 141 contextDirectoryManager = new AnalysisServerContextDirectoryManager(this, re sourceProvider); |
| 142 AnalysisEngine.instance.logger = new AnalysisLogger(); | 142 AnalysisEngine.instance.logger = new AnalysisLogger(); |
| 143 running = true; | 143 running = true; |
| 144 Notification notification = new Notification(SERVER_CONNECTED); | 144 Notification notification = new Notification(SERVER_CONNECTED); |
| 145 channel.sendNotification(notification); | 145 channel.sendNotification(notification); |
| 146 channel.listen(handleRequest, onDone: done, onError: error); | 146 channel.listen(handleRequest, onDone: done, onError: error); |
| 147 } | 147 } |
| 148 | 148 |
| 149 /** | 149 /** |
| 150 * Schedules execution of the given [ServerOperation]. | |
| 151 */ | |
| 152 void scheduleOperation(ServerOperation operation) { | |
| 153 bool wasEmpty = operationQueue.isEmpty; | |
| 154 addOperation(operation); | |
| 155 if (wasEmpty) { | |
| 156 _schedulePerformOperation(); | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 /** | |
| 150 * Schedules analysis of the given context. | 161 * Schedules analysis of the given context. |
| 151 */ | 162 */ |
| 152 void schedulePerformAnalysisOperation(AnalysisContext context) { | 163 void schedulePerformAnalysisOperation(AnalysisContext context) { |
| 153 scheduleOperation(new PerformAnalysisOperation(context, false)); | 164 scheduleOperation(new PerformAnalysisOperation(context, false)); |
| 154 } | 165 } |
| 155 | 166 |
| 156 /** | 167 /** |
| 157 * Schedules execution of the given [ServerOperation]. | 168 * Send the given [notification] to the client. |
| 158 */ | 169 */ |
| 159 void scheduleOperation(ServerOperation operation) { | 170 void sendNotification(Notification notification) { |
| 160 bool wasEmpty = operationQueue.isEmpty; | 171 channel.sendNotification(notification); |
| 161 addOperation(operation); | |
| 162 if (wasEmpty) { | |
| 163 _schedulePerformOperation(); | |
| 164 } | |
| 165 } | 172 } |
| 166 | 173 |
| 167 /** | 174 /** |
| 175 * Set the priority files to the given [files]. | |
| 176 */ | |
| 177 void setPriorityFiles(Request request, List<String> files) { | |
|
Paul Berry
2014/06/16 23:43:16
I don't think this algorithm will do the right thi
Brian Wilkerson
2014/06/17 17:46:16
Good catch! Thanks!
| |
| 178 Map<AnalysisContext, List<Source>> sourceMap = | |
| 179 new HashMap<AnalysisContext, List<Source>>(); | |
| 180 List<String> unanalyzed = new List<String>(); | |
| 181 files.forEach((file) { | |
| 182 AnalysisContext analysisContext = _getAnalysisContext(file); | |
| 183 if (analysisContext == null) { | |
| 184 unanalyzed.add(file); | |
| 185 } else { | |
| 186 List<Source> sourceList = sourceMap[analysisContext]; | |
| 187 if (sourceList == null) { | |
| 188 sourceList = <Source>[]; | |
| 189 sourceMap[analysisContext] = sourceList; | |
| 190 } | |
| 191 String uri = new Uri.file(file).toString(); | |
| 192 Source source = analysisContext.sourceFactory.forUri(uri); | |
| 193 sourceList.add(source); | |
| 194 } | |
| 195 }); | |
| 196 if (unanalyzed.isNotEmpty) { | |
| 197 StringBuffer buffer = new StringBuffer(); | |
| 198 buffer.writeAll(unanalyzed, ', '); | |
| 199 throw new RequestFailure(new Response.unanalyzedPriorityFiles(request, | |
| 200 buffer.toString())); | |
| 201 } | |
| 202 sourceMap.forEach((AnalysisContext context, List<Source> sourceList) { | |
| 203 context.analysisPriorityOrder = sourceList; | |
| 204 }); | |
| 205 } | |
| 206 | |
| 207 /** | |
| 168 * Adds the given [ServerOperation] to the queue, but does not schedule | 208 * Adds the given [ServerOperation] to the queue, but does not schedule |
| 169 * operations execution. | 209 * operations execution. |
| 170 */ | 210 */ |
| 171 void addOperation(ServerOperation operation) { | 211 void addOperation(ServerOperation operation) { |
| 172 operationQueue.add(operation); | 212 operationQueue.add(operation); |
| 173 } | 213 } |
| 174 | 214 |
| 175 /** | 215 /** |
| 176 * The socket from which requests are being read has been closed. | 216 * The socket from which requests are being read has been closed. |
| 177 */ | 217 */ |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 } | 444 } |
| 405 | 445 |
| 406 /** | 446 /** |
| 407 * Return `true` if all operations have been performed in this [AnalysisServer ]. | 447 * Return `true` if all operations have been performed in this [AnalysisServer ]. |
| 408 */ | 448 */ |
| 409 bool test_areOperationsFinished() { | 449 bool test_areOperationsFinished() { |
| 410 return operationQueue.isEmpty; | 450 return operationQueue.isEmpty; |
| 411 } | 451 } |
| 412 | 452 |
| 413 /** | 453 /** |
| 414 * Send the given [notification] to the client. | |
| 415 */ | |
| 416 void sendNotification(Notification notification) { | |
| 417 channel.sendNotification(notification); | |
| 418 } | |
| 419 | |
| 420 /** | |
| 421 * Schedules [performOperation] exection. | 454 * Schedules [performOperation] exection. |
| 422 */ | 455 */ |
| 423 void _schedulePerformOperation() { | 456 void _schedulePerformOperation() { |
| 424 new Future(performOperation); | 457 new Future(performOperation); |
| 425 } | 458 } |
| 426 } | 459 } |
| 427 | 460 |
| 428 | 461 |
| 429 /** | 462 /** |
| 430 * An enumeration of the services provided by the analysis domain. | 463 * An enumeration of the services provided by the analysis domain. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 /** | 522 /** |
| 490 * An enumeration of the services provided by the server domain. | 523 * An enumeration of the services provided by the server domain. |
| 491 */ | 524 */ |
| 492 class ServerService extends Enum2<ServerService> { | 525 class ServerService extends Enum2<ServerService> { |
| 493 static const ServerService STATUS = const ServerService('STATUS', 0); | 526 static const ServerService STATUS = const ServerService('STATUS', 0); |
| 494 | 527 |
| 495 static const List<ServerService> VALUES = const [STATUS]; | 528 static const List<ServerService> VALUES = const [STATUS]; |
| 496 | 529 |
| 497 const ServerService(String name, int ordinal) : super(name, ordinal); | 530 const ServerService(String name, int ordinal) : super(name, ordinal); |
| 498 } | 531 } |
| OLD | NEW |