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; | 5 library edit.domain; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/collections.dart'; | 10 import 'package:analysis_server/src/collections.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
| 12 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 12 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| 13 import 'package:analysis_server/src/services/correction/assist.dart'; | 13 import 'package:analysis_server/src/services/correction/assist.dart'; |
| 14 import 'package:analysis_server/src/services/correction/fix.dart'; | 14 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 15 import 'package:analysis_server/src/services/correction/sort_members.dart'; | 15 import 'package:analysis_server/src/services/correction/sort_members.dart'; |
| 16 import 'package:analysis_server/src/services/correction/status.dart'; | 16 import 'package:analysis_server/src/services/correction/status.dart'; |
| 17 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 17 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 18 import 'package:analysis_server/src/services/search/search_engine.dart'; | 18 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 19 import 'package:analyzer/src/generated/ast.dart'; | 19 import 'package:analyzer/src/generated/ast.dart'; |
| 20 import 'package:analyzer/src/generated/element.dart'; | 20 import 'package:analyzer/src/generated/element.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart' as engine; | 21 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 22 import 'package:analyzer/src/generated/error.dart' as engine; | 22 import 'package:analyzer/src/generated/error.dart' as engine; |
| 23 import 'package:analyzer/src/generated/parser.dart' as engine; | 23 import 'package:analyzer/src/generated/parser.dart' as engine; |
| 24 import 'package:analyzer/src/generated/scanner.dart' as engine; | 24 import 'package:analyzer/src/generated/scanner.dart' as engine; |
| 25 import 'package:analyzer/src/generated/source.dart'; | 25 import 'package:analyzer/src/generated/source.dart'; |
| 26 import 'package:dart_style/dart_style.dart'; | |
|
danrubel
2015/01/13 19:35:18
Do we need to update the analysis_server pubspec?
pquitslund
2015/01/13 20:06:55
Why not! Done.
| |
| 26 | 27 |
| 27 | 28 |
| 28 bool test_simulateRefactoringException_change = false; | 29 bool test_simulateRefactoringException_change = false; |
| 29 bool test_simulateRefactoringException_final = false; | 30 bool test_simulateRefactoringException_final = false; |
| 30 bool test_simulateRefactoringException_init = false; | 31 bool test_simulateRefactoringException_init = false; |
| 31 | 32 |
| 32 | 33 |
| 33 /** | 34 /** |
| 34 * Instances of the class [EditDomainHandler] implement a [RequestHandler] | 35 * Instances of the class [EditDomainHandler] implement a [RequestHandler] |
| 35 * that handles requests in the edit domain. | 36 * that handles requests in the edit domain. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 49 | 50 |
| 50 /** | 51 /** |
| 51 * Initialize a newly created handler to handle requests for the given [server ]. | 52 * Initialize a newly created handler to handle requests for the given [server ]. |
| 52 */ | 53 */ |
| 53 EditDomainHandler(this.server) { | 54 EditDomainHandler(this.server) { |
| 54 searchEngine = server.searchEngine; | 55 searchEngine = server.searchEngine; |
| 55 refactoringManager = new _RefactoringManager(server, searchEngine); | 56 refactoringManager = new _RefactoringManager(server, searchEngine); |
| 56 } | 57 } |
| 57 | 58 |
| 58 Response format(Request request) { | 59 Response format(Request request) { |
| 59 throw new RequestFailure( | |
| 60 new Response.unsupportedFeature( | |
| 61 request.id, | |
| 62 'The edit.format request is not yet supported')); | |
| 63 | 60 |
| 64 // EditFormatParams params = new EditFormatParams.fromRequest(request); | 61 EditFormatParams params = new EditFormatParams.fromRequest(request); |
| 65 // String file = params.file; | 62 String file = params.file; |
| 66 // int initialOffset = params.selectionOffset; | 63 |
| 67 // int initialLength = params.selectionLength; | 64 engine.AnalysisContext context = server.getAnalysisContext(file); |
| 68 // | 65 if (context == null) { |
| 69 // List<SourceEdit> edits = <SourceEdit>[]; | 66 return new Response.formatInvalidFile(request); |
| 70 // int finalOffset = initialOffset; | 67 } |
|
pquitslund
2015/01/13 18:54:08
Comments welcome especially on error handling. Sh
| |
| 71 // int finalLength = initialLength; | 68 |
| 72 // return new EditFormatResult(edits, finalOffset, finalLength).toResponse(re quest.id); | 69 Source source = server.getSource(file); |
| 70 engine.TimestampedData<String> contents = context.getContents(source); | |
|
Brian Wilkerson
2015/01/13 19:29:47
The method getContents will throw an exception if
pquitslund
2015/01/13 20:06:54
Done.
| |
| 71 String unformattedSource = contents.data; | |
| 72 | |
| 73 SourceCode code = new SourceCode( | |
| 74 unformattedSource, | |
| 75 uri: null, | |
| 76 isCompilationUnit: true, | |
| 77 selectionStart: params.selectionOffset, | |
| 78 selectionLength: params.selectionLength); | |
| 79 DartFormatter formatter = new DartFormatter(); | |
| 80 SourceCode formattedResult = formatter.formatSource(code); | |
| 81 String formattedSource = formattedResult.text; | |
| 82 | |
| 83 List<SourceEdit> edits = <SourceEdit>[]; | |
| 84 | |
| 85 if (formattedSource != unformattedSource) { | |
| 86 SourceEdit edit = | |
|
Brian Wilkerson
2015/01/13 19:29:47
Perhaps add a TODO to consider producing more effi
pquitslund
2015/01/13 20:06:54
Done.
| |
| 87 new SourceEdit(0, unformattedSource.length, formattedSource); | |
| 88 edits.add(edit); | |
| 89 } | |
| 90 | |
| 91 return new EditFormatResult( | |
| 92 edits, | |
| 93 formattedResult.selectionStart, | |
| 94 formattedResult.selectionLength).toResponse(request.id); | |
| 73 } | 95 } |
| 74 | 96 |
| 75 Response getAssists(Request request) { | 97 Response getAssists(Request request) { |
| 76 var params = new EditGetAssistsParams.fromRequest(request); | 98 var params = new EditGetAssistsParams.fromRequest(request); |
| 77 List<SourceChange> changes = <SourceChange>[]; | 99 List<SourceChange> changes = <SourceChange>[]; |
| 78 List<CompilationUnit> units = | 100 List<CompilationUnit> units = |
| 79 server.getResolvedCompilationUnits(params.file); | 101 server.getResolvedCompilationUnits(params.file); |
| 80 if (units.isNotEmpty) { | 102 if (units.isNotEmpty) { |
| 81 CompilationUnit unit = units[0]; | 103 CompilationUnit unit = units[0]; |
| 82 List<Assist> assists = | 104 List<Assist> assists = |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 } | 566 } |
| 545 if (refactoring is RenameRefactoring) { | 567 if (refactoring is RenameRefactoring) { |
| 546 RenameRefactoring renameRefactoring = refactoring; | 568 RenameRefactoring renameRefactoring = refactoring; |
| 547 RenameOptions renameOptions = params.options; | 569 RenameOptions renameOptions = params.options; |
| 548 renameRefactoring.newName = renameOptions.newName; | 570 renameRefactoring.newName = renameOptions.newName; |
| 549 return renameRefactoring.checkNewName(); | 571 return renameRefactoring.checkNewName(); |
| 550 } | 572 } |
| 551 return new RefactoringStatus(); | 573 return new RefactoringStatus(); |
| 552 } | 574 } |
| 553 } | 575 } |
| OLD | NEW |