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

Side by Side Diff: pkg/analysis_server/lib/src/edit/edit_domain.dart

Issue 2832643005: Add plugin support for getAssists (Closed)
Patch Set: Created 3 years, 8 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_abstract.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 6
7 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; 7 import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
8 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; 8 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart';
9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (newLength == null) { 136 if (newLength == null) {
137 newLength = 0; 137 newLength = 0;
138 } 138 }
139 139
140 return new EditFormatResult(edits, newStart, newLength) 140 return new EditFormatResult(edits, newStart, newLength)
141 .toResponse(request.id); 141 .toResponse(request.id);
142 } 142 }
143 143
144 Future getAssists(Request request) async { 144 Future getAssists(Request request) async {
145 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request); 145 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request);
146 List<Assist> assists; 146 String file = params.file;
147 int offset = params.offset;
148 int length = params.length;
149
150 List<SourceChange> changes = <SourceChange>[];
147 if (server.options.enableNewAnalysisDriver) { 151 if (server.options.enableNewAnalysisDriver) {
148 AnalysisResult result = await server.getAnalysisResult(params.file); 152 //
153 // Allow plugins to start computing assists.
154 //
155 AnalysisDriver driver = server.getAnalysisDriver(file);
156 plugin.EditGetAssistsParams requestParams =
157 new plugin.EditGetAssistsParams(file, offset, length);
158 Map<PluginInfo, Future<plugin.Response>> pluginFutures =
159 server.pluginManager.broadcast(driver.contextRoot, requestParams);
160 //
161 // Compute fixes associated with server-generated errors.
162 //
163 AnalysisResult result = await server.getAnalysisResult(file);
149 if (result != null) { 164 if (result != null) {
150 CompilationUnit unit = result.unit; 165 CompilationUnit unit = result.unit;
151 CompilationUnitElement compilationUnitElement = 166 CompilationUnitElement compilationUnitElement =
152 resolutionMap.elementDeclaredByCompilationUnit(unit); 167 resolutionMap.elementDeclaredByCompilationUnit(unit);
153 DartAssistContext dartAssistContext = new _DartAssistContextForValues( 168 DartAssistContext dartAssistContext = new _DartAssistContextForValues(
154 compilationUnitElement.source, 169 compilationUnitElement.source,
155 params.offset, 170 offset,
156 params.length, 171 length,
157 compilationUnitElement.context, 172 compilationUnitElement.context,
158 unit); 173 unit);
159 try { 174 try {
160 AssistProcessor processor = new AssistProcessor(dartAssistContext); 175 AssistProcessor processor = new AssistProcessor(dartAssistContext);
161 assists = await processor.compute(); 176 List<Assist> assists = await processor.compute();
177 for (Assist assist in assists) {
178 changes.add(assist.change);
179 }
162 } catch (_) {} 180 } catch (_) {}
163 } 181 }
182 //
183 // Add the fixes produced by plugins to the server-generated fixes.
184 //
185 List<plugin.Response> responses = await waitForResponses(pluginFutures,
186 requestParameters: requestParams);
187 ResultConverter converter = new ResultConverter();
188 List<plugin.PrioritizedSourceChange> pluginChanges =
189 <plugin.PrioritizedSourceChange>[];
190 for (plugin.Response response in responses) {
191 plugin.EditGetAssistsResult result =
192 new plugin.EditGetAssistsResult.fromResponse(response);
193 pluginChanges.addAll(result.assists);
194 }
195 pluginChanges
196 .sort((first, second) => first.priority.compareTo(second.priority));
197 changes
198 .addAll(pluginChanges.map(converter.convertPrioritizedSourceChange));
164 } else { 199 } else {
165 ContextSourcePair pair = server.getContextSourcePair(params.file); 200 ContextSourcePair pair = server.getContextSourcePair(file);
166 engine.AnalysisContext context = pair.context; 201 engine.AnalysisContext context = pair.context;
167 Source source = pair.source; 202 Source source = pair.source;
168 if (context != null && source != null) { 203 if (context != null && source != null) {
169 assists = await computeAssists( 204 List<Assist> assists = await computeAssists(
170 server.serverPlugin, context, source, params.offset, params.length); 205 server.serverPlugin, context, source, offset, length);
206 for (Assist assist in assists) {
207 changes.add(assist.change);
208 }
171 } 209 }
172 } 210 }
173 // Send the assist changes. 211 //
174 List<SourceChange> changes = <SourceChange>[]; 212 // Send the response.
175 assists?.forEach((Assist assist) { 213 //
176 changes.add(assist.change); 214 server
177 }); 215 .sendResponse(new EditGetAssistsResult(changes).toResponse(request.id));
178 Response response =
179 new EditGetAssistsResult(changes).toResponse(request.id);
180 server.sendResponse(response);
181 } 216 }
182 217
183 Future getFixes(Request request) async { 218 Future getFixes(Request request) async {
184 var params = new EditGetFixesParams.fromRequest(request); 219 var params = new EditGetFixesParams.fromRequest(request);
185 String file = params.file; 220 String file = params.file;
186 int offset = params.offset; 221 int offset = params.offset;
187 222
188 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[]; 223 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[];
189 if (server.options.enableNewAnalysisDriver) { 224 if (server.options.enableNewAnalysisDriver) {
190 // 225 //
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 new AnalysisErrorFixes(serverError); 297 new AnalysisErrorFixes(serverError);
263 errorFixesList.add(errorFixes); 298 errorFixesList.add(errorFixes);
264 fixes.forEach((fix) { 299 fixes.forEach((fix) {
265 errorFixes.fixes.add(fix.change); 300 errorFixes.fixes.add(fix.change);
266 }); 301 });
267 } 302 }
268 } 303 }
269 } 304 }
270 } 305 }
271 } 306 }
272 307 //
273 // Send the response. 308 // Send the response.
309 //
274 server.sendResponse( 310 server.sendResponse(
275 new EditGetFixesResult(errorFixesList).toResponse(request.id)); 311 new EditGetFixesResult(errorFixesList).toResponse(request.id));
276 } 312 }
277 313
278 Future getStatementCompletion(Request request) async { 314 Future getStatementCompletion(Request request) async {
279 var params = new EditGetStatementCompletionParams.fromRequest(request); 315 var params = new EditGetStatementCompletionParams.fromRequest(request);
280 SourceChange change; 316 SourceChange change;
281 317
282 AnalysisResult result = await server.getAnalysisResult(params.file); 318 AnalysisResult result = await server.getAnalysisResult(params.file);
283 if (result != null) { 319 if (result != null) {
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 } 1068 }
1033 return new RefactoringStatus(); 1069 return new RefactoringStatus();
1034 } 1070 }
1035 } 1071 }
1036 1072
1037 /** 1073 /**
1038 * [_RefactoringManager] throws instances of this class internally to stop 1074 * [_RefactoringManager] throws instances of this class internally to stop
1039 * processing in a manager that was reset. 1075 * processing in a manager that was reset.
1040 */ 1076 */
1041 class _ResetError {} 1077 class _ResetError {}
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/analysis_abstract.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698