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

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

Issue 1099633004: Fix error handling for formatting and update the spec (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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
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/edit/assist/assist_core.dart'; 9 import 'package:analysis_server/edit/assist/assist_core.dart';
10 import 'package:analysis_server/edit/fix/fix_core.dart'; 10 import 'package:analysis_server/edit/fix/fix_core.dart';
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 start = null; 91 start = null;
92 length = null; 92 length = null;
93 } 93 }
94 94
95 SourceCode code = new SourceCode(unformattedSource, 95 SourceCode code = new SourceCode(unformattedSource,
96 uri: null, 96 uri: null,
97 isCompilationUnit: true, 97 isCompilationUnit: true,
98 selectionStart: start, 98 selectionStart: start,
99 selectionLength: length); 99 selectionLength: length);
100 DartFormatter formatter = new DartFormatter(); 100 DartFormatter formatter = new DartFormatter();
101 SourceCode formattedResult = formatter.formatSource(code); 101 SourceCode formattedResult;
102 try {
103 formattedResult = formatter.formatSource(code);
104 } on FormatterException {
105 return new Response.formatWithErrors(request);
106 }
102 String formattedSource = formattedResult.text; 107 String formattedSource = formattedResult.text;
103 108
104 List<SourceEdit> edits = <SourceEdit>[]; 109 List<SourceEdit> edits = <SourceEdit>[];
105 110
106 if (formattedSource != unformattedSource) { 111 if (formattedSource != unformattedSource) {
107 //TODO: replace full replacements with smaller, more targeted edits 112 //TODO: replace full replacements with smaller, more targeted edits
108 SourceEdit edit = 113 SourceEdit edit =
109 new SourceEdit(0, unformattedSource.length, formattedSource); 114 new SourceEdit(0, unformattedSource.length, formattedSource);
110 edits.add(edit); 115 edits.add(edit);
111 } 116 }
112 117
113 int newStart = formattedResult.selectionStart; 118 int newStart = formattedResult.selectionStart;
114 int newLength = formattedResult.selectionLength; 119 int newLength = formattedResult.selectionLength;
115 120
116 // Sending null start/length values would violate protocol, so convert back 121 // Sending null start/length values would violate protocol, so convert back
117 // to 0. 122 // to 0.
118 if (newStart == null) { 123 if (newStart == null) {
119 newStart = 0; 124 newStart = 0;
120 } 125 }
121 if (newLength == null) { 126 if (newLength == null) {
122 newLength = 0; 127 newLength = 0;
123 } 128 }
124 129
125 return new EditFormatResult(edits, newStart, 130 return new EditFormatResult(edits, newStart, newLength)
126 newLength).toResponse(request.id); 131 .toResponse(request.id);
127 } 132 }
128 133
129 Response getAssists(Request request) { 134 Response getAssists(Request request) {
130 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request); 135 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request);
131 ContextSourcePair pair = server.getContextSourcePair(params.file); 136 ContextSourcePair pair = server.getContextSourcePair(params.file);
132 engine.AnalysisContext context = pair.context; 137 engine.AnalysisContext context = pair.context;
133 Source source = pair.source; 138 Source source = pair.source;
134 List<SourceChange> changes = <SourceChange>[]; 139 List<SourceChange> changes = <SourceChange>[];
135 if (context != null && source != null) { 140 if (context != null && source != null) {
136 List<Assist> assists = computeAssists(plugin, context, 141 List<Assist> assists =
137 source, params.offset, params.length); 142 computeAssists(plugin, context, source, params.offset, params.length);
138 assists.forEach((Assist assist) { 143 assists.forEach((Assist assist) {
139 changes.add(assist.change); 144 changes.add(assist.change);
140 }); 145 });
141 } 146 }
142 return new EditGetAssistsResult(changes).toResponse(request.id); 147 return new EditGetAssistsResult(changes).toResponse(request.id);
143 } 148 }
144 149
145 Response getFixes(Request request) { 150 Response getFixes(Request request) {
146 var params = new EditGetFixesParams.fromRequest(request); 151 var params = new EditGetFixesParams.fromRequest(request);
147 String file = params.file; 152 String file = params.file;
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 650 }
646 if (refactoring is RenameRefactoring) { 651 if (refactoring is RenameRefactoring) {
647 RenameRefactoring renameRefactoring = refactoring; 652 RenameRefactoring renameRefactoring = refactoring;
648 RenameOptions renameOptions = params.options; 653 RenameOptions renameOptions = params.options;
649 renameRefactoring.newName = renameOptions.newName; 654 renameRefactoring.newName = renameOptions.newName;
650 return renameRefactoring.checkNewName(); 655 return renameRefactoring.checkNewName();
651 } 656 }
652 return new RefactoringStatus(); 657 return new RefactoringStatus();
653 } 658 }
654 } 659 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698