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

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

Issue 3004733002: Add folding support for plugins and update the main tutorial page (Closed)
Patch Set: Created 3 years, 3 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
(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/folding/folding.dart';
12 import 'package:analyzer_plugin/utilities/folding/folding.dart';
13 import 'package:analyzer_plugin/utilities/generator.dart';
14
15 /**
16 * A mixin that can be used when creating a subclass of [ServerPlugin] and
17 * mixing in [FoldingMixin]. This implements the creation of the folding
18 * request based on the assumption that the driver being created is an
19 * [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 * [FoldingMixin] as a mix-in.
24 */
25 abstract class DartFoldingMixin implements FoldingMixin {
26 @override
27 Future<FoldingRequest> getFoldingRequest(String path) async {
28 ResolveResult result = await getResolveResult(path);
29 return new DartFoldingRequestImpl(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 folding 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 FoldingMixin implements ServerPlugin {
41 /**
42 * Return a list containing the folding contributors that should be used
43 * to create folding regions for the file with the given [path].
44 */
45 List<FoldingContributor> getFoldingContributors(String path);
46
47 /**
48 * Return the folding request that should be passes to the contributors
49 * returned from [getFoldingContributors].
50 *
51 * Throw a [RequestFailure] if the request could not be created.
52 */
53 Future<FoldingRequest> getFoldingRequest(String path);
54
55 @override
56 Future<Null> sendFoldingNotification(String path) async {
57 try {
58 FoldingRequest request = await getFoldingRequest(path);
59 FoldingGenerator generator =
60 new FoldingGenerator(getFoldingContributors(path));
61 GeneratorResult generatorResult =
62 await generator.generateFoldingNotification(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 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/doc/tutorial/tutorial.md ('k') | pkg/analyzer_plugin/lib/src/utilities/folding/folding.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698