Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; | |
| 6 | |
| 7 import 'dart:async'; | 5 import 'dart:async'; |
| 8 | 6 |
| 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; | 7 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; |
| 10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; | 8 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; |
| 11 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 12 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; | 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; |
| 13 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
| 14 import 'package:analysis_server/src/collections.dart'; | 12 import 'package:analysis_server/src/collections.dart'; |
| 15 import 'package:analysis_server/src/constants.dart'; | 13 import 'package:analysis_server/src/constants.dart'; |
| 14 import 'package:analysis_server/src/domain_abstract.dart'; | |
| 15 import 'package:analysis_server/src/plugin/plugin_manager.dart'; | |
| 16 import 'package:analysis_server/src/plugin/result_converter.dart'; | |
| 16 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 17 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| 17 import 'package:analysis_server/src/services/completion/statement/statement_comp letion.dart'; | 18 import 'package:analysis_server/src/services/completion/statement/statement_comp letion.dart'; |
| 18 import 'package:analysis_server/src/services/correction/assist.dart'; | 19 import 'package:analysis_server/src/services/correction/assist.dart'; |
| 19 import 'package:analysis_server/src/services/correction/assist_internal.dart'; | 20 import 'package:analysis_server/src/services/correction/assist_internal.dart'; |
| 20 import 'package:analysis_server/src/services/correction/fix.dart'; | 21 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 21 import 'package:analysis_server/src/services/correction/fix_internal.dart'; | 22 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
| 22 import 'package:analysis_server/src/services/correction/organize_directives.dart '; | 23 import 'package:analysis_server/src/services/correction/organize_directives.dart '; |
| 23 import 'package:analysis_server/src/services/correction/sort_members.dart'; | 24 import 'package:analysis_server/src/services/correction/sort_members.dart'; |
| 24 import 'package:analysis_server/src/services/correction/status.dart'; | 25 import 'package:analysis_server/src/services/correction/status.dart'; |
| 25 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 26 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 26 import 'package:analysis_server/src/services/search/search_engine.dart'; | 27 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 27 import 'package:analyzer/dart/ast/ast.dart'; | 28 import 'package:analyzer/dart/ast/ast.dart'; |
| 28 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 29 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 29 import 'package:analyzer/dart/element/element.dart'; | 30 import 'package:analyzer/dart/element/element.dart'; |
| 30 import 'package:analyzer/error/error.dart' as engine; | 31 import 'package:analyzer/error/error.dart' as engine; |
| 31 import 'package:analyzer/file_system/file_system.dart'; | 32 import 'package:analyzer/file_system/file_system.dart'; |
| 32 import 'package:analyzer/src/dart/analysis/driver.dart'; | 33 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 33 import 'package:analyzer/src/dart/element/ast_provider.dart'; | 34 import 'package:analyzer/src/dart/element/ast_provider.dart'; |
| 34 import 'package:analyzer/src/dart/scanner/scanner.dart' as engine; | 35 import 'package:analyzer/src/dart/scanner/scanner.dart' as engine; |
| 35 import 'package:analyzer/src/error/codes.dart' as engine; | 36 import 'package:analyzer/src/error/codes.dart' as engine; |
| 36 import 'package:analyzer/src/generated/engine.dart' as engine; | 37 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 37 import 'package:analyzer/src/generated/parser.dart' as engine; | 38 import 'package:analyzer/src/generated/parser.dart' as engine; |
| 38 import 'package:analyzer/src/generated/source.dart'; | 39 import 'package:analyzer/src/generated/source.dart'; |
| 39 import 'package:analyzer/task/dart.dart'; | 40 import 'package:analyzer/task/dart.dart'; |
| 41 import 'package:analyzer_plugin/protocol/protocol.dart' as plugin; | |
| 42 import 'package:analyzer_plugin/protocol/protocol_constants.dart' as plugin; | |
| 43 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; | |
| 40 import 'package:dart_style/dart_style.dart'; | 44 import 'package:dart_style/dart_style.dart'; |
| 41 | 45 |
| 42 int test_resetCount = 0; | 46 int test_resetCount = 0; |
| 43 | 47 |
| 44 bool test_simulateRefactoringException_change = false; | 48 bool test_simulateRefactoringException_change = false; |
| 45 bool test_simulateRefactoringException_final = false; | 49 bool test_simulateRefactoringException_final = false; |
| 46 bool test_simulateRefactoringException_init = false; | 50 bool test_simulateRefactoringException_init = false; |
| 47 | 51 |
| 48 bool test_simulateRefactoringReset_afterCreateChange = false; | 52 bool test_simulateRefactoringReset_afterCreateChange = false; |
| 49 bool test_simulateRefactoringReset_afterFinalConditions = false; | 53 bool test_simulateRefactoringReset_afterFinalConditions = false; |
| 50 bool test_simulateRefactoringReset_afterInitialConditions = false; | 54 bool test_simulateRefactoringReset_afterInitialConditions = false; |
| 51 | 55 |
| 52 /** | 56 /** |
| 53 * Instances of the class [EditDomainHandler] implement a [RequestHandler] | 57 * Instances of the class [EditDomainHandler] implement a [RequestHandler] |
| 54 * that handles requests in the edit domain. | 58 * that handles requests in the edit domain. |
| 55 */ | 59 */ |
| 56 class EditDomainHandler implements RequestHandler { | 60 class EditDomainHandler extends AbstractRequestHandler { |
| 57 /** | |
| 58 * The analysis server that is using this handler to process requests. | |
| 59 */ | |
| 60 final AnalysisServer server; | |
| 61 | |
| 62 /** | 61 /** |
| 63 * The [SearchEngine] for this server. | 62 * The [SearchEngine] for this server. |
| 64 */ | 63 */ |
| 65 SearchEngine searchEngine; | 64 SearchEngine searchEngine; |
| 66 | 65 |
| 66 /** | |
| 67 * The object used to manage uncompleted refactorings. | |
| 68 */ | |
| 67 _RefactoringManager refactoringManager; | 69 _RefactoringManager refactoringManager; |
| 68 | 70 |
| 69 /** | 71 /** |
| 70 * Initialize a newly created handler to handle requests for the given [server ]. | 72 * Initialize a newly created handler to handle requests for the given [server ]. |
| 71 */ | 73 */ |
| 72 EditDomainHandler(this.server) { | 74 EditDomainHandler(AnalysisServer server) : super(server) { |
| 73 searchEngine = server.searchEngine; | 75 searchEngine = server.searchEngine; |
| 74 _newRefactoringManager(); | 76 _newRefactoringManager(); |
| 75 } | 77 } |
| 76 | 78 |
| 77 Response format(Request request) { | 79 Response format(Request request) { |
| 78 EditFormatParams params = new EditFormatParams.fromRequest(request); | 80 EditFormatParams params = new EditFormatParams.fromRequest(request); |
| 79 String file = params.file; | 81 String file = params.file; |
| 80 | 82 |
| 81 String unformattedSource; | 83 String unformattedSource; |
| 82 try { | 84 try { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 server.sendResponse(response); | 180 server.sendResponse(response); |
| 179 } | 181 } |
| 180 | 182 |
| 181 Future getFixes(Request request) async { | 183 Future getFixes(Request request) async { |
| 182 var params = new EditGetFixesParams.fromRequest(request); | 184 var params = new EditGetFixesParams.fromRequest(request); |
| 183 String file = params.file; | 185 String file = params.file; |
| 184 int offset = params.offset; | 186 int offset = params.offset; |
| 185 | 187 |
| 186 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[]; | 188 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[]; |
| 187 if (server.options.enableNewAnalysisDriver) { | 189 if (server.options.enableNewAnalysisDriver) { |
| 190 AnalysisDriver driver = server.getAnalysisDriver(file); | |
| 191 plugin.EditGetFixesParams pluginParams = | |
| 192 new plugin.EditGetFixesParams(file, offset); | |
| 193 Map<PluginInfo, Future<plugin.Response>> pluginFutures = | |
| 194 server.pluginManager.broadcast(driver.contextRoot, pluginParams); | |
|
scheglov
2017/04/19 20:19:04
Could you instead an empty line here?
Brian Wilkerson
2017/04/19 20:52:48
I'm adding comments instead.
| |
| 188 AnalysisResult result = await server.getAnalysisResult(file); | 195 AnalysisResult result = await server.getAnalysisResult(file); |
| 189 if (result != null) { | 196 if (result != null) { |
| 190 CompilationUnit unit = result.unit; | 197 CompilationUnit unit = result.unit; |
| 191 LineInfo lineInfo = result.lineInfo; | 198 LineInfo lineInfo = result.lineInfo; |
| 192 int requestLine = lineInfo.getLocation(offset).lineNumber; | 199 int requestLine = lineInfo.getLocation(offset).lineNumber; |
| 193 for (engine.AnalysisError error in result.errors) { | 200 for (engine.AnalysisError error in result.errors) { |
| 194 int errorLine = lineInfo.getLocation(error.offset).lineNumber; | 201 int errorLine = lineInfo.getLocation(error.offset).lineNumber; |
| 195 if (errorLine == requestLine) { | 202 if (errorLine == requestLine) { |
| 196 var context = new _DartFixContextImpl( | 203 var context = new _DartFixContextImpl( |
| 197 server.resourceProvider, | 204 server.resourceProvider, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 208 newAnalysisError_fromEngine(lineInfo, error); | 215 newAnalysisError_fromEngine(lineInfo, error); |
| 209 AnalysisErrorFixes errorFixes = | 216 AnalysisErrorFixes errorFixes = |
| 210 new AnalysisErrorFixes(serverError); | 217 new AnalysisErrorFixes(serverError); |
| 211 errorFixesList.add(errorFixes); | 218 errorFixesList.add(errorFixes); |
| 212 fixes.forEach((fix) { | 219 fixes.forEach((fix) { |
| 213 errorFixes.fixes.add(fix.change); | 220 errorFixes.fixes.add(fix.change); |
| 214 }); | 221 }); |
| 215 } | 222 } |
| 216 } | 223 } |
| 217 } | 224 } |
| 218 } | 225 } |
|
scheglov
2017/04/19 20:19:04
Could you instead an empty line here?
Brian Wilkerson
2017/04/19 20:52:48
I'm adding comments instead.
| |
| 226 List<plugin.Response> responses = await waitForResponses(pluginFutures); | |
| 227 ResultConverter converter = new ResultConverter(); | |
| 228 for (plugin.Response response in responses) { | |
| 229 plugin.EditGetFixesResult result = | |
| 230 new plugin.EditGetFixesResult.fromResponse(response); | |
| 231 errorFixesList.addAll(result.fixes | |
| 232 .map((fixes) => converter.convertAnalysisErrorFixes(fixes))); | |
|
scheglov
2017/04/19 20:19:04
You could just pass converter.convertAnalysisError
Brian Wilkerson
2017/04/19 20:52:48
Done
| |
| 233 } | |
| 219 } else { | 234 } else { |
| 220 CompilationUnit unit = await server.getResolvedCompilationUnit(file); | 235 CompilationUnit unit = await server.getResolvedCompilationUnit(file); |
| 221 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); | 236 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); |
| 222 LineInfo lineInfo = errorInfo?.lineInfo; | 237 LineInfo lineInfo = errorInfo?.lineInfo; |
| 223 if (unit != null && errorInfo != null && lineInfo != null) { | 238 if (unit != null && errorInfo != null && lineInfo != null) { |
| 224 int requestLine = lineInfo.getLocation(offset).lineNumber; | 239 int requestLine = lineInfo.getLocation(offset).lineNumber; |
| 225 for (engine.AnalysisError error in errorInfo.errors) { | 240 for (engine.AnalysisError error in errorInfo.errors) { |
| 226 int errorLine = lineInfo.getLocation(error.offset).lineNumber; | 241 int errorLine = lineInfo.getLocation(error.offset).lineNumber; |
| 227 if (errorLine == requestLine) { | 242 if (errorLine == requestLine) { |
| 228 List<Fix> fixes = await computeFixes( | 243 List<Fix> fixes = await computeFixes( |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 } | 1022 } |
| 1008 return new RefactoringStatus(); | 1023 return new RefactoringStatus(); |
| 1009 } | 1024 } |
| 1010 } | 1025 } |
| 1011 | 1026 |
| 1012 /** | 1027 /** |
| 1013 * [_RefactoringManager] throws instances of this class internally to stop | 1028 * [_RefactoringManager] throws instances of this class internally to stop |
| 1014 * processing in a manager that was reset. | 1029 * processing in a manager that was reset. |
| 1015 */ | 1030 */ |
| 1016 class _ResetError {} | 1031 class _ResetError {} |
| OLD | NEW |