| 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) { |
| 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 sourceList.add(_getSource(file)); |
| 192 } |
| 193 }); |
| 194 if (unanalyzed.isNotEmpty) { |
| 195 StringBuffer buffer = new StringBuffer(); |
| 196 buffer.writeAll(unanalyzed, ', '); |
| 197 throw new RequestFailure(new Response.unanalyzedPriorityFiles(request, |
| 198 buffer.toString())); |
| 199 } |
| 200 folderMap.forEach((Folder folder, ContextDirectory directory) { |
| 201 AnalysisContext context = directory.context; |
| 202 List<Source> sourceList = sourceMap[context]; |
| 203 if (sourceList == null) { |
| 204 sourceList = Source.EMPTY_ARRAY; |
| 205 } |
| 206 context.analysisPriorityOrder = sourceList; |
| 207 }); |
| 208 } |
| 209 |
| 210 /** |
| 168 * Adds the given [ServerOperation] to the queue, but does not schedule | 211 * Adds the given [ServerOperation] to the queue, but does not schedule |
| 169 * operations execution. | 212 * operations execution. |
| 170 */ | 213 */ |
| 171 void addOperation(ServerOperation operation) { | 214 void addOperation(ServerOperation operation) { |
| 172 operationQueue.add(operation); | 215 operationQueue.add(operation); |
| 173 } | 216 } |
| 174 | 217 |
| 175 /** | 218 /** |
| 176 * The socket from which requests are being read has been closed. | 219 * The socket from which requests are being read has been closed. |
| 177 */ | 220 */ |
| 178 void done() { | 221 void done() { |
| 179 running = false; | 222 running = false; |
| 180 } | 223 } |
| 181 | 224 |
| 182 /** | 225 /** |
| 183 * There was an error related to the socket from which requests are being | 226 * There was an error related to the socket from which requests are being |
| 184 * read. | 227 * read. |
| 185 */ | 228 */ |
| 186 void error(argument) { | 229 void error(argument) { |
| 187 running = false; | 230 running = false; |
| 188 } | 231 } |
| 189 | 232 |
| 233 // TODO(brianwilkerson) Add the following method after 'prioritySources' has |
| 234 // been added to InternalAnalysisContext. |
| 235 // /** |
| 236 // * Return a list containing the full names of all of the sources that are |
| 237 // * priority sources. |
| 238 // */ |
| 239 // List<String> getPriorityFiles() { |
| 240 // List<String> priorityFiles = new List<String>(); |
| 241 // folderMap.values.forEach((ContextDirectory directory) { |
| 242 // InternalAnalysisContext context = directory.context; |
| 243 // context.prioritySources.forEach((Source source) { |
| 244 // priorityFiles.add(source.fullName); |
| 245 // }); |
| 246 // }); |
| 247 // return priorityFiles; |
| 248 // } |
| 249 |
| 190 /** | 250 /** |
| 191 * Handle a [request] that was read from the communication channel. | 251 * Handle a [request] that was read from the communication channel. |
| 192 */ | 252 */ |
| 193 void handleRequest(Request request) { | 253 void handleRequest(Request request) { |
| 194 int count = handlers.length; | 254 int count = handlers.length; |
| 195 for (int i = 0; i < count; i++) { | 255 for (int i = 0; i < count; i++) { |
| 196 try { | 256 try { |
| 197 Response response = handlers[i].handleRequest(request); | 257 Response response = handlers[i].handleRequest(request); |
| 198 if (response != null) { | 258 if (response != null) { |
| 199 channel.sendResponse(response); | 259 channel.sendResponse(response); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 } | 464 } |
| 405 | 465 |
| 406 /** | 466 /** |
| 407 * Return `true` if all operations have been performed in this [AnalysisServer
]. | 467 * Return `true` if all operations have been performed in this [AnalysisServer
]. |
| 408 */ | 468 */ |
| 409 bool test_areOperationsFinished() { | 469 bool test_areOperationsFinished() { |
| 410 return operationQueue.isEmpty; | 470 return operationQueue.isEmpty; |
| 411 } | 471 } |
| 412 | 472 |
| 413 /** | 473 /** |
| 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. | 474 * Schedules [performOperation] exection. |
| 422 */ | 475 */ |
| 423 void _schedulePerformOperation() { | 476 void _schedulePerformOperation() { |
| 424 new Future(performOperation); | 477 new Future(performOperation); |
| 425 } | 478 } |
| 426 } | 479 } |
| 427 | 480 |
| 428 | 481 |
| 429 /** | 482 /** |
| 430 * An enumeration of the services provided by the analysis domain. | 483 * An enumeration of the services provided by the analysis domain. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 /** | 542 /** |
| 490 * An enumeration of the services provided by the server domain. | 543 * An enumeration of the services provided by the server domain. |
| 491 */ | 544 */ |
| 492 class ServerService extends Enum2<ServerService> { | 545 class ServerService extends Enum2<ServerService> { |
| 493 static const ServerService STATUS = const ServerService('STATUS', 0); | 546 static const ServerService STATUS = const ServerService('STATUS', 0); |
| 494 | 547 |
| 495 static const List<ServerService> VALUES = const [STATUS]; | 548 static const List<ServerService> VALUES = const [STATUS]; |
| 496 | 549 |
| 497 const ServerService(String name, int ordinal) : super(name, ordinal); | 550 const ServerService(String name, int ordinal) : super(name, ordinal); |
| 498 } | 551 } |
| OLD | NEW |