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

Unified Diff: pkg/analysis_server/lib/src/domain_kythe.dart

Issue 3000823002: Forward Kythe requests to plugins and merge in the results (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/analysis_server/lib/src/domain_kythe.dart
diff --git a/pkg/analysis_server/lib/src/domain_kythe.dart b/pkg/analysis_server/lib/src/domain_kythe.dart
index a369f3d7158cdf2538d1742a2e360d9ea144b80d..cbe971cc2ef44a16795a1107b5fe6768980009df 100644
--- a/pkg/analysis_server/lib/src/domain_kythe.dart
+++ b/pkg/analysis_server/lib/src/domain_kythe.dart
@@ -9,39 +9,89 @@ import 'package:analysis_server/protocol/protocol.dart';
import 'package:analysis_server/protocol/protocol_constants.dart';
import 'package:analysis_server/protocol/protocol_generated.dart';
import 'package:analysis_server/src/analysis_server.dart';
+import 'package:analysis_server/src/domain_abstract.dart';
+import 'package:analysis_server/src/plugin/plugin_manager.dart';
+import 'package:analysis_server/src/plugin/result_merger.dart';
import 'package:analysis_server/src/services/kythe/kythe_visitors.dart';
+import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/resolver/inheritance_manager.dart';
+import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
import 'package:analyzer_plugin/protocol/protocol_common.dart';
+import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin;
+import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
/**
* Instances of the class [KytheDomainHandler] implement a [RequestHandler]
* that handles requests in the `kythe` domain.
*/
-class KytheDomainHandler implements RequestHandler {
- /**
- * The analysis server that is using this handler to process requests.
- */
- final AnalysisServer server;
-
+class KytheDomainHandler extends AbstractRequestHandler {
/**
* Initialize a newly created handler to handle requests for the given [server].
*/
- KytheDomainHandler(this.server);
+ KytheDomainHandler(AnalysisServer server) : super(server);
/**
* Implement the `kythe.getKytheEntries` request.
*/
Future<Null> getKytheEntries(Request request) async {
String file = new KytheGetKytheEntriesParams.fromRequest(request).file;
- AnalysisResult result = await server.getAnalysisResult(file);
- List<KytheEntry> entries = <KytheEntry>[];
- // TODO(brianwilkerson) Figure out how to get the list of files.
- List<String> files = <String>[];
- result.unit.accept(new KytheDartVisitor([] /*entries*/, file,
- new InheritanceManager(result.libraryElement), result.content));
- server.sendResponse(
- new KytheGetKytheEntriesResult(entries, files).toResponse(request.id));
+ AnalysisDriver driver = server.getAnalysisDriver(file);
+ if (driver == null) {
+ server.sendResponse(new Response.getKytheEntriesInvalidFile(request));
+ } else {
+ //
+ // Allow plugins to start computing entries.
+ //
+ plugin.KytheGetKytheEntriesParams requestParams =
+ new plugin.KytheGetKytheEntriesParams(file);
+ Map<PluginInfo, Future<plugin.Response>> pluginFutures = server
+ .pluginManager
+ .broadcastRequest(requestParams, contextRoot: driver.contextRoot);
+ //
+ // Compute entries generated by server.
+ //
+ List<KytheGetKytheEntriesResult> allResults =
+ <KytheGetKytheEntriesResult>[];
+ AnalysisResult result = await server.getAnalysisResult(file);
+ CompilationUnit unit = result?.unit;
+ if (unit != null && result.exists) {
+ List<KytheEntry> entries = <KytheEntry>[];
+ // TODO(brianwilkerson) Figure out how to get the list of files.
+ List<String> files = <String>[];
+ result.unit.accept(new KytheDartVisitor(entries, file,
+ new InheritanceManager(result.libraryElement), result.content));
+ allResults.add(new KytheGetKytheEntriesResult(entries, files));
+ }
+ //
+ // Add the entries produced by plugins to the server-generated entries.
+ //
+ if (pluginFutures != null) {
+ List<plugin.Response> responses = await waitForResponses(pluginFutures,
+ requestParameters: requestParams);
+ for (plugin.Response response in responses) {
+ plugin.KytheGetKytheEntriesResult result =
+ new plugin.KytheGetKytheEntriesResult.fromResponse(response);
+ allResults.add(
+ new KytheGetKytheEntriesResult(result.entries, result.files));
+ }
+ }
+ //
+ // Return the result.
+ //
+ ResultMerger merger = new ResultMerger();
+ KytheGetKytheEntriesResult mergedResults =
+ merger.mergeKytheEntries(allResults);
+ if (mergedResults == null) {
+ server.sendResponse(
+ new KytheGetKytheEntriesResult(<KytheEntry>[], <String>[])
+ .toResponse(request.id));
+ } else {
+ server.sendResponse(new KytheGetKytheEntriesResult(
+ mergedResults.entries, mergedResults.files)
+ .toResponse(request.id));
+ }
+ }
}
@override
« no previous file with comments | « pkg/analysis_server/lib/protocol/protocol_generated.dart ('k') | pkg/analysis_server/lib/src/plugin/result_merger.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698