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

Unified Diff: pkg/analyzer_plugin/lib/utilities/assist/assist.dart

Issue 2924063002: Add support for implementing getAssists in plugins (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « pkg/analyzer_plugin/lib/src/utilities/assist/assist.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_plugin/lib/utilities/assist/assist.dart
diff --git a/pkg/analyzer_plugin/lib/utilities/assist/assist.dart b/pkg/analyzer_plugin/lib/utilities/assist/assist.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e68db53eb5076a27d6e6784c9718eebbc51d9c8b
--- /dev/null
+++ b/pkg/analyzer_plugin/lib/utilities/assist/assist.dart
@@ -0,0 +1,103 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analyzer/dart/analysis/results.dart';
+import 'package:analyzer/file_system/file_system.dart';
+import 'package:analyzer_plugin/protocol/protocol.dart';
+import 'package:analyzer_plugin/protocol/protocol_generated.dart';
+import 'package:analyzer_plugin/src/utilities/assist/assist.dart';
+import 'package:analyzer_plugin/utilities/generator.dart';
+
+/**
+ * An object that [AssistContributor]s use to record assists.
+ *
+ * Clients may not extend, implement or mix-in this class.
+ */
+abstract class AssistCollector {
+ /**
+ * Record a new [assist].
+ */
+ void addAssist(PrioritizedSourceChange assist);
+}
+
+/**
+ * An object used to produce assists.
+ *
+ * Clients may implement this class when implementing plugins.
+ */
+abstract class AssistContributor {
+ /**
+ * Contribute assists for the location in the file specified by the given
+ * [request] into the given [collector].
+ */
+ void computeFixes(AssistRequest request, AssistCollector collector);
scheglov 2017/06/07 16:09:19 computeAssists() ?
+}
+
+/**
+ * A generator that will generate an 'edit.getAssists' response.
+ *
+ * Clients may not extend, implement or mix-in this class.
+ */
+class AssistGenerator {
+ /**
+ * The contributors to be used to generate the assists.
+ */
+ final List<AssistContributor> contributors;
+
+ /**
+ * Initialize a newly created assists generator to use the given
+ * [contributors].
+ */
+ AssistGenerator(this.contributors);
+
+ /**
+ * Create an 'edit.getAssists' response for the location in the file specified
+ * by the given [request]. If any of the contributors throws an exception,
+ * also create a non-fatal 'plugin.error' notification.
+ */
+ GeneratorResult generateAssistsResponse(AssistRequest request) {
+ List<Notification> notifications = <Notification>[];
+ AssistCollectorImpl collector = new AssistCollectorImpl();
+ for (AssistContributor contributor in contributors) {
+ try {
+ contributor.computeFixes(request, collector);
+ } catch (exception, stackTrace) {
+ notifications.add(new PluginErrorParams(
+ false, exception.toString(), stackTrace.toString())
+ .toNotification());
+ }
+ }
+ EditGetAssistsResult result = new EditGetAssistsResult(collector.assists);
+ return new GeneratorResult(result, notifications);
+ }
+}
+
+/**
+ * The information about a requested set of assists.
+ *
+ * Clients may not extend, implement or mix-in this class.
+ */
+abstract class AssistRequest {
+ /**
+ * Return the length of the selection within the source for which assists are
+ * being requested.
+ */
+ int get length;
+
+ /**
+ * Return the offset of the selection within the source for which assists are
+ * being requested.
+ */
+ int get offset;
+
+ /**
+ * Return the resource provider associated with this request.
+ */
+ ResourceProvider get resourceProvider;
+
+ /**
+ * The analysis result for the file in which the assists are being requested.
+ */
+ ResolveResult get result;
+}
« no previous file with comments | « pkg/analyzer_plugin/lib/src/utilities/assist/assist.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698