| 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; | 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/fix/fix_core.dart'; | 10 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 newStart = 0; | 123 newStart = 0; |
| 124 } | 124 } |
| 125 if (newLength == null) { | 125 if (newLength == null) { |
| 126 newLength = 0; | 126 newLength = 0; |
| 127 } | 127 } |
| 128 | 128 |
| 129 return new EditFormatResult(edits, newStart, newLength) | 129 return new EditFormatResult(edits, newStart, newLength) |
| 130 .toResponse(request.id); | 130 .toResponse(request.id); |
| 131 } | 131 } |
| 132 | 132 |
| 133 Response getAssists(Request request) { | 133 Future getAssists(Request request) async { |
| 134 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request); | 134 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request); |
| 135 ContextSourcePair pair = server.getContextSourcePair(params.file); | 135 ContextSourcePair pair = server.getContextSourcePair(params.file); |
| 136 engine.AnalysisContext context = pair.context; | 136 engine.AnalysisContext context = pair.context; |
| 137 Source source = pair.source; | 137 Source source = pair.source; |
| 138 List<SourceChange> changes = <SourceChange>[]; | 138 List<SourceChange> changes = <SourceChange>[]; |
| 139 if (context != null && source != null) { | 139 if (context != null && source != null) { |
| 140 List<Assist> assists = computeAssists( | 140 List<Assist> assists = await computeAssists( |
| 141 server.serverPlugin, context, source, params.offset, params.length); | 141 server.serverPlugin, context, source, params.offset, params.length); |
| 142 assists.forEach((Assist assist) { | 142 assists.forEach((Assist assist) { |
| 143 changes.add(assist.change); | 143 changes.add(assist.change); |
| 144 }); | 144 }); |
| 145 } | 145 } |
| 146 return new EditGetAssistsResult(changes).toResponse(request.id); | 146 Response response = |
| 147 new EditGetAssistsResult(changes).toResponse(request.id); |
| 148 server.sendResponse(response); |
| 147 } | 149 } |
| 148 | 150 |
| 149 Response getFixes(Request request) { | 151 Response getFixes(Request request) { |
| 150 var params = new EditGetFixesParams.fromRequest(request); | 152 var params = new EditGetFixesParams.fromRequest(request); |
| 151 String file = params.file; | 153 String file = params.file; |
| 152 int offset = params.offset; | 154 int offset = params.offset; |
| 153 // add fixes | 155 // add fixes |
| 154 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[]; | 156 List<AnalysisErrorFixes> errorFixesList = <AnalysisErrorFixes>[]; |
| 155 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); | 157 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); |
| 156 for (CompilationUnit unit in units) { | 158 for (CompilationUnit unit in units) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 181 return new EditGetFixesResult(errorFixesList).toResponse(request.id); | 183 return new EditGetFixesResult(errorFixesList).toResponse(request.id); |
| 182 } | 184 } |
| 183 | 185 |
| 184 @override | 186 @override |
| 185 Response handleRequest(Request request) { | 187 Response handleRequest(Request request) { |
| 186 try { | 188 try { |
| 187 String requestName = request.method; | 189 String requestName = request.method; |
| 188 if (requestName == EDIT_FORMAT) { | 190 if (requestName == EDIT_FORMAT) { |
| 189 return format(request); | 191 return format(request); |
| 190 } else if (requestName == EDIT_GET_ASSISTS) { | 192 } else if (requestName == EDIT_GET_ASSISTS) { |
| 191 return getAssists(request); | 193 getAssists(request); |
| 194 return Response.DELAYED_RESPONSE; |
| 192 } else if (requestName == EDIT_GET_AVAILABLE_REFACTORINGS) { | 195 } else if (requestName == EDIT_GET_AVAILABLE_REFACTORINGS) { |
| 193 return _getAvailableRefactorings(request); | 196 return _getAvailableRefactorings(request); |
| 194 } else if (requestName == EDIT_GET_FIXES) { | 197 } else if (requestName == EDIT_GET_FIXES) { |
| 195 return getFixes(request); | 198 return getFixes(request); |
| 196 } else if (requestName == EDIT_GET_REFACTORING) { | 199 } else if (requestName == EDIT_GET_REFACTORING) { |
| 197 return _getRefactoring(request); | 200 return _getRefactoring(request); |
| 198 } else if (requestName == EDIT_ORGANIZE_DIRECTIVES) { | 201 } else if (requestName == EDIT_ORGANIZE_DIRECTIVES) { |
| 199 return organizeDirectives(request); | 202 return organizeDirectives(request); |
| 200 } else if (requestName == EDIT_SORT_MEMBERS) { | 203 } else if (requestName == EDIT_SORT_MEMBERS) { |
| 201 return sortMembers(request); | 204 return sortMembers(request); |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 } | 739 } |
| 737 return new RefactoringStatus(); | 740 return new RefactoringStatus(); |
| 738 } | 741 } |
| 739 } | 742 } |
| 740 | 743 |
| 741 /** | 744 /** |
| 742 * [_RefactoringManager] throws instances of this class internally to stop | 745 * [_RefactoringManager] throws instances of this class internally to stop |
| 743 * processing in a manager that was reset. | 746 * processing in a manager that was reset. |
| 744 */ | 747 */ |
| 745 class _ResetError {} | 748 class _ResetError {} |
| OLD | NEW |