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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:core'; 6 import 'dart:core';
7 7
8 import 'package:analysis_server/protocol/protocol.dart'; 8 import 'package:analysis_server/protocol/protocol.dart';
9 import 'package:analysis_server/protocol/protocol_constants.dart'; 9 import 'package:analysis_server/protocol/protocol_constants.dart';
10 import 'package:analysis_server/protocol/protocol_generated.dart'; 10 import 'package:analysis_server/protocol/protocol_generated.dart';
11 import 'package:analysis_server/src/analysis_server.dart'; 11 import 'package:analysis_server/src/analysis_server.dart';
12 import 'package:analysis_server/src/domain_abstract.dart';
13 import 'package:analysis_server/src/plugin/plugin_manager.dart';
14 import 'package:analysis_server/src/plugin/result_merger.dart';
12 import 'package:analysis_server/src/services/kythe/kythe_visitors.dart'; 15 import 'package:analysis_server/src/services/kythe/kythe_visitors.dart';
16 import 'package:analyzer/dart/ast/ast.dart';
13 import 'package:analyzer/src/dart/analysis/driver.dart'; 17 import 'package:analyzer/src/dart/analysis/driver.dart';
14 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; 18 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart';
19 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
15 import 'package:analyzer_plugin/protocol/protocol_common.dart'; 20 import 'package:analyzer_plugin/protocol/protocol_common.dart';
21 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin;
22 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
16 23
17 /** 24 /**
18 * Instances of the class [KytheDomainHandler] implement a [RequestHandler] 25 * Instances of the class [KytheDomainHandler] implement a [RequestHandler]
19 * that handles requests in the `kythe` domain. 26 * that handles requests in the `kythe` domain.
20 */ 27 */
21 class KytheDomainHandler implements RequestHandler { 28 class KytheDomainHandler extends AbstractRequestHandler {
22 /**
23 * The analysis server that is using this handler to process requests.
24 */
25 final AnalysisServer server;
26
27 /** 29 /**
28 * Initialize a newly created handler to handle requests for the given [server ]. 30 * Initialize a newly created handler to handle requests for the given [server ].
29 */ 31 */
30 KytheDomainHandler(this.server); 32 KytheDomainHandler(AnalysisServer server) : super(server);
31 33
32 /** 34 /**
33 * Implement the `kythe.getKytheEntries` request. 35 * Implement the `kythe.getKytheEntries` request.
34 */ 36 */
35 Future<Null> getKytheEntries(Request request) async { 37 Future<Null> getKytheEntries(Request request) async {
36 String file = new KytheGetKytheEntriesParams.fromRequest(request).file; 38 String file = new KytheGetKytheEntriesParams.fromRequest(request).file;
37 AnalysisResult result = await server.getAnalysisResult(file); 39 AnalysisDriver driver = server.getAnalysisDriver(file);
38 List<KytheEntry> entries = <KytheEntry>[]; 40 if (driver == null) {
39 // TODO(brianwilkerson) Figure out how to get the list of files. 41 server.sendResponse(new Response.getKytheEntriesInvalidFile(request));
40 List<String> files = <String>[]; 42 } else {
41 result.unit.accept(new KytheDartVisitor([] /*entries*/, file, 43 //
42 new InheritanceManager(result.libraryElement), result.content)); 44 // Allow plugins to start computing entries.
43 server.sendResponse( 45 //
44 new KytheGetKytheEntriesResult(entries, files).toResponse(request.id)); 46 plugin.KytheGetKytheEntriesParams requestParams =
47 new plugin.KytheGetKytheEntriesParams(file);
48 Map<PluginInfo, Future<plugin.Response>> pluginFutures = server
49 .pluginManager
50 .broadcastRequest(requestParams, contextRoot: driver.contextRoot);
51 //
52 // Compute entries generated by server.
53 //
54 List<KytheGetKytheEntriesResult> allResults =
55 <KytheGetKytheEntriesResult>[];
56 AnalysisResult result = await server.getAnalysisResult(file);
57 CompilationUnit unit = result?.unit;
58 if (unit != null && result.exists) {
59 List<KytheEntry> entries = <KytheEntry>[];
60 // TODO(brianwilkerson) Figure out how to get the list of files.
61 List<String> files = <String>[];
62 result.unit.accept(new KytheDartVisitor(entries, file,
63 new InheritanceManager(result.libraryElement), result.content));
64 allResults.add(new KytheGetKytheEntriesResult(entries, files));
65 }
66 //
67 // Add the entries produced by plugins to the server-generated entries.
68 //
69 if (pluginFutures != null) {
70 List<plugin.Response> responses = await waitForResponses(pluginFutures,
71 requestParameters: requestParams);
72 for (plugin.Response response in responses) {
73 plugin.KytheGetKytheEntriesResult result =
74 new plugin.KytheGetKytheEntriesResult.fromResponse(response);
75 allResults.add(
76 new KytheGetKytheEntriesResult(result.entries, result.files));
77 }
78 }
79 //
80 // Return the result.
81 //
82 ResultMerger merger = new ResultMerger();
83 KytheGetKytheEntriesResult mergedResults =
84 merger.mergeKytheEntries(allResults);
85 if (mergedResults == null) {
86 server.sendResponse(
87 new KytheGetKytheEntriesResult(<KytheEntry>[], <String>[])
88 .toResponse(request.id));
89 } else {
90 server.sendResponse(new KytheGetKytheEntriesResult(
91 mergedResults.entries, mergedResults.files)
92 .toResponse(request.id));
93 }
94 }
45 } 95 }
46 96
47 @override 97 @override
48 Response handleRequest(Request request) { 98 Response handleRequest(Request request) {
49 try { 99 try {
50 String requestName = request.method; 100 String requestName = request.method;
51 if (requestName == KYTHE_REQUEST_GET_KYTHE_ENTRIES) { 101 if (requestName == KYTHE_REQUEST_GET_KYTHE_ENTRIES) {
52 getKytheEntries(request); 102 getKytheEntries(request);
53 return Response.DELAYED_RESPONSE; 103 return Response.DELAYED_RESPONSE;
54 } 104 }
55 } on RequestFailure catch (exception) { 105 } on RequestFailure catch (exception) {
56 return exception.response; 106 return exception.response;
57 } 107 }
58 return null; 108 return null;
59 } 109 }
60 } 110 }
OLDNEW
« 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