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

Side by Side Diff: pkg/analysis_server/lib/src/edit/edit_domain.dart

Issue 894863002: Formatter service API tweaks. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return new Response.formatInvalidFile(request); 66 return new Response.formatInvalidFile(request);
67 } 67 }
68 68
69 Source source = server.getSource(file); 69 Source source = server.getSource(file);
70 engine.TimestampedData<String> contents; 70 engine.TimestampedData<String> contents;
71 try { 71 try {
72 contents = context.getContents(source); 72 contents = context.getContents(source);
73 } catch (e) { 73 } catch (e) {
74 return new Response.formatInvalidFile(request); 74 return new Response.formatInvalidFile(request);
75 } 75 }
76
76 String unformattedSource = contents.data; 77 String unformattedSource = contents.data;
77 78
79 int start = params.selectionOffset;
80 int length = params.selectionLength;
81
82 // No need to preserve 0,0 selection
83 if (start == 0 && length == 0) {
84 start = null;
85 length = null;
86 }
87
78 SourceCode code = new SourceCode( 88 SourceCode code = new SourceCode(
79 unformattedSource, 89 unformattedSource,
80 uri: null, 90 uri: null,
81 isCompilationUnit: true, 91 isCompilationUnit: true,
82 selectionStart: params.selectionOffset, 92 selectionStart: start,
83 selectionLength: params.selectionLength); 93 selectionLength: length);
84 DartFormatter formatter = new DartFormatter(); 94 DartFormatter formatter = new DartFormatter();
85 SourceCode formattedResult = formatter.formatSource(code); 95 SourceCode formattedResult = formatter.formatSource(code);
86 String formattedSource = formattedResult.text; 96 String formattedSource = formattedResult.text;
87 97
88 List<SourceEdit> edits = <SourceEdit>[]; 98 List<SourceEdit> edits = <SourceEdit>[];
89 99
90 if (formattedSource != unformattedSource) { 100 if (formattedSource != unformattedSource) {
91 //TODO: replace full replacements with smaller, more targeted edits 101 //TODO: replace full replacements with smaller, more targeted edits
92 SourceEdit edit = 102 SourceEdit edit =
93 new SourceEdit(0, unformattedSource.length, formattedSource); 103 new SourceEdit(0, unformattedSource.length, formattedSource);
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } 615 }
606 if (refactoring is RenameRefactoring) { 616 if (refactoring is RenameRefactoring) {
607 RenameRefactoring renameRefactoring = refactoring; 617 RenameRefactoring renameRefactoring = refactoring;
608 RenameOptions renameOptions = params.options; 618 RenameOptions renameOptions = params.options;
609 renameRefactoring.newName = renameOptions.newName; 619 renameRefactoring.newName = renameOptions.newName;
610 return renameRefactoring.checkNewName(); 620 return renameRefactoring.checkNewName();
611 } 621 }
612 return new RefactoringStatus(); 622 return new RefactoringStatus();
613 } 623 }
614 } 624 }
OLDNEW
« 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