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

Unified Diff: pkg/analyzer_plugin/doc/tutorial/outline.md

Issue 3002233002: Add utilities to support the outline notification (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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer_plugin/doc/tutorial/outline.md
diff --git a/pkg/analyzer_plugin/doc/tutorial/outline.md b/pkg/analyzer_plugin/doc/tutorial/outline.md
new file mode 100644
index 0000000000000000000000000000000000000000..c17c71c6133196e483fe330b69c562a702600989
--- /dev/null
+++ b/pkg/analyzer_plugin/doc/tutorial/outline.md
@@ -0,0 +1,80 @@
+# Providing Outlines
+
+Outline information is used by clients to allow users to see the structure of
+their code.
+
+## Implementation details
+
+Outline information can is available through a subscription. If the server has
scheglov 2017/08/24 18:29:20 "can" or "is"?
Brian Wilkerson 2017/08/24 18:52:46 Done ('is')
+subscribed for outline information in some set of files, the the plugin should
scheglov 2017/08/24 18:29:20 "the the" => "then the"?
Brian Wilkerson 2017/08/24 18:52:46 Done
+send the information in an `analysis.outline` notification whenever the
+information needs to be updated.
+
+When a notification needs to be sent, the method`sendOutlineNotification` will
+be invoked. This method is responsible for sending the notification.
+
+The easiest way to add support for this notification is by adding the classes
+`OutlineMixin` and `DartOutlineMixin` (from
+`package:analyzer_plugin/plugin/outline_mixin.dart`) to the list of mixins
+for your subclass of `ServerPlugin`. This will leave you with one abstract
+method that you need to implement: `getOutlineContributors`. That method is
+responsible for returning a list of `OutlineContributor`s. It is the outline
+contributors that produce the actual outline information. (Most plugins will
+only need a single outline contributor.)
+
+To write an outline contributor, create a class that implements
+`OutlineContributor`. The interface defines a single method named
+`computeOutline`. The method has two arguments: an `OutlineRequest` that
+describes the file for which outline information is being requested and an
+`OutlineCollector` through which outline information is to be added.
+
+If you mix in the class `DartOutlineMixin`, then the request will be an instance
+of `DartOutlineRequest`, which also has analysis results.
+
+## Example
+
+Start by creating a class that implements `OutlineContributor`, then
+implement the method `computeOutline`. This method is typically implemented
+by creating a visitor (such as an AstVisitor) that can visit the results of the
+analysis (such as a CompilationUnit) and extract the outline information from
+the analysis result.
+
+For example, your contributor might look something like the following:
+
+```dart
+class MyOutlineContributor implements OutlineContributor {
+ @override
+ void computeOutline(
+ OutlineRequest request, OutlineCollector collector) {
+ if (request is DartOutlineRequest) {
+ OutlineVisitor visitor = new OutlineVisitor(collector);
+ request.result.unit.accept(visitor);
+ }
+ }
+}
+
+class OutlineVisitor extends RecursiveAstVisitor {
+ final OutlineCollector collector;
+
+ OutlineVisitor(this.collector);
+
+ @override
+ void visitClassDeclaration(ClassDeclaration node) {
+ // ...
+ }
+}
+```
+
+Given a contributor like the one above, you can implement your plugin similar to
+the following:
+
+```dart
+class MyPlugin extends ServerPlugin with OutlineMixin, DartOutlineMixin {
+ // ...
+
+ @override
+ List<OutlineContributor> getOutlineContributors(String path) {
+ return <OutlineContributor>[new MyOutlineContributor()];
+ }
+}
+```

Powered by Google App Engine
This is Rietveld 408576698