Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: pkg/analysis_server/lib/src/edit/edit_domain.dart

Issue 833903005: Analysis server format service wiring (and protocol doc update). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/doc/api.html ('k') | pkg/analysis_server/lib/src/generated_protocol.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « pkg/analysis_server/doc/api.html ('k') | pkg/analysis_server/lib/src/generated_protocol.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698