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

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

Issue 1232683003: Issue 23640. Implement 'analysis.getNavigation' request. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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) 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 library domain.analysis; 5 library domain.analysis;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
9 9
10 import 'package:analysis_server/src/analysis_server.dart'; 10 import 'package:analysis_server/src/analysis_server.dart';
11 import 'package:analysis_server/src/computer/computer_hover.dart'; 11 import 'package:analysis_server/src/computer/computer_hover.dart';
12 import 'package:analysis_server/src/computer/computer_navigation.dart';
12 import 'package:analysis_server/src/constants.dart'; 13 import 'package:analysis_server/src/constants.dart';
13 import 'package:analysis_server/src/protocol_server.dart'; 14 import 'package:analysis_server/src/protocol_server.dart';
14 import 'package:analysis_server/src/services/dependencies/library_dependencies.d art'; 15 import 'package:analysis_server/src/services/dependencies/library_dependencies.d art';
15 import 'package:analyzer/file_system/file_system.dart'; 16 import 'package:analyzer/file_system/file_system.dart';
16 import 'package:analyzer/src/generated/ast.dart'; 17 import 'package:analyzer/src/generated/ast.dart';
17 import 'package:analyzer/src/generated/engine.dart' as engine; 18 import 'package:analyzer/src/generated/engine.dart' as engine;
18 19
19 /** 20 /**
20 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] 21 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler]
21 * that handles requests in the `analysis` domain. 22 * that handles requests in the `analysis` domain.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 Map<String, Map<String, List<String>>> packageMap = 99 Map<String, Map<String, List<String>>> packageMap =
99 collector.calculatePackageMap(server.folderMap); 100 collector.calculatePackageMap(server.folderMap);
100 server.sendResponse(new AnalysisGetLibraryDependenciesResult( 101 server.sendResponse(new AnalysisGetLibraryDependenciesResult(
101 libraries.toList(growable: false), packageMap) 102 libraries.toList(growable: false), packageMap)
102 .toResponse(request.id)); 103 .toResponse(request.id));
103 }); 104 });
104 // delay response 105 // delay response
105 return Response.DELAYED_RESPONSE; 106 return Response.DELAYED_RESPONSE;
106 } 107 }
107 108
109 /**
110 * Implement the `analysis.getNavigation` request.
111 */
112 Response getNavigation(Request request) {
113 var params = new AnalysisGetNavigationParams.fromRequest(request);
114 String file = params.file;
115 int offset = params.offset;
116 Future<AnalysisDoneReason> completionFuture =
117 server.onFileAnalysisComplete(file);
118 if (completionFuture == null) {
119 return new Response.getNavigationInvalidFile(request);
120 }
121 completionFuture.then((AnalysisDoneReason reason) {
122 switch (reason) {
123 case AnalysisDoneReason.COMPLETE:
124 List<CompilationUnit> units =
125 server.getResolvedCompilationUnits(file);
126 if (units.isEmpty) {
127 server.sendResponse(new Response.getNavigationInvalidFile(request));
128 } else {
129 DartUnitNavigationComputer computer =
130 new DartUnitNavigationComputer();
131 for (CompilationUnit unit in units) {
132 AstNode node = new NodeLocator(offset).searchWithin(unit);
133 if (node != null) {
134 computer.compute(node);
135 }
136 }
137 server.sendResponse(new AnalysisGetNavigationResult(
138 computer.files, computer.targets, computer.regions)
139 .toResponse(request.id));
140 }
141 break;
142 case AnalysisDoneReason.CONTEXT_REMOVED:
143 // The active contexts have changed, so try again.
144 Response response = getNavigation(request);
145 if (response != Response.DELAYED_RESPONSE) {
146 server.sendResponse(response);
147 }
148 break;
149 }
150 });
151 // delay response
152 return Response.DELAYED_RESPONSE;
153 }
154
108 @override 155 @override
109 Response handleRequest(Request request) { 156 Response handleRequest(Request request) {
110 try { 157 try {
111 String requestName = request.method; 158 String requestName = request.method;
112 if (requestName == ANALYSIS_GET_ERRORS) { 159 if (requestName == ANALYSIS_GET_ERRORS) {
113 return getErrors(request); 160 return getErrors(request);
114 } else if (requestName == ANALYSIS_GET_HOVER) { 161 } else if (requestName == ANALYSIS_GET_HOVER) {
115 return getHover(request); 162 return getHover(request);
116 } else if (requestName == ANALYSIS_GET_LIBRARY_DEPENDENCIES) { 163 } else if (requestName == ANALYSIS_GET_LIBRARY_DEPENDENCIES) {
117 return getLibraryDependencies(request); 164 return getLibraryDependencies(request);
165 } else if (requestName == ANALYSIS_GET_NAVIGATION) {
166 return getNavigation(request);
118 } else if (requestName == ANALYSIS_REANALYZE) { 167 } else if (requestName == ANALYSIS_REANALYZE) {
119 return reanalyze(request); 168 return reanalyze(request);
120 } else if (requestName == ANALYSIS_SET_ANALYSIS_ROOTS) { 169 } else if (requestName == ANALYSIS_SET_ANALYSIS_ROOTS) {
121 return setAnalysisRoots(request); 170 return setAnalysisRoots(request);
122 } else if (requestName == ANALYSIS_SET_PRIORITY_FILES) { 171 } else if (requestName == ANALYSIS_SET_PRIORITY_FILES) {
123 return setPriorityFiles(request); 172 return setPriorityFiles(request);
124 } else if (requestName == ANALYSIS_SET_SUBSCRIPTIONS) { 173 } else if (requestName == ANALYSIS_SET_SUBSCRIPTIONS) {
125 return setSubscriptions(request); 174 return setSubscriptions(request);
126 } else if (requestName == ANALYSIS_UPDATE_CONTENT) { 175 } else if (requestName == ANALYSIS_UPDATE_CONTENT) {
127 return updateContent(request); 176 return updateContent(request);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 273 }
225 if (newOptions.generateLints != null) { 274 if (newOptions.generateLints != null) {
226 updaters.add((engine.AnalysisOptionsImpl options) { 275 updaters.add((engine.AnalysisOptionsImpl options) {
227 options.lint = newOptions.generateLints; 276 options.lint = newOptions.generateLints;
228 }); 277 });
229 } 278 }
230 server.updateOptions(updaters); 279 server.updateOptions(updaters);
231 return new AnalysisUpdateOptionsResult().toResponse(request.id); 280 return new AnalysisUpdateOptionsResult().toResponse(request.id);
232 } 281 }
233 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698