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

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

Issue 2481643002: Support for Quick Fixes with the new analysis driver. (Closed)
Patch Set: Created 4 years, 1 month 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 | no next file » | 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 library edit.domain; 5 library edit.domain;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; 10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart';
11 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 11 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
12 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
12 import 'package:analysis_server/src/analysis_server.dart'; 13 import 'package:analysis_server/src/analysis_server.dart';
13 import 'package:analysis_server/src/collections.dart'; 14 import 'package:analysis_server/src/collections.dart';
14 import 'package:analysis_server/src/constants.dart'; 15 import 'package:analysis_server/src/constants.dart';
15 import 'package:analysis_server/src/protocol_server.dart' hide Element; 16 import 'package:analysis_server/src/protocol_server.dart' hide Element;
16 import 'package:analysis_server/src/services/correction/assist.dart'; 17 import 'package:analysis_server/src/services/correction/assist.dart';
17 import 'package:analysis_server/src/services/correction/assist_internal.dart'; 18 import 'package:analysis_server/src/services/correction/assist_internal.dart';
18 import 'package:analysis_server/src/services/correction/fix.dart'; 19 import 'package:analysis_server/src/services/correction/fix.dart';
20 import 'package:analysis_server/src/services/correction/fix_internal.dart';
19 import 'package:analysis_server/src/services/correction/organize_directives.dart '; 21 import 'package:analysis_server/src/services/correction/organize_directives.dart ';
20 import 'package:analysis_server/src/services/correction/sort_members.dart'; 22 import 'package:analysis_server/src/services/correction/sort_members.dart';
21 import 'package:analysis_server/src/services/correction/status.dart'; 23 import 'package:analysis_server/src/services/correction/status.dart';
22 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 24 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
23 import 'package:analysis_server/src/services/search/search_engine.dart'; 25 import 'package:analysis_server/src/services/search/search_engine.dart';
24 import 'package:analyzer/dart/ast/ast.dart'; 26 import 'package:analyzer/dart/ast/ast.dart';
25 import 'package:analyzer/dart/element/element.dart'; 27 import 'package:analyzer/dart/element/element.dart';
26 import 'package:analyzer/error/error.dart' as engine; 28 import 'package:analyzer/error/error.dart' as engine;
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/dart/scanner/scanner.dart' as engine; 31 import 'package:analyzer/src/dart/scanner/scanner.dart' as engine;
29 import 'package:analyzer/src/error/codes.dart' as engine; 32 import 'package:analyzer/src/error/codes.dart' as engine;
30 import 'package:analyzer/src/generated/engine.dart' as engine; 33 import 'package:analyzer/src/generated/engine.dart' as engine;
31 import 'package:analyzer/src/generated/parser.dart' as engine; 34 import 'package:analyzer/src/generated/parser.dart' as engine;
32 import 'package:analyzer/src/generated/source.dart'; 35 import 'package:analyzer/src/generated/source.dart';
33 import 'package:analyzer/task/dart.dart'; 36 import 'package:analyzer/task/dart.dart';
34 import 'package:dart_style/dart_style.dart'; 37 import 'package:dart_style/dart_style.dart';
35 38
36 int test_resetCount = 0; 39 int test_resetCount = 0;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 List<SourceChange> changes = <SourceChange>[]; 165 List<SourceChange> changes = <SourceChange>[];
163 assists?.forEach((Assist assist) { 166 assists?.forEach((Assist assist) {
164 changes.add(assist.change); 167 changes.add(assist.change);
165 }); 168 });
166 Response response = 169 Response response =
167 new EditGetAssistsResult(changes).toResponse(request.id); 170 new EditGetAssistsResult(changes).toResponse(request.id);
168 server.sendResponse(response); 171 server.sendResponse(response);
169 } 172 }
170 173
171 Future getFixes(Request request) async { 174 Future getFixes(Request request) async {
172 if (server.options.enableNewAnalysisDriver) {
173 // TODO(scheglov) implement for the new analysis driver
174 return;
175 }
176 var params = new EditGetFixesParams.fromRequest(request); 175 var params = new EditGetFixesParams.fromRequest(request);
177 String file = params.file; 176 String file = params.file;
178 int offset = params.offset; 177 int offset = params.offset;
179 // add fixes 178
180 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[]; 179 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[];
181 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 180 if (server.options.enableNewAnalysisDriver) {
182 for (CompilationUnit unit in units) { 181 AnalysisResult result = await server.getAnalysisResult(file);
183 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); 182 CompilationUnit unit = result.unit;
184 if (errorInfo != null) { 183 LineInfo lineInfo = result.lineInfo;
185 LineInfo lineInfo = errorInfo.lineInfo; 184 int requestLine = lineInfo.getLocation(offset).lineNumber;
186 int requestLine = lineInfo.getLocation(offset).lineNumber; 185 for (engine.AnalysisError error in result.errors) {
187 for (engine.AnalysisError error in errorInfo.errors) { 186 int errorLine = lineInfo.getLocation(error.offset).lineNumber;
188 int errorLine = lineInfo.getLocation(error.offset).lineNumber; 187 if (errorLine == requestLine) {
189 if (errorLine == requestLine) { 188 var context = new _DartFixContextImpl(
190 List<Fix> fixes = await computeFixes(server.serverPlugin, 189 server.resourceProvider, unit.element.context, unit, error);
191 server.resourceProvider, unit.element.context, error); 190 List<Fix> fixes =
192 if (fixes.isNotEmpty) { 191 await new DefaultFixContributor().internalComputeFixes(context);
193 AnalysisError serverError = 192 if (fixes.isNotEmpty) {
194 newAnalysisError_fromEngine(lineInfo, error); 193 AnalysisError serverError =
195 AnalysisErrorFixes errorFixes = 194 newAnalysisError_fromEngine(lineInfo, error);
196 new AnalysisErrorFixes(serverError); 195 AnalysisErrorFixes errorFixes = new AnalysisErrorFixes(serverError);
197 errorFixesList.add(errorFixes); 196 errorFixesList.add(errorFixes);
198 fixes.forEach((fix) { 197 fixes.forEach((fix) {
199 errorFixes.fixes.add(fix.change); 198 errorFixes.fixes.add(fix.change);
200 }); 199 });
200 }
201 }
202 }
203 } else {
204 List<CompilationUnit> units = server.getResolvedCompilationUnits(file);
205 for (CompilationUnit unit in units) {
206 engine.AnalysisErrorInfo errorInfo = server.getErrors(file);
207 if (errorInfo != null) {
208 LineInfo lineInfo = errorInfo.lineInfo;
209 int requestLine = lineInfo.getLocation(offset).lineNumber;
210 for (engine.AnalysisError error in errorInfo.errors) {
211 int errorLine = lineInfo.getLocation(error.offset).lineNumber;
212 if (errorLine == requestLine) {
213 List<Fix> fixes = await computeFixes(server.serverPlugin,
214 server.resourceProvider, unit.element.context, error);
215 if (fixes.isNotEmpty) {
216 AnalysisError serverError =
217 newAnalysisError_fromEngine(lineInfo, error);
218 AnalysisErrorFixes errorFixes =
219 new AnalysisErrorFixes(serverError);
220 errorFixesList.add(errorFixes);
221 fixes.forEach((fix) {
222 errorFixes.fixes.add(fix.change);
223 });
224 }
201 } 225 }
202 } 226 }
203 } 227 }
204 } 228 }
205 } 229 }
206 // respond 230
231 // Send the response.
207 server.sendResponse( 232 server.sendResponse(
208 new EditGetFixesResult(errorFixesList).toResponse(request.id)); 233 new EditGetFixesResult(errorFixesList).toResponse(request.id));
209 } 234 }
210 235
211 @override 236 @override
212 Response handleRequest(Request request) { 237 Response handleRequest(Request request) {
213 try { 238 try {
214 String requestName = request.method; 239 String requestName = request.method;
215 if (requestName == EDIT_FORMAT) { 240 if (requestName == EDIT_FORMAT) {
216 return format(request); 241 return format(request);
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 final engine.AnalysisContext analysisContext; 448 final engine.AnalysisContext analysisContext;
424 449
425 @override 450 @override
426 final CompilationUnit unit; 451 final CompilationUnit unit;
427 452
428 _DartAssistContextForValues(this.source, this.selectionOffset, 453 _DartAssistContextForValues(this.source, this.selectionOffset,
429 this.selectionLength, this.analysisContext, this.unit); 454 this.selectionLength, this.analysisContext, this.unit);
430 } 455 }
431 456
432 /** 457 /**
458 * And implementation of [DartFixContext].
459 */
460 class _DartFixContextImpl implements DartFixContext {
461 @override
462 final ResourceProvider resourceProvider;
463
464 @override
465 final engine.AnalysisContext analysisContext;
466
467 @override
468 final CompilationUnit unit;
469
470 @override
471 final engine.AnalysisError error;
472
473 _DartFixContextImpl(
474 this.resourceProvider, this.analysisContext, this.unit, this.error);
475 }
476
477 /**
433 * An object managing a single [Refactoring] instance. 478 * An object managing a single [Refactoring] instance.
434 * 479 *
435 * The instance is identified by its kind, file, offset and length. 480 * The instance is identified by its kind, file, offset and length.
436 * It is initialized when the a set of parameters is given for the first time. 481 * It is initialized when the a set of parameters is given for the first time.
437 * All subsequent requests are performed on this [Refactoring] instance. 482 * All subsequent requests are performed on this [Refactoring] instance.
438 * 483 *
439 * Once new set of parameters is received, the previous [Refactoring] instance 484 * Once new set of parameters is received, the previous [Refactoring] instance
440 * is invalidated and a new one is created and initialized. 485 * is invalidated and a new one is created and initialized.
441 */ 486 */
442 class _RefactoringManager { 487 class _RefactoringManager {
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 } 916 }
872 return new RefactoringStatus(); 917 return new RefactoringStatus();
873 } 918 }
874 } 919 }
875 920
876 /** 921 /**
877 * [_RefactoringManager] throws instances of this class internally to stop 922 * [_RefactoringManager] throws instances of this class internally to stop
878 * processing in a manager that was reset. 923 * processing in a manager that was reset.
879 */ 924 */
880 class _ResetError {} 925 class _ResetError {}
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698