Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: pkg/analyzer_plugin/lib/protocol/protocol.dart

Issue 2890163004: Add requestTime to responses (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 'package:analyzer_plugin/protocol/protocol_generated.dart'; 5 import 'package:analyzer_plugin/protocol/protocol_generated.dart';
6 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart'; 6 import 'package:analyzer_plugin/src/protocol/protocol_internal.dart';
7 7
8 /** 8 /**
9 * An interface for enumerated types in the protocol. 9 * An interface for enumerated types in the protocol.
10 * 10 *
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 RequestFailure(this.error); 333 RequestFailure(this.error);
334 } 334 }
335 335
336 /** 336 /**
337 * A response to the server. 337 * A response to the server.
338 * 338 *
339 * Clients may not extend, implement or mix-in this class. 339 * Clients may not extend, implement or mix-in this class.
340 */ 340 */
341 class Response { 341 class Response {
342 /** 342 /**
343 * The [Response] instance that is returned when a real [Response] cannot
344 * be provided at the moment.
345 */
346 static final Response DELAYED_RESPONSE = new Response('DELAYED_RESPONSE');
347
348 /**
349 * The name of the JSON attribute containing the id of the request for which 343 * The name of the JSON attribute containing the id of the request for which
350 * this is a response. 344 * this is a response.
351 */ 345 */
352 static const String ID = 'id'; 346 static const String ID = 'id';
353 347
354 /** 348 /**
355 * The name of the JSON attribute containing the error message. 349 * The name of the JSON attribute containing the error message.
356 */ 350 */
357 static const String ERROR = 'error'; 351 static const String ERROR = 'error';
358 352
359 /** 353 /**
354 * The name of the JSON attribute containing the time at which the request was
355 * handled by the plugin.
356 */
357 static const String REQUEST_TIME = 'requestTime';
358
359 /**
360 * The name of the JSON attribute containing the result values. 360 * The name of the JSON attribute containing the result values.
361 */ 361 */
362 static const String RESULT = 'result'; 362 static const String RESULT = 'result';
363 363
364 /** 364 /**
365 * The unique identifier used to identify the request that this response is 365 * The unique identifier used to identify the request that this response is
366 * associated with. 366 * associated with.
367 */ 367 */
368 final String id; 368 final String id;
369 369
370 /** 370 /**
371 * The error that was caused by attempting to handle the request, or `null` if 371 * The error that was caused by attempting to handle the request, or `null` if
372 * there was no error. 372 * there was no error.
373 */ 373 */
374 final RequestError error; 374 final RequestError error;
375 375
376 /** 376 /**
377 * The time at which the request was handled by the plugin.
378 */
379 final int requestTime;
380
381 /**
377 * A table mapping the names of result fields to their values. Should be 382 * A table mapping the names of result fields to their values. Should be
378 * `null` if there is no result to send. 383 * `null` if there is no result to send.
379 */ 384 */
380 Map<String, Object> result; 385 Map<String, Object> result;
381 386
382 /** 387 /**
383 * Initialize a newly created instance to represent a response to a request 388 * Initialize a newly created instance to represent a response to a request
384 * with the given [id]. If [_result] is provided, it will be used as the 389 * with the given [id]. If [_result] is provided, it will be used as the
385 * result; otherwise an empty result will be used. If an [error] is provided 390 * result; otherwise an empty result will be used. If an [error] is provided
386 * then the response will represent an error condition. 391 * then the response will represent an error condition.
387 */ 392 */
388 Response(this.id, {Map<String, Object> result, this.error}) : result = result; 393 Response(this.id, this.requestTime, {this.error, Map<String, Object> result})
389 394 : result = result;
390 // /**
391 // * Initialize a newly created instance to represent the FILE_NOT_ANALYZED
392 // * error condition.
393 // */
394 // Response.fileNotAnalyzed(Request request, String file)
395 // : this(request.id,
396 // error: new RequestError(RequestErrorCode.FILE_NOT_ANALYZED,
397 // 'File is not analyzed: $file.'));
398 //
399 // /**
400 // * Initialize a newly created instance to represent the FORMAT_INVALID_FILE
401 // * error condition.
402 // */
403 // Response.formatInvalidFile(Request request)
404 // : this(request.id,
405 // error: new RequestError(RequestErrorCode.FORMAT_INVALID_FILE,
406 // 'Error during `edit.format`: invalid file.'));
407 //
408 // /**
409 // * Initialize a newly created instance to represent the FORMAT_WITH_ERROR
410 // * error condition.
411 // */
412 // Response.formatWithErrors(Request request)
413 // : this(request.id,
414 // error: new RequestError(RequestErrorCode.FORMAT_WITH_ERRORS,
415 // 'Error during `edit.format`: source contains syntax errors.'));
416 395
417 /** 396 /**
418 * Initialize a newly created instance based on the given JSON data. 397 * Initialize a newly created instance based on the given JSON data.
419 */ 398 */
420 factory Response.fromJson(Map json) { 399 factory Response.fromJson(Map json) {
421 try { 400 try {
422 Object id = json[Response.ID]; 401 Object id = json[ID];
423 if (id is! String) { 402 if (id is! String) {
424 return null; 403 return null;
425 } 404 }
426 Object error = json[Response.ERROR]; 405 Object error = json[ERROR];
427 RequestError decodedError; 406 RequestError decodedError;
428 if (error is Map) { 407 if (error is Map) {
429 decodedError = new RequestError.fromJson( 408 decodedError = new RequestError.fromJson(
430 new ResponseDecoder(null), '.error', error); 409 new ResponseDecoder(null), '.error', error);
431 } 410 }
432 Object result = json[Response.RESULT]; 411 Object requestTime = json[REQUEST_TIME];
412 if (requestTime is! int) {
413 return null;
414 }
415 Object result = json[RESULT];
433 Map<String, Object> decodedResult; 416 Map<String, Object> decodedResult;
434 if (result is Map) { 417 if (result is Map) {
435 decodedResult = result as Map<String, Object>; 418 decodedResult = result as Map<String, Object>;
436 } 419 }
437 return new Response(id, error: decodedError, result: decodedResult); 420 return new Response(id, requestTime,
421 error: decodedError, result: decodedResult);
438 } catch (exception) { 422 } catch (exception) {
439 return null; 423 return null;
440 } 424 }
441 } 425 }
442 426
443 /** 427 /**
444 * Return a table representing the structure of the Json object that will be 428 * Return a table representing the structure of the Json object that will be
445 * sent to the client to represent this response. 429 * sent to the client to represent this response.
446 */ 430 */
447 Map<String, Object> toJson() { 431 Map<String, Object> toJson() {
448 Map<String, Object> jsonObject = <String, Object>{}; 432 Map<String, Object> jsonObject = <String, Object>{};
449 jsonObject[ID] = id; 433 jsonObject[ID] = id;
450 if (error != null) { 434 if (error != null) {
451 jsonObject[ERROR] = error.toJson(); 435 jsonObject[ERROR] = error.toJson();
452 } 436 }
437 jsonObject[REQUEST_TIME] = requestTime;
453 if (result != null) { 438 if (result != null) {
454 jsonObject[RESULT] = result; 439 jsonObject[RESULT] = result;
455 } 440 }
456 return jsonObject; 441 return jsonObject;
457 } 442 }
458 } 443 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/lib/plugin/plugin.dart ('k') | pkg/analyzer_plugin/lib/protocol/protocol_generated.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698