OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
8 import 'package:analyzer/file_system/physical_file_system.dart'; | 8 import 'package:analyzer/file_system/physical_file_system.dart'; |
9 import 'package:analyzer/src/dart/analysis/driver.dart' | 9 import 'package:analyzer/src/dart/analysis/driver.dart' |
10 show AnalysisDriverGeneric, AnalysisDriverScheduler; | 10 show AnalysisDriverGeneric, AnalysisDriverScheduler; |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } on FileSystemException { | 482 } on FileSystemException { |
483 // The folder does not exist, so ignore it. | 483 // The folder does not exist, so ignore it. |
484 } | 484 } |
485 } | 485 } |
486 } | 486 } |
487 | 487 |
488 /** | 488 /** |
489 * Compute the response that should be returned for the given [request], or | 489 * Compute the response that should be returned for the given [request], or |
490 * `null` if the response has already been sent. | 490 * `null` if the response has already been sent. |
491 */ | 491 */ |
492 Future<Response> _getResponse(Request request) async { | 492 Future<Response> _getResponse(Request request, int requestTime) async { |
493 ResponseResult result = null; | 493 ResponseResult result = null; |
494 switch (request.method) { | 494 switch (request.method) { |
495 case ANALYSIS_REQUEST_HANDLE_WATCH_EVENTS: | 495 case ANALYSIS_REQUEST_HANDLE_WATCH_EVENTS: |
496 var params = new AnalysisHandleWatchEventsParams.fromRequest(request); | 496 var params = new AnalysisHandleWatchEventsParams.fromRequest(request); |
497 result = await handleAnalysisHandleWatchEvents(params); | 497 result = await handleAnalysisHandleWatchEvents(params); |
498 break; | 498 break; |
499 case ANALYSIS_REQUEST_REANALYZE: | 499 case ANALYSIS_REQUEST_REANALYZE: |
500 var params = new AnalysisReanalyzeParams.fromRequest(request); | 500 var params = new AnalysisReanalyzeParams.fromRequest(request); |
501 result = await handleAnalysisReanalyze(params); | 501 result = await handleAnalysisReanalyze(params); |
502 break; | 502 break; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 var params = new EditGetFixesParams.fromRequest(request); | 538 var params = new EditGetFixesParams.fromRequest(request); |
539 result = await handleEditGetFixes(params); | 539 result = await handleEditGetFixes(params); |
540 break; | 540 break; |
541 case EDIT_REQUEST_GET_REFACTORING: | 541 case EDIT_REQUEST_GET_REFACTORING: |
542 var params = new EditGetRefactoringParams.fromRequest(request); | 542 var params = new EditGetRefactoringParams.fromRequest(request); |
543 result = await handleEditGetRefactoring(params); | 543 result = await handleEditGetRefactoring(params); |
544 break; | 544 break; |
545 case PLUGIN_REQUEST_SHUTDOWN: | 545 case PLUGIN_REQUEST_SHUTDOWN: |
546 var params = new PluginShutdownParams(); | 546 var params = new PluginShutdownParams(); |
547 result = await handlePluginShutdown(params); | 547 result = await handlePluginShutdown(params); |
548 _channel.sendResponse(result.toResponse(request.id)); | 548 _channel.sendResponse(result.toResponse(request.id, requestTime)); |
549 _channel.close(); | 549 _channel.close(); |
550 return null; | 550 return null; |
551 case PLUGIN_REQUEST_VERSION_CHECK: | 551 case PLUGIN_REQUEST_VERSION_CHECK: |
552 var params = new PluginVersionCheckParams.fromRequest(request); | 552 var params = new PluginVersionCheckParams.fromRequest(request); |
553 result = await handlePluginVersionCheck(params); | 553 result = await handlePluginVersionCheck(params); |
554 break; | 554 break; |
555 } | 555 } |
556 if (result == null) { | 556 if (result == null) { |
557 return new Response(request.id, | 557 return new Response(request.id, requestTime, |
558 error: RequestErrorFactory.unknownRequest(request.method)); | 558 error: RequestErrorFactory.unknownRequest(request.method)); |
559 } | 559 } |
560 return result.toResponse(request.id); | 560 return result.toResponse(request.id, requestTime); |
561 } | 561 } |
562 | 562 |
563 /** | 563 /** |
564 * The method that is called when a [request] is received from the analysis | 564 * The method that is called when a [request] is received from the analysis |
565 * server. | 565 * server. |
566 */ | 566 */ |
567 Future<Null> _onRequest(Request request) async { | 567 Future<Null> _onRequest(Request request) async { |
| 568 int requestTime = new DateTime.now().millisecondsSinceEpoch; |
568 String id = request.id; | 569 String id = request.id; |
569 Response response; | 570 Response response; |
570 try { | 571 try { |
571 response = await _getResponse(request); | 572 response = await _getResponse(request, requestTime); |
572 } on RequestFailure catch (exception) { | 573 } on RequestFailure catch (exception) { |
573 response = new Response(id, error: exception.error); | 574 response = new Response(id, requestTime, error: exception.error); |
574 } catch (exception, stackTrace) { | 575 } catch (exception, stackTrace) { |
575 response = new Response(id, | 576 response = new Response(id, requestTime, |
576 error: new RequestError( | 577 error: new RequestError( |
577 RequestErrorCode.PLUGIN_ERROR, exception.toString(), | 578 RequestErrorCode.PLUGIN_ERROR, exception.toString(), |
578 stackTrace: stackTrace.toString())); | 579 stackTrace: stackTrace.toString())); |
579 } | 580 } |
580 if (response != null) { | 581 if (response != null) { |
581 _channel.sendResponse(response); | 582 _channel.sendResponse(response); |
582 } | 583 } |
583 } | 584 } |
584 } | 585 } |
OLD | NEW |