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:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 Set<ServerService> serverServices = new HashSet<ServerService>(); | 159 Set<ServerService> serverServices = new HashSet<ServerService>(); |
| 160 | 160 |
| 161 /** | 161 /** |
| 162 * A table mapping [AnalysisService]s to the file paths for which these | 162 * A table mapping [AnalysisService]s to the file paths for which these |
| 163 * notifications should be sent. | 163 * notifications should be sent. |
| 164 */ | 164 */ |
| 165 Map<AnalysisService, Set<String>> analysisServices = | 165 Map<AnalysisService, Set<String>> analysisServices = |
| 166 new HashMap<AnalysisService, Set<String>>(); | 166 new HashMap<AnalysisService, Set<String>>(); |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * A table mapping [AnalysisContext]s to the completers that should be | |
| 170 * completed when analysis of this context is finished. | |
| 171 */ | |
| 172 Map<AnalysisContext, Completer> contextAnalysisDoneCompleters = | |
| 173 new HashMap<AnalysisContext, Completer>(); | |
| 174 | |
| 175 /** | |
| 169 * True if any exceptions thrown by analysis should be propagated up the call | 176 * True if any exceptions thrown by analysis should be propagated up the call |
| 170 * stack. | 177 * stack. |
| 171 */ | 178 */ |
| 172 bool rethrowExceptions; | 179 bool rethrowExceptions; |
| 173 | 180 |
| 174 /** | 181 /** |
| 175 * Initialize a newly created server to receive requests from and send | 182 * Initialize a newly created server to receive requests from and send |
| 176 * responses to the given [channel]. | 183 * responses to the given [channel]. |
| 177 * | 184 * |
| 178 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are | 185 * If [rethrowExceptions] is true, then any exceptions thrown by analysis are |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 } | 220 } |
| 214 | 221 |
| 215 /** | 222 /** |
| 216 * Send the given [notification] to the client. | 223 * Send the given [notification] to the client. |
| 217 */ | 224 */ |
| 218 void sendNotification(Notification notification) { | 225 void sendNotification(Notification notification) { |
| 219 channel.sendNotification(notification); | 226 channel.sendNotification(notification); |
| 220 } | 227 } |
| 221 | 228 |
| 222 /** | 229 /** |
| 230 * Send the given [response] to the client. | |
| 231 */ | |
| 232 void sendResponse(Response response) { | |
| 233 channel.sendResponse(response); | |
| 234 } | |
| 235 | |
| 236 /** | |
| 223 * Set the priority files to the given [files]. | 237 * Set the priority files to the given [files]. |
| 224 */ | 238 */ |
| 225 void setPriorityFiles(Request request, List<String> files) { | 239 void setPriorityFiles(Request request, List<String> files) { |
| 226 Map<AnalysisContext, List<Source>> sourceMap = | 240 Map<AnalysisContext, List<Source>> sourceMap = |
| 227 new HashMap<AnalysisContext, List<Source>>(); | 241 new HashMap<AnalysisContext, List<Source>>(); |
| 228 List<String> unanalyzed = new List<String>(); | 242 List<String> unanalyzed = new List<String>(); |
| 229 files.forEach((file) { | 243 files.forEach((file) { |
| 230 AnalysisContext analysisContext = getAnalysisContext(file); | 244 AnalysisContext analysisContext = getAnalysisContext(file); |
| 231 if (analysisContext == null) { | 245 if (analysisContext == null) { |
| 232 unanalyzed.add(file); | 246 unanalyzed.add(file); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 // } | 334 // } |
| 321 | 335 |
| 322 /** | 336 /** |
| 323 * Handle a [request] that was read from the communication channel. | 337 * Handle a [request] that was read from the communication channel. |
| 324 */ | 338 */ |
| 325 void handleRequest(Request request) { | 339 void handleRequest(Request request) { |
| 326 int count = handlers.length; | 340 int count = handlers.length; |
| 327 for (int i = 0; i < count; i++) { | 341 for (int i = 0; i < count; i++) { |
| 328 try { | 342 try { |
| 329 Response response = handlers[i].handleRequest(request); | 343 Response response = handlers[i].handleRequest(request); |
| 344 if (response == Response.DELAYED_RESPONSE) { | |
| 345 return; | |
| 346 } | |
| 330 if (response != null) { | 347 if (response != null) { |
| 331 channel.sendResponse(response); | 348 channel.sendResponse(response); |
| 332 return; | 349 return; |
| 333 } | 350 } |
| 334 } on RequestFailure catch (exception) { | 351 } on RequestFailure catch (exception) { |
| 335 channel.sendResponse(exception.response); | 352 channel.sendResponse(exception.response); |
| 336 return; | 353 return; |
| 337 } | 354 } |
| 338 } | 355 } |
| 339 channel.sendResponse(new Response.unknownRequest(request)); | 356 channel.sendResponse(new Response.unknownRequest(request)); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 AstNode node = new NodeLocator.con1(offset).searchWithin(unit); | 627 AstNode node = new NodeLocator.con1(offset).searchWithin(unit); |
| 611 Element element = ElementLocator.locateWithOffset(node, offset); | 628 Element element = ElementLocator.locateWithOffset(node, offset); |
| 612 if (element != null) { | 629 if (element != null) { |
| 613 elements.add(element); | 630 elements.add(element); |
| 614 } | 631 } |
| 615 } | 632 } |
| 616 return elements; | 633 return elements; |
| 617 } | 634 } |
| 618 | 635 |
| 619 /** | 636 /** |
| 637 * Returns a [Future] completing when [file] has been completely analyzed, in | |
| 638 * particular, all its errors have been computed. | |
| 639 */ | |
| 640 Future onFileAnalysisComplete(String file) { | |
| 641 // prepare AnalysisContext | |
|
Paul Berry
2014/07/22 21:10:24
I can see three areas where we might want to impro
scheglov
2014/07/22 21:23:24
Unfortunately, there is no mechanism in the analys
| |
| 642 AnalysisContext context = getAnalysisContext(file); | |
| 643 if (context == null) { | |
| 644 return new Future.value(); | |
| 645 } | |
| 646 // schedule context analysis | |
| 647 schedulePerformAnalysisOperation(context); | |
| 648 // associate with the context completer | |
| 649 Completer completer = contextAnalysisDoneCompleters[context]; | |
| 650 if (completer == null) { | |
| 651 completer = new Completer(); | |
| 652 contextAnalysisDoneCompleters[context] = completer; | |
| 653 } | |
| 654 return completer.future; | |
| 655 } | |
| 656 | |
| 657 /** | |
| 658 * This method is called when analysis of the given [AnalysisContext] is | |
| 659 * done. | |
| 660 */ | |
| 661 void sendContextAnalysisDoneNotifications(AnalysisContext context) { | |
| 662 Completer completer = contextAnalysisDoneCompleters[context]; | |
| 663 if (completer != null) { | |
| 664 completer.complete(); | |
| 665 } | |
| 666 } | |
| 667 | |
| 668 /** | |
| 620 * Return the [CompilationUnit] of the Dart file with the given [path]. | 669 * Return the [CompilationUnit] of the Dart file with the given [path]. |
| 621 * Return `null` if the file is not a part of any context. | 670 * Return `null` if the file is not a part of any context. |
| 622 */ | 671 */ |
| 623 CompilationUnit test_getResolvedCompilationUnit(String path) { | 672 CompilationUnit test_getResolvedCompilationUnit(String path) { |
| 624 // prepare AnalysisContext | 673 // prepare AnalysisContext |
| 625 AnalysisContext context = getAnalysisContext(path); | 674 AnalysisContext context = getAnalysisContext(path); |
| 626 if (context == null) { | 675 if (context == null) { |
| 627 return null; | 676 return null; |
| 628 } | 677 } |
| 629 // prepare sources | 678 // prepare sources |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 675 /** | 724 /** |
| 676 * An enumeration of the services provided by the server domain. | 725 * An enumeration of the services provided by the server domain. |
| 677 */ | 726 */ |
| 678 class ServerService extends Enum2<ServerService> { | 727 class ServerService extends Enum2<ServerService> { |
| 679 static const ServerService STATUS = const ServerService('STATUS', 0); | 728 static const ServerService STATUS = const ServerService('STATUS', 0); |
| 680 | 729 |
| 681 static const List<ServerService> VALUES = const [STATUS]; | 730 static const List<ServerService> VALUES = const [STATUS]; |
| 682 | 731 |
| 683 const ServerService(String name, int ordinal) : super(name, ordinal); | 732 const ServerService(String name, int ordinal) : super(name, ordinal); |
| 684 } | 733 } |
| OLD | NEW |