| 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 | 8 |
| 9 import 'package:analysis_server/src/analysis_logger.dart'; | 9 import 'package:analysis_server/src/analysis_logger.dart'; |
| 10 import 'package:analysis_server/src/channel.dart'; | 10 import 'package:analysis_server/src/channel.dart'; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 */ | 59 */ |
| 60 final List<AnalysisContext> contextWorkQueue = new List<AnalysisContext>(); | 60 final List<AnalysisContext> contextWorkQueue = new List<AnalysisContext>(); |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Initialize a newly created server to receive requests from and send | 63 * Initialize a newly created server to receive requests from and send |
| 64 * responses to the given [channel]. | 64 * responses to the given [channel]. |
| 65 */ | 65 */ |
| 66 AnalysisServer(this.channel) { | 66 AnalysisServer(this.channel) { |
| 67 AnalysisEngine.instance.logger = new AnalysisLogger(); | 67 AnalysisEngine.instance.logger = new AnalysisLogger(); |
| 68 running = true; | 68 running = true; |
| 69 // TODO set running=false on done or error | 69 channel.listen(handleRequest, onDone: done, onError: error); |
| 70 channel.listen(handleRequest); | |
| 71 } | 70 } |
| 72 | 71 |
| 73 /** | 72 /** |
| 74 * Add the given [context] to the list of analysis contexts for which analysis | 73 * Add the given [context] to the list of analysis contexts for which analysis |
| 75 * work needs to be performed. Ensure that the work will be performed. | 74 * work needs to be performed. Ensure that the work will be performed. |
| 76 */ | 75 */ |
| 77 void addContextToWorkQueue(AnalysisContext context) { | 76 void addContextToWorkQueue(AnalysisContext context) { |
| 78 if (!contextWorkQueue.contains(context)) { | 77 if (!contextWorkQueue.contains(context)) { |
| 79 contextWorkQueue.add(context); | 78 contextWorkQueue.add(context); |
| 80 run(); | 79 run(); |
| 81 } | 80 } |
| 82 } | 81 } |
| 83 | 82 |
| 84 /** | 83 /** |
| 85 * The socket from which requests are being read has been closed. | 84 * The socket from which requests are being read has been closed. |
| 86 */ | 85 */ |
| 87 void done() { | 86 void done() { |
| 88 running = false; | 87 running = false; |
| 89 } | 88 } |
| 90 | 89 |
| 91 /** | 90 /** |
| 92 * There was an error related to the socket from which requests are being | 91 * There was an error related to the socket from which requests are being |
| 93 * read. | 92 * read. |
| 94 */ | 93 */ |
| 95 void error() { | 94 void error(argument) { |
| 96 running = false; | 95 running = false; |
| 97 } | 96 } |
| 98 | 97 |
| 99 /** | 98 /** |
| 100 * Handle a [request] that was read from the communication channel. | 99 * Handle a [request] that was read from the communication channel. |
| 101 */ | 100 */ |
| 102 void handleRequest(Request request) { | 101 void handleRequest(Request request) { |
| 103 int count = handlers.length; | 102 int count = handlers.length; |
| 104 for (int i = 0; i < count; i++) { | 103 for (int i = 0; i < count; i++) { |
| 105 Response response = handlers[i].handleRequest(request); | 104 try { |
| 106 if (response != null) { | 105 Response response = handlers[i].handleRequest(request); |
| 107 channel.sendResponse(response); | 106 if (response != null) { |
| 107 channel.sendResponse(response); |
| 108 return; |
| 109 } |
| 110 } on RequestFailure catch (exception) { |
| 111 channel.sendResponse(exception.response); |
| 108 return; | 112 return; |
| 109 } | 113 } |
| 110 } | 114 } |
| 111 channel.sendResponse(new Response.unknownRequest(request)); | 115 channel.sendResponse(new Response.unknownRequest(request)); |
| 112 } | 116 } |
| 113 | 117 |
| 114 /** | 118 /** |
| 115 * Perform the next available task. If a request was received that has not yet | 119 * Perform the next available task. If a request was received that has not yet |
| 116 * been performed, perform it next. Otherwise, look for some analysis that | 120 * been performed, perform it next. Otherwise, look for some analysis that |
| 117 * needs to be done and do that. Otherwise, do nothing. | 121 * needs to be done and do that. Otherwise, do nothing. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 172 } |
| 169 } | 173 } |
| 170 | 174 |
| 171 /** | 175 /** |
| 172 * Send the given [notification] to the client. | 176 * Send the given [notification] to the client. |
| 173 */ | 177 */ |
| 174 void sendNotification(Notification notification) { | 178 void sendNotification(Notification notification) { |
| 175 channel.sendNotification(notification); | 179 channel.sendNotification(notification); |
| 176 } | 180 } |
| 177 } | 181 } |
| OLD | NEW |