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

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

Issue 3003573002: Add minimal support for sending notifications (Closed)
Patch Set: Created 3 years, 4 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
« no previous file with comments | « no previous file | pkg/analyzer_plugin/test/plugin/mocks.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analyzer/dart/analysis/results.dart';
7 import 'package:analyzer/file_system/file_system.dart'; 8 import 'package:analyzer/file_system/file_system.dart';
8 import 'package:analyzer/file_system/physical_file_system.dart'; 9 import 'package:analyzer/file_system/physical_file_system.dart';
9 import 'package:analyzer/src/dart/analysis/byte_store.dart'; 10 import 'package:analyzer/src/dart/analysis/byte_store.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart' 11 import 'package:analyzer/src/dart/analysis/driver.dart'
11 show AnalysisDriverGeneric, AnalysisDriverScheduler; 12 show AnalysisDriverGeneric, AnalysisDriverScheduler;
12 import 'package:analyzer/src/dart/analysis/file_byte_store.dart'; 13 import 'package:analyzer/src/dart/analysis/file_byte_store.dart';
13 import 'package:analyzer/src/dart/analysis/file_state.dart'; 14 import 'package:analyzer/src/dart/analysis/file_state.dart';
14 import 'package:analyzer/src/dart/analysis/performance_logger.dart'; 15 import 'package:analyzer/src/dart/analysis/performance_logger.dart';
15 import 'package:analyzer/src/generated/sdk.dart'; 16 import 'package:analyzer/src/generated/sdk.dart';
16 import 'package:analyzer_plugin/channel/channel.dart'; 17 import 'package:analyzer_plugin/channel/channel.dart';
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 */ 421 */
421 void onDone() {} 422 void onDone() {}
422 423
423 /** 424 /**
424 * The method that is called when an error has occurred in the analysis 425 * The method that is called when an error has occurred in the analysis
425 * server. This method will not be invoked under normal conditions. 426 * server. This method will not be invoked under normal conditions.
426 */ 427 */
427 void onError(Object exception, StackTrace stackTrace) {} 428 void onError(Object exception, StackTrace stackTrace) {}
428 429
429 /** 430 /**
430 * Send notifications corresponding to the given description of subscriptions. 431 * If the plugin provides folding information, send a folding notification
431 * The map is keyed by the path of each file for which notifications should be 432 * for the file with the given [path] to the server.
432 * sent and has values representing the list of services associated with the 433 *
433 * notifications to send. 434 * If a [result] is provided then it is expected to be the result of analyzing
435 * the file at the given [path].
436 */
437 Future<Null> sendFoldingNotification(String path, {ResolveResult result}) {
438 return new Future.value();
439 }
440
441 /**
442 * If the plugin provides highlighting information, send a highlights
443 * notification for the file with the given [path] to the server.
444 *
445 * If a [result] is provided then it is expected to be the result of analyzing
446 * the file at the given [path].
447 */
448 Future<Null> sendHighlightsNotification(String path, {ResolveResult result}) {
scheglov 2017/08/22 17:55:27 I think `result` must be a required parameter in a
Brian Wilkerson 2017/08/22 18:33:15 For performance reasons? In spite of the fact that
scheglov 2017/08/22 18:49:21 Well, you're probably right. It's OK with me to ke
Brian Wilkerson 2017/08/23 14:06:43 But we need to keep them? If I've understood Mike
449 return new Future.value();
450 }
451
452 /**
453 * If the plugin provides navigation information, send a navigation
454 * notification for the file with the given [path] to the server.
455 *
456 * If a [result] is provided then it is expected to be the result of analyzing
457 * the file at the given [path].
458 */
459 Future<Null> sendNavigationNotification(String path, {ResolveResult result}) {
460 return new Future.value();
461 }
462
463 /**
464 * Send notifications for the services subscribed to for the file with the
465 * given [path].
466 *
467 * If a [result] is provided then it is expected to be the result of analyzing
468 * the file at the given [path].
469 *
470 * This is a convenience method that subclasses can use to send notifications
471 * after analysis has been performed on a file.
472 */
473 void sendNotificationsForFile(String path, {ResolveResult result}) {
474 for (AnalysisService service in subscriptionManager.servicesForFile(path)) {
475 _sendNotificationForFile(path, service, result: result);
476 }
477 }
478
479 /**
480 * Send notifications corresponding to the given description of
481 * [subscriptions]. The map is keyed by the path of each file for which
482 * notifications should be sent and has values representing the list of
483 * services associated with the notifications to send.
484 *
485 * This method is used when the set of subscribed notifications has been
486 * changed and notifications need to be sent even when the specified files
487 * have already been analyzed.
434 */ 488 */
435 void sendNotificationsForSubscriptions( 489 void sendNotificationsForSubscriptions(
436 Map<String, List<AnalysisService>> subscriptions); 490 Map<String, List<AnalysisService>> subscriptions) {
491 subscriptions.forEach((String path, List<AnalysisService> services) {
492 for (AnalysisService service in services) {
493 _sendNotificationForFile(path, service);
494 }
495 });
496 }
497
498 /**
499 * If the plugin provides occurrences information, send an occurrences
500 * notification for the file with the given [path] to the server.
501 *
502 * If a [result] is provided then it is expected to be the result of analyzing
503 * the file at the given [path].
504 */
505 Future<Null> sendOccurrencesNotification(String path,
506 {ResolveResult result}) {
507 return new Future.value();
508 }
509
510 /**
511 * If the plugin provides outline information, send an outline notification
512 * for the file with the given [path] to the server.
513 *
514 * If a [result] is provided then it is expected to be the result of analyzing
515 * the file at the given [path].
516 */
517 Future<Null> sendOutlineNotification(String path, {ResolveResult result}) {
518 return new Future.value();
519 }
437 520
438 /** 521 /**
439 * Start this plugin by listening to the given communication [channel]. 522 * Start this plugin by listening to the given communication [channel].
440 */ 523 */
441 void start(PluginCommunicationChannel channel) { 524 void start(PluginCommunicationChannel channel) {
442 _channel = channel; 525 _channel = channel;
443 _channel.listen(_onRequest, onError: onError, onDone: onDone); 526 _channel.listen(_onRequest, onError: onError, onDone: onDone);
444 } 527 }
445 528
446 /** 529 /**
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } catch (exception, stackTrace) { 638 } catch (exception, stackTrace) {
556 response = new Response(id, requestTime, 639 response = new Response(id, requestTime,
557 error: new RequestError( 640 error: new RequestError(
558 RequestErrorCode.PLUGIN_ERROR, exception.toString(), 641 RequestErrorCode.PLUGIN_ERROR, exception.toString(),
559 stackTrace: stackTrace.toString())); 642 stackTrace: stackTrace.toString()));
560 } 643 }
561 if (response != null) { 644 if (response != null) {
562 _channel.sendResponse(response); 645 _channel.sendResponse(response);
563 } 646 }
564 } 647 }
648
649 /**
650 * Send a notification for the file at the given [path] corresponding to the
651 * given [service].
652 *
653 * If a [result] is provided then it is expected to be the result of analyzing
654 * the file at the given [path].
655 */
656 void _sendNotificationForFile(String path, AnalysisService service,
657 {ResolveResult result}) {
658 switch (service) {
659 case AnalysisService.FOLDING:
660 sendFoldingNotification(path, result: result);
661 break;
662 case AnalysisService.HIGHLIGHTS:
663 sendHighlightsNotification(path, result: result);
664 break;
665 case AnalysisService.NAVIGATION:
666 sendNavigationNotification(path, result: result);
667 break;
668 case AnalysisService.OCCURRENCES:
669 sendOccurrencesNotification(path, result: result);
670 break;
671 case AnalysisService.OUTLINE:
672 sendOutlineNotification(path, result: result);
673 break;
674 }
675 }
565 } 676 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer_plugin/test/plugin/mocks.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698