Chromium Code Reviews| Index: pkg/analysis_server/lib/src/edit/edit_domain.dart |
| =================================================================== |
| --- pkg/analysis_server/lib/src/edit/edit_domain.dart (revision 42828) |
| +++ pkg/analysis_server/lib/src/edit/edit_domain.dart (working copy) |
| @@ -23,6 +23,7 @@ |
| import 'package:analyzer/src/generated/parser.dart' as engine; |
| import 'package:analyzer/src/generated/scanner.dart' as engine; |
| import 'package:analyzer/src/generated/source.dart'; |
| +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.
|
| bool test_simulateRefactoringException_change = false; |
| @@ -56,20 +57,41 @@ |
| } |
| Response format(Request request) { |
| - throw new RequestFailure( |
| - new Response.unsupportedFeature( |
| - request.id, |
| - 'The edit.format request is not yet supported')); |
| -// EditFormatParams params = new EditFormatParams.fromRequest(request); |
| -// String file = params.file; |
| -// int initialOffset = params.selectionOffset; |
| -// int initialLength = params.selectionLength; |
| -// |
| -// List<SourceEdit> edits = <SourceEdit>[]; |
| -// int finalOffset = initialOffset; |
| -// int finalLength = initialLength; |
| -// return new EditFormatResult(edits, finalOffset, finalLength).toResponse(request.id); |
| + EditFormatParams params = new EditFormatParams.fromRequest(request); |
| + String file = params.file; |
| + |
| + engine.AnalysisContext context = server.getAnalysisContext(file); |
| + if (context == null) { |
| + return new Response.formatInvalidFile(request); |
| + } |
|
pquitslund
2015/01/13 18:54:08
Comments welcome especially on error handling. Sh
|
| + |
| + Source source = server.getSource(file); |
| + 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.
|
| + String unformattedSource = contents.data; |
| + |
| + SourceCode code = new SourceCode( |
| + unformattedSource, |
| + uri: null, |
| + isCompilationUnit: true, |
| + selectionStart: params.selectionOffset, |
| + selectionLength: params.selectionLength); |
| + DartFormatter formatter = new DartFormatter(); |
| + SourceCode formattedResult = formatter.formatSource(code); |
| + String formattedSource = formattedResult.text; |
| + |
| + List<SourceEdit> edits = <SourceEdit>[]; |
| + |
| + if (formattedSource != unformattedSource) { |
| + 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.
|
| + new SourceEdit(0, unformattedSource.length, formattedSource); |
| + edits.add(edit); |
| + } |
| + |
| + return new EditFormatResult( |
| + edits, |
| + formattedResult.selectionStart, |
| + formattedResult.selectionLength).toResponse(request.id); |
| } |
| Response getAssists(Request request) { |