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

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

Issue 407263002: Implementation of the 'analysis.getErrors' API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
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:collection'; 7 import 'dart:collection';
8 8
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/operation/operation_analysis.dart';
12 import 'package:analysis_server/src/protocol.dart'; 13 import 'package:analysis_server/src/protocol.dart';
13 import 'package:analysis_services/constants.dart'; 14 import 'package:analysis_services/constants.dart';
15 import 'package:analyzer/src/generated/ast.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 16 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/ast.dart'; 17 import 'package:analyzer/src/generated/error.dart';
16 18
17 /** 19 /**
18 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] 20 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler]
19 * that handles requests in the `analysis` domain. 21 * that handles requests in the `analysis` domain.
20 */ 22 */
21 class AnalysisDomainHandler implements RequestHandler { 23 class AnalysisDomainHandler implements RequestHandler {
22 /** 24 /**
23 * The analysis server that is using this handler to process requests. 25 * The analysis server that is using this handler to process requests.
24 */ 26 */
25 final AnalysisServer server; 27 final AnalysisServer server;
26 28
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 AnalysisDomainHandler(this.server); 32 AnalysisDomainHandler(this.server);
31 33
32 /** 34 /**
35 * Implement the `analysis.getErrors` request.
36 */
37 Response getErrors(Request request) {
38 String file = request.getRequiredParameter(FILE).asString();
39 server.onFileAnalysisComplete(file).then((_) {
40 Response response = new Response(request.id);
41 AnalysisErrorInfo errorInfo = server.getErrors(file);
42 if (errorInfo == null) {
43 response.setResult(ERRORS, []);
44 } else {
45 response.setResult(ERRORS, errorInfo.errors.map((AnalysisError error) {
46 return errorToJson(errorInfo.lineInfo, error);
47 }).toList());
48 }
49 server.sendResponse(response);
50 });
51 // delay response
52 return Response.DELAYED_RESPONSE;
53 }
54
55 /**
33 * Implement the `analysis.getHover` request. 56 * Implement the `analysis.getHover` request.
34 */ 57 */
35 Response getAnalysisHover(Request request) { 58 Response getHover(Request request) {
36 // prepare parameters 59 // prepare parameters
37 String file = request.getRequiredParameter(FILE).asString(); 60 String file = request.getRequiredParameter(FILE).asString();
38 int offset = request.getRequiredParameter(OFFSET).asInt(); 61 int offset = request.getRequiredParameter(OFFSET).asInt();
39 // prepare hovers 62 // prepare hovers
40 List<Hover> hovers = <Hover>[]; 63 List<Hover> hovers = <Hover>[];
41 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 64 List<CompilationUnit> units = server.getResolvedCompilationUnits(file);
42 for (CompilationUnit unit in units) { 65 for (CompilationUnit unit in units) {
43 Hover hoverInformation = new DartUnitHoverComputer(unit, offset).compute() ; 66 Hover hoverInformation =
67 new DartUnitHoverComputer(unit, offset).compute();
44 if (hoverInformation != null) { 68 if (hoverInformation != null) {
45 hovers.add(hoverInformation); 69 hovers.add(hoverInformation);
46 } 70 }
47 } 71 }
48 // send response 72 // send response
49 Response response = new Response(request.id); 73 Response response = new Response(request.id);
50 response.setResult(HOVERS, hovers); 74 response.setResult(HOVERS, hovers);
51 return response; 75 return response;
52 } 76 }
53 77
54 @override 78 @override
55 Response handleRequest(Request request) { 79 Response handleRequest(Request request) {
56 try { 80 try {
57 String requestName = request.method; 81 String requestName = request.method;
58 if (requestName == ANALYSIS_GET_HOVER) { 82 if (requestName == ANALYSIS_GET_ERRORS) {
59 return getAnalysisHover(request); 83 return getErrors(request);
84 } else if (requestName == ANALYSIS_GET_HOVER) {
85 return getHover(request);
60 } else if (requestName == ANALYSIS_SET_ANALYSIS_ROOTS) { 86 } else if (requestName == ANALYSIS_SET_ANALYSIS_ROOTS) {
61 return setAnalysisRoots(request); 87 return setAnalysisRoots(request);
62 } else if (requestName == ANALYSIS_SET_PRIORITY_FILES) { 88 } else if (requestName == ANALYSIS_SET_PRIORITY_FILES) {
63 return setPriorityFiles(request); 89 return setPriorityFiles(request);
64 } else if (requestName == ANALYSIS_SET_SUBSCRIPTIONS) { 90 } else if (requestName == ANALYSIS_SET_SUBSCRIPTIONS) {
65 return setSubscriptions(request); 91 return setSubscriptions(request);
66 } else if (requestName == ANALYSIS_UPDATE_CONTENT) { 92 } else if (requestName == ANALYSIS_UPDATE_CONTENT) {
67 return updateContent(request); 93 return updateContent(request);
68 } else if (requestName == ANALYSIS_UPDATE_OPTIONS) { 94 } else if (requestName == ANALYSIS_UPDATE_OPTIONS) {
69 return updateOptions(request); 95 return updateOptions(request);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 * Implement the 'analysis.setSubscriptions' request. 132 * Implement the 'analysis.setSubscriptions' request.
107 */ 133 */
108 Response setSubscriptions(Request request) { 134 Response setSubscriptions(Request request) {
109 // parse subscriptions 135 // parse subscriptions
110 Map<AnalysisService, Set<String>> subMap; 136 Map<AnalysisService, Set<String>> subMap;
111 { 137 {
112 RequestDatum subDatum = request.getRequiredParameter(SUBSCRIPTIONS); 138 RequestDatum subDatum = request.getRequiredParameter(SUBSCRIPTIONS);
113 Map<String, List<String>> subStringMap = subDatum.asStringListMap(); 139 Map<String, List<String>> subStringMap = subDatum.asStringListMap();
114 subMap = new HashMap<AnalysisService, Set<String>>(); 140 subMap = new HashMap<AnalysisService, Set<String>>();
115 subStringMap.forEach((String serviceName, List<String> paths) { 141 subStringMap.forEach((String serviceName, List<String> paths) {
116 AnalysisService service = Enum2.valueOf(AnalysisService.VALUES, 142 AnalysisService service =
117 serviceName); 143 Enum2.valueOf(AnalysisService.VALUES, serviceName);
118 if (service == null) { 144 if (service == null) {
119 throw new RequestFailure(new Response.unknownAnalysisService(request, 145 throw new RequestFailure(
120 serviceName)); 146 new Response.unknownAnalysisService(request, serviceName));
121 } 147 }
122 subMap[service] = new HashSet.from(paths); 148 subMap[service] = new HashSet.from(paths);
123 }); 149 });
124 } 150 }
125 server.setAnalysisSubscriptions(subMap); 151 server.setAnalysisSubscriptions(subMap);
126 return new Response(request.id); 152 return new Response(request.id);
127 } 153 }
128 154
129 /** 155 /**
130 * Implement the 'analysis.updateContent' request. 156 * Implement the 'analysis.updateContent' request.
131 */ 157 */
132 Response updateContent(Request request) { 158 Response updateContent(Request request) {
133 var changes = new HashMap<String, ContentChange>(); 159 var changes = new HashMap<String, ContentChange>();
134 RequestDatum filesDatum = request.getRequiredParameter(FILES); 160 RequestDatum filesDatum = request.getRequiredParameter(FILES);
135 filesDatum.forEachMap((file, changeDatum) { 161 filesDatum.forEachMap((file, changeDatum) {
136 var change = new ContentChange(); 162 var change = new ContentChange();
137 change.content = changeDatum[CONTENT].isNull ? null : 163 change.content = changeDatum[CONTENT].isNull ?
164 null :
138 changeDatum[CONTENT].asString(); 165 changeDatum[CONTENT].asString();
139 if (changeDatum.hasKey(OFFSET)) { 166 if (changeDatum.hasKey(OFFSET)) {
140 change.offset = changeDatum[OFFSET].asInt(); 167 change.offset = changeDatum[OFFSET].asInt();
141 change.oldLength = changeDatum[OLD_LENGTH].asInt(); 168 change.oldLength = changeDatum[OLD_LENGTH].asInt();
142 change.newLength = changeDatum[NEW_LENGTH].asInt(); 169 change.newLength = changeDatum[NEW_LENGTH].asInt();
143 } 170 }
144 changes[file] = change; 171 changes[file] = change;
145 }); 172 });
146 server.updateContent(changes); 173 server.updateContent(changes);
147 return new Response(request.id); 174 return new Response(request.id);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 bool optionValue = optionDatum.asBool(); 213 bool optionValue = optionDatum.asBool();
187 updaters.add((AnalysisOptionsImpl options) { 214 updaters.add((AnalysisOptionsImpl options) {
188 options.dart2jsHint = optionValue; 215 options.dart2jsHint = optionValue;
189 }); 216 });
190 } else if (optionName == GENERATE_HINTS) { 217 } else if (optionName == GENERATE_HINTS) {
191 bool optionValue = optionDatum.asBool(); 218 bool optionValue = optionDatum.asBool();
192 updaters.add((AnalysisOptionsImpl options) { 219 updaters.add((AnalysisOptionsImpl options) {
193 options.hint = optionValue; 220 options.hint = optionValue;
194 }); 221 });
195 } else { 222 } else {
196 throw new RequestFailure(new Response.unknownOptionName(request, 223 throw new RequestFailure(
197 optionName)); 224 new Response.unknownOptionName(request, optionName));
198 } 225 }
199 }); 226 });
200 server.updateOptions(updaters); 227 server.updateOptions(updaters);
201 return new Response(request.id); 228 return new Response(request.id);
202 } 229 }
203 230
204 /** 231 /**
205 * Implement the 'analysis.updateSdks' request. 232 * Implement the 'analysis.updateSdks' request.
206 */ 233 */
207 Response updateSdks(Request request) { 234 Response updateSdks(Request request) {
(...skipping 14 matching lines...) Expand all
222 249
223 /** 250 /**
224 * A description of the change to the content of a file. 251 * A description of the change to the content of a file.
225 */ 252 */
226 class ContentChange { 253 class ContentChange {
227 String content; 254 String content;
228 int offset; 255 int offset;
229 int oldLength; 256 int oldLength;
230 int newLength; 257 int newLength;
231 } 258 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698