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'; |
11 import 'package:analysis_server/src/analysis_server.dart'; | 11 import 'package:analysis_server/src/analysis_server.dart'; |
12 import 'package:analysis_server/src/collections.dart'; | 12 import 'package:analysis_server/src/collections.dart'; |
13 import 'package:analysis_server/src/constants.dart'; | 13 import 'package:analysis_server/src/constants.dart'; |
14 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 14 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
15 import 'package:analysis_server/src/services/correction/assist.dart'; | 15 import 'package:analysis_server/src/services/correction/assist.dart'; |
16 import 'package:analysis_server/src/services/correction/fix.dart'; | 16 import 'package:analysis_server/src/services/correction/fix.dart'; |
17 import 'package:analysis_server/src/services/correction/organize_directives.dart
'; | 17 import 'package:analysis_server/src/services/correction/organize_directives.dart
'; |
18 import 'package:analysis_server/src/services/correction/sort_members.dart'; | 18 import 'package:analysis_server/src/services/correction/sort_members.dart'; |
19 import 'package:analysis_server/src/services/correction/status.dart'; | 19 import 'package:analysis_server/src/services/correction/status.dart'; |
20 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 20 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
21 import 'package:analysis_server/src/services/search/search_engine.dart'; | 21 import 'package:analysis_server/src/services/search/search_engine.dart'; |
22 import 'package:analyzer/dart/ast/ast.dart'; | 22 import 'package:analyzer/dart/ast/ast.dart'; |
23 import 'package:analyzer/dart/element/element.dart'; | 23 import 'package:analyzer/dart/element/element.dart'; |
24 import 'package:analyzer/error/error.dart' as engine; | 24 import 'package:analyzer/error/error.dart' as engine; |
| 25 import 'package:analyzer/src/dart/analysis/driver.dart'; |
25 import 'package:analyzer/src/dart/scanner/scanner.dart' as engine; | 26 import 'package:analyzer/src/dart/scanner/scanner.dart' as engine; |
26 import 'package:analyzer/src/error/codes.dart' as engine; | 27 import 'package:analyzer/src/error/codes.dart' as engine; |
27 import 'package:analyzer/src/generated/engine.dart' as engine; | 28 import 'package:analyzer/src/generated/engine.dart' as engine; |
28 import 'package:analyzer/src/generated/parser.dart' as engine; | 29 import 'package:analyzer/src/generated/parser.dart' as engine; |
29 import 'package:analyzer/src/generated/source.dart'; | 30 import 'package:analyzer/src/generated/source.dart'; |
30 import 'package:analyzer/task/dart.dart'; | 31 import 'package:analyzer/task/dart.dart'; |
31 import 'package:dart_style/dart_style.dart'; | 32 import 'package:dart_style/dart_style.dart'; |
32 | 33 |
33 int test_resetCount = 0; | 34 int test_resetCount = 0; |
34 | 35 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } else if (requestName == EDIT_GET_AVAILABLE_REFACTORINGS) { | 205 } else if (requestName == EDIT_GET_AVAILABLE_REFACTORINGS) { |
205 return _getAvailableRefactorings(request); | 206 return _getAvailableRefactorings(request); |
206 } else if (requestName == EDIT_GET_FIXES) { | 207 } else if (requestName == EDIT_GET_FIXES) { |
207 getFixes(request); | 208 getFixes(request); |
208 return Response.DELAYED_RESPONSE; | 209 return Response.DELAYED_RESPONSE; |
209 } else if (requestName == EDIT_GET_REFACTORING) { | 210 } else if (requestName == EDIT_GET_REFACTORING) { |
210 return _getRefactoring(request); | 211 return _getRefactoring(request); |
211 } else if (requestName == EDIT_ORGANIZE_DIRECTIVES) { | 212 } else if (requestName == EDIT_ORGANIZE_DIRECTIVES) { |
212 return organizeDirectives(request); | 213 return organizeDirectives(request); |
213 } else if (requestName == EDIT_SORT_MEMBERS) { | 214 } else if (requestName == EDIT_SORT_MEMBERS) { |
214 return sortMembers(request); | 215 sortMembers(request); |
| 216 return Response.DELAYED_RESPONSE; |
215 } | 217 } |
216 } on RequestFailure catch (exception) { | 218 } on RequestFailure catch (exception) { |
217 return exception.response; | 219 return exception.response; |
218 } | 220 } |
219 return null; | 221 return null; |
220 } | 222 } |
221 | 223 |
222 Response organizeDirectives(Request request) { | 224 Response organizeDirectives(Request request) { |
223 var params = new EditOrganizeDirectivesParams.fromRequest(request); | 225 var params = new EditOrganizeDirectivesParams.fromRequest(request); |
224 // prepare file | 226 // prepare file |
(...skipping 19 matching lines...) Expand all Loading... |
244 } | 246 } |
245 // do organize | 247 // do organize |
246 int fileStamp = context.getModificationStamp(source); | 248 int fileStamp = context.getModificationStamp(source); |
247 String code = context.getContents(source).data; | 249 String code = context.getContents(source).data; |
248 DirectiveOrganizer sorter = new DirectiveOrganizer(code, unit, errors); | 250 DirectiveOrganizer sorter = new DirectiveOrganizer(code, unit, errors); |
249 List<SourceEdit> edits = sorter.organize(); | 251 List<SourceEdit> edits = sorter.organize(); |
250 SourceFileEdit fileEdit = new SourceFileEdit(file, fileStamp, edits: edits); | 252 SourceFileEdit fileEdit = new SourceFileEdit(file, fileStamp, edits: edits); |
251 return new EditOrganizeDirectivesResult(fileEdit).toResponse(request.id); | 253 return new EditOrganizeDirectivesResult(fileEdit).toResponse(request.id); |
252 } | 254 } |
253 | 255 |
254 Response sortMembers(Request request) { | 256 Future<Null> sortMembers(Request request) async { |
255 var params = new EditSortMembersParams.fromRequest(request); | 257 var params = new EditSortMembersParams.fromRequest(request); |
256 // prepare file | 258 // prepare file |
257 String file = params.file; | 259 String file = params.file; |
258 if (!engine.AnalysisEngine.isDartFileName(file)) { | 260 if (!engine.AnalysisEngine.isDartFileName(file)) { |
259 return new Response.sortMembersInvalidFile(request); | 261 server.sendResponse(new Response.sortMembersInvalidFile(request)); |
260 } | 262 } |
261 // prepare location | 263 // Prepare the file information. |
262 ContextSourcePair contextSource = server.getContextSourcePair(file); | 264 int fileStamp; |
263 engine.AnalysisContext context = contextSource.context; | 265 String code; |
264 Source source = contextSource.source; | 266 CompilationUnit unit; |
265 if (context == null || source == null) { | 267 List<engine.AnalysisError> errors; |
266 return new Response.sortMembersInvalidFile(request); | 268 if (server.options.enableNewAnalysisDriver) { |
| 269 AnalysisDriver driver = server.getAnalysisDriver(file); |
| 270 ParseResult result = await driver.parseFile(file); |
| 271 fileStamp = -1; |
| 272 code = result.content; |
| 273 unit = result.unit; |
| 274 errors = result.errors; |
| 275 } else { |
| 276 // prepare location |
| 277 ContextSourcePair contextSource = server.getContextSourcePair(file); |
| 278 engine.AnalysisContext context = contextSource.context; |
| 279 Source source = contextSource.source; |
| 280 if (context == null || source == null) { |
| 281 server.sendResponse(new Response.sortMembersInvalidFile(request)); |
| 282 return; |
| 283 } |
| 284 // prepare code |
| 285 fileStamp = context.getModificationStamp(source); |
| 286 code = context.getContents(source).data; |
| 287 // prepare parsed unit |
| 288 try { |
| 289 unit = context.parseCompilationUnit(source); |
| 290 } catch (e) { |
| 291 server.sendResponse(new Response.sortMembersInvalidFile(request)); |
| 292 return; |
| 293 } |
| 294 // Get the errors. |
| 295 errors = context.getErrors(source).errors; |
267 } | 296 } |
268 // prepare parsed unit | 297 // Check if there are scan/parse errors in the file. |
269 CompilationUnit unit; | 298 int numScanParseErrors = _getNumberOfScanParseErrors(errors); |
270 try { | 299 if (numScanParseErrors != 0) { |
271 unit = context.parseCompilationUnit(source); | 300 server.sendResponse( |
272 } catch (e) { | 301 new Response.sortMembersParseErrors(request, numScanParseErrors)); |
273 return new Response.sortMembersInvalidFile(request); | 302 return; |
274 } | 303 } |
275 // check if there are scan/parse errors in the file | 304 // Do sort. |
276 engine.AnalysisErrorInfo errors = context.getErrors(source); | |
277 int numScanParseErrors = _getNumberOfScanParseErrors(errors.errors); | |
278 if (numScanParseErrors != 0) { | |
279 return new Response.sortMembersParseErrors(request, numScanParseErrors); | |
280 } | |
281 // do sort | |
282 int fileStamp = context.getModificationStamp(source); | |
283 String code = context.getContents(source).data; | |
284 MemberSorter sorter = new MemberSorter(code, unit); | 305 MemberSorter sorter = new MemberSorter(code, unit); |
285 List<SourceEdit> edits = sorter.sort(); | 306 List<SourceEdit> edits = sorter.sort(); |
286 SourceFileEdit fileEdit = new SourceFileEdit(file, fileStamp, edits: edits); | 307 SourceFileEdit fileEdit = new SourceFileEdit(file, fileStamp, edits: edits); |
287 return new EditSortMembersResult(fileEdit).toResponse(request.id); | 308 server.sendResponse( |
| 309 new EditSortMembersResult(fileEdit).toResponse(request.id)); |
288 } | 310 } |
289 | 311 |
290 Response _getAvailableRefactorings(Request request) { | 312 Response _getAvailableRefactorings(Request request) { |
291 if (searchEngine == null) { | 313 if (searchEngine == null) { |
292 return new Response.noIndexGenerated(request); | 314 return new Response.noIndexGenerated(request); |
293 } | 315 } |
294 _getAvailableRefactoringsImpl(request); | 316 _getAvailableRefactoringsImpl(request); |
295 return Response.DELAYED_RESPONSE; | 317 return Response.DELAYED_RESPONSE; |
296 } | 318 } |
297 | 319 |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 } | 832 } |
811 return new RefactoringStatus(); | 833 return new RefactoringStatus(); |
812 } | 834 } |
813 } | 835 } |
814 | 836 |
815 /** | 837 /** |
816 * [_RefactoringManager] throws instances of this class internally to stop | 838 * [_RefactoringManager] throws instances of this class internally to stop |
817 * processing in a manager that was reset. | 839 * processing in a manager that was reset. |
818 */ | 840 */ |
819 class _ResetError {} | 841 class _ResetError {} |
OLD | NEW |