OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:async'; |
| 6 |
| 7 import 'package:analyzer/dart/analysis/results.dart'; |
| 8 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 9 import 'package:analyzer_plugin/plugin/plugin.dart'; |
| 10 import 'package:analyzer_plugin/protocol/protocol.dart'; |
| 11 import 'package:analyzer_plugin/src/utilities/highlights/highlights.dart'; |
| 12 import 'package:analyzer_plugin/utilities/generator.dart'; |
| 13 import 'package:analyzer_plugin/utilities/highlights/highlights.dart'; |
| 14 |
| 15 /** |
| 16 * A mixin that can be used when creating a subclass of [ServerPlugin] and |
| 17 * mixing in [HighlightsMixin]. This implements the creation of the |
| 18 * highlighting request based on the assumption that the driver being created is |
| 19 * an [AnalysisDriver]. |
| 20 * |
| 21 * Clients may not extend or implement this class, but are allowed to use it as |
| 22 * a mix-in when creating a subclass of [ServerPlugin] that also uses |
| 23 * [HighlightsMixin] as a mix-in. |
| 24 */ |
| 25 abstract class DartHighlightsMixin implements HighlightsMixin { |
| 26 @override |
| 27 Future<HighlightsRequest> getHighlightsRequest(String path) async { |
| 28 ResolveResult result = await getResolveResult(path); |
| 29 return new DartHighlightsRequestImpl(resourceProvider, result); |
| 30 } |
| 31 } |
| 32 |
| 33 /** |
| 34 * A mixin that can be used when creating a subclass of [ServerPlugin] to |
| 35 * provide most of the implementation for producing highlighting notifications. |
| 36 * |
| 37 * Clients may not extend or implement this class, but are allowed to use it as |
| 38 * a mix-in when creating a subclass of [ServerPlugin]. |
| 39 */ |
| 40 abstract class HighlightsMixin implements ServerPlugin { |
| 41 /** |
| 42 * Return a list containing the highlighting contributors that should be used |
| 43 * to create highlighting information for the file with the given [path]. |
| 44 */ |
| 45 List<HighlightsContributor> getHighlightsContributors(String path); |
| 46 |
| 47 /** |
| 48 * Return the highlighting request that should be passes to the contributors |
| 49 * returned from [getHighlightsContributors]. |
| 50 * |
| 51 * Throw a [RequestFailure] if the request could not be created. |
| 52 */ |
| 53 Future<HighlightsRequest> getHighlightsRequest(String path); |
| 54 |
| 55 @override |
| 56 Future<Null> sendHighlightsNotification(String path) async { |
| 57 try { |
| 58 HighlightsRequest request = await getHighlightsRequest(path); |
| 59 HighlightsGenerator generator = |
| 60 new HighlightsGenerator(getHighlightsContributors(path)); |
| 61 GeneratorResult generatorResult = |
| 62 await generator.generateHighlightsNotification(request); |
| 63 generatorResult.sendNotifications(channel); |
| 64 } on RequestFailure { |
| 65 // If we couldn't analyze the file, then don't send a notification. |
| 66 } |
| 67 } |
| 68 } |
OLD | NEW |