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

Side by Side Diff: pkg/analysis_server/lib/src/domain_analysis.dart

Issue 2908633002: Make server forward getNavigation requests to 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 unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/get_navigation_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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/plugin/analysis/analysis_domain.dart'; 8 import 'package:analysis_server/plugin/analysis/analysis_domain.dart';
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/computer/computer_hover.dart'; 10 import 'package:analysis_server/src/computer/computer_hover.dart';
11 import 'package:analysis_server/src/constants.dart'; 11 import 'package:analysis_server/src/constants.dart';
12 import 'package:analysis_server/src/context_manager.dart'; 12 import 'package:analysis_server/src/context_manager.dart';
13 import 'package:analysis_server/src/domain_abstract.dart';
13 import 'package:analysis_server/src/domains/analysis/navigation.dart'; 14 import 'package:analysis_server/src/domains/analysis/navigation.dart';
14 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart'; 15 import 'package:analysis_server/src/domains/analysis/navigation_dart.dart';
15 import 'package:analysis_server/src/operation/operation_analysis.dart' 16 import 'package:analysis_server/src/operation/operation_analysis.dart'
16 show NavigationOperation, OccurrencesOperation; 17 show NavigationOperation, OccurrencesOperation;
18 import 'package:analysis_server/src/plugin/plugin_manager.dart';
17 import 'package:analysis_server/src/plugin/request_converter.dart'; 19 import 'package:analysis_server/src/plugin/request_converter.dart';
20 import 'package:analysis_server/src/plugin/result_merger.dart';
18 import 'package:analysis_server/src/protocol/protocol_internal.dart'; 21 import 'package:analysis_server/src/protocol/protocol_internal.dart';
19 import 'package:analysis_server/src/protocol_server.dart'; 22 import 'package:analysis_server/src/protocol_server.dart';
20 import 'package:analysis_server/src/services/dependencies/library_dependencies.d art'; 23 import 'package:analysis_server/src/services/dependencies/library_dependencies.d art';
21 import 'package:analysis_server/src/services/dependencies/reachable_source_colle ctor.dart'; 24 import 'package:analysis_server/src/services/dependencies/reachable_source_colle ctor.dart';
22 import 'package:analyzer/dart/ast/ast.dart'; 25 import 'package:analyzer/dart/ast/ast.dart';
23 import 'package:analyzer/dart/element/element.dart'; 26 import 'package:analyzer/dart/element/element.dart';
24 import 'package:analyzer/error/error.dart' as engine; 27 import 'package:analyzer/error/error.dart' as engine;
25 import 'package:analyzer/exception/exception.dart'; 28 import 'package:analyzer/exception/exception.dart';
26 import 'package:analyzer/file_system/file_system.dart'; 29 import 'package:analyzer/file_system/file_system.dart';
27 import 'package:analyzer/src/dart/analysis/driver.dart'; 30 import 'package:analyzer/src/dart/analysis/driver.dart';
28 import 'package:analyzer/src/generated/engine.dart' as engine; 31 import 'package:analyzer/src/generated/engine.dart' as engine;
29 import 'package:analyzer/src/generated/source.dart'; 32 import 'package:analyzer/src/generated/source.dart';
30 import 'package:analyzer/task/model.dart' show ResultDescriptor; 33 import 'package:analyzer/task/model.dart' show ResultDescriptor;
34 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
35 import 'package:analyzer_plugin/protocol/protocol_common.dart';
36 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin;
37 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
31 38
32 /** 39 /**
33 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] 40 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler]
34 * that handles requests in the `analysis` domain. 41 * that handles requests in the `analysis` domain.
35 */ 42 */
36 class AnalysisDomainHandler implements RequestHandler { 43 class AnalysisDomainHandler extends AbstractRequestHandler {
37 /**
38 * The analysis server that is using this handler to process requests.
39 */
40 final AnalysisServer server;
41
42 /** 44 /**
43 * Initialize a newly created handler to handle requests for the given [server ]. 45 * Initialize a newly created handler to handle requests for the given [server ].
44 */ 46 */
45 AnalysisDomainHandler(this.server) { 47 AnalysisDomainHandler(AnalysisServer server) : super(server) {
46 _callAnalysisDomainReceivers(); 48 _callAnalysisDomainReceivers();
47 } 49 }
48 50
49 /** 51 /**
50 * Implement the `analysis.getErrors` request. 52 * Implement the `analysis.getErrors` request.
51 */ 53 */
52 Future<Null> getErrors(Request request) async { 54 Future<Null> getErrors(Request request) async {
53 String file = new AnalysisGetErrorsParams.fromRequest(request).file; 55 String file = new AnalysisGetErrorsParams.fromRequest(request).file;
54 56
55 void send(engine.AnalysisOptions analysisOptions, LineInfo lineInfo, 57 void send(engine.AnalysisOptions analysisOptions, LineInfo lineInfo,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // delay response 153 // delay response
152 return Response.DELAYED_RESPONSE; 154 return Response.DELAYED_RESPONSE;
153 } 155 }
154 156
155 /** 157 /**
156 * Implement the `analysis.getNavigation` request. 158 * Implement the `analysis.getNavigation` request.
157 */ 159 */
158 Future<Null> getNavigation(Request request) async { 160 Future<Null> getNavigation(Request request) async {
159 var params = new AnalysisGetNavigationParams.fromRequest(request); 161 var params = new AnalysisGetNavigationParams.fromRequest(request);
160 String file = params.file; 162 String file = params.file;
163 int offset = params.offset;
164 int length = params.length;
161 165
162 if (server.options.enableNewAnalysisDriver) { 166 if (server.options.enableNewAnalysisDriver) {
163 AnalysisDriver driver = server.getAnalysisDriver(file); 167 AnalysisDriver driver = server.getAnalysisDriver(file);
164 if (driver == null) { 168 if (driver == null) {
165 server.sendResponse(new Response.getNavigationInvalidFile(request)); 169 server.sendResponse(new Response.getNavigationInvalidFile(request));
166 } else { 170 } else {
171 //
172 // Allow plugins to start computing navigation data.
173 //
174 plugin.AnalysisGetNavigationParams requestParams =
175 new plugin.AnalysisGetNavigationParams(file, offset, length);
176 Map<PluginInfo, Future<plugin.Response>> pluginFutures = server
177 .pluginManager
178 .broadcastRequest(requestParams, contextRoot: driver.contextRoot);
179 //
180 // Compute navigation data generated by server.
181 //
182 List<AnalysisNavigationParams> allResults =
183 <AnalysisNavigationParams>[];
167 AnalysisResult result = await server.getAnalysisResult(file); 184 AnalysisResult result = await server.getAnalysisResult(file);
168 CompilationUnit unit = result?.unit; 185 CompilationUnit unit = result?.unit;
169 if (unit == null || !result.exists) { 186 if (unit != null && result.exists) {
170 server.sendResponse(new Response.getNavigationInvalidFile(request)); 187 NavigationCollectorImpl collector = new NavigationCollectorImpl();
188 computeDartNavigation(collector, unit, offset, length);
189 collector.createRegions();
190 allResults.add(new AnalysisNavigationParams(
191 file, collector.regions, collector.targets, collector.files));
192 }
193 //
194 // Add the navigation data produced by plugins to the server-generated
195 // navigation data.
196 //
197 if (pluginFutures != null) {
198 List<plugin.Response> responses = await waitForResponses(
199 pluginFutures,
200 requestParameters: requestParams);
201 for (plugin.Response response in responses) {
202 plugin.AnalysisGetNavigationResult result =
203 new plugin.AnalysisGetNavigationResult.fromResponse(response);
204 allResults.add(new AnalysisNavigationParams(
205 file, result.regions, result.targets, result.files));
206 }
207 }
208 //
209 // Return the result.
210 //
211 ResultMerger merger = new ResultMerger();
212 AnalysisNavigationParams mergedResults =
213 merger.mergeNavigation(allResults);
214 if (mergedResults == null) {
215 server.sendResponse(new AnalysisGetNavigationResult(
216 <String>[], <NavigationTarget>[], <NavigationRegion>[])
217 .toResponse(request.id));
171 } else { 218 } else {
172 NavigationCollectorImpl collector = new NavigationCollectorImpl();
173 computeDartNavigation(collector, unit, params.offset, params.length);
174 collector.createRegions();
175 server.sendResponse(new AnalysisGetNavigationResult( 219 server.sendResponse(new AnalysisGetNavigationResult(
176 collector.files, collector.targets, collector.regions) 220 mergedResults.files,
221 mergedResults.targets,
222 mergedResults.regions)
177 .toResponse(request.id)); 223 .toResponse(request.id));
178 } 224 }
179 } 225 }
180 return; 226 return;
181 } 227 }
182 228
183 Future<AnalysisDoneReason> analysisFuture = 229 Future<AnalysisDoneReason> analysisFuture =
184 server.onFileAnalysisComplete(file); 230 server.onFileAnalysisComplete(file);
185 if (analysisFuture == null) { 231 if (analysisFuture == null) {
186 server.sendResponse(new Response.getNavigationInvalidFile(request)); 232 server.sendResponse(new Response.getNavigationInvalidFile(request));
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 context.onResultChanged(descriptor).listen((result) { 534 context.onResultChanged(descriptor).listen((result) {
489 StreamController<engine.ResultChangedEvent> controller = 535 StreamController<engine.ResultChangedEvent> controller =
490 controllers[result.descriptor]; 536 controllers[result.descriptor];
491 if (controller != null) { 537 if (controller != null) {
492 controller.add(result); 538 controller.add(result);
493 } 539 }
494 }); 540 });
495 } 541 }
496 } 542 }
497 } 543 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis/get_navigation_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698