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

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

Issue 2466703002: Get code to format from 'overlayState' or from the Source. (Closed)
Patch Set: Created 4 years, 1 month 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
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/plugin/edit/assist/assist_core.dart'; 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
10 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 10 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 */ 62 */
63 EditDomainHandler(this.server) { 63 EditDomainHandler(this.server) {
64 searchEngine = server.searchEngine; 64 searchEngine = server.searchEngine;
65 _newRefactoringManager(); 65 _newRefactoringManager();
66 } 66 }
67 67
68 Response format(Request request) { 68 Response format(Request request) {
69 EditFormatParams params = new EditFormatParams.fromRequest(request); 69 EditFormatParams params = new EditFormatParams.fromRequest(request);
70 String file = params.file; 70 String file = params.file;
71 71
72 ContextSourcePair contextSource = server.getContextSourcePair(file); 72 String unformattedSource;
73
74 engine.AnalysisContext context = contextSource.context;
75 if (context == null) {
76 return new Response.formatInvalidFile(request);
77 }
78
79 Source source = contextSource.source;
80 engine.TimestampedData<String> contents;
81 try { 73 try {
82 contents = context.getContents(source); 74 Source source = server.resourceProvider.getFile(file).createSource();
75 unformattedSource = server.overlayState.getContents(source);
76 unformattedSource ??= source.contents.data;
83 } catch (e) { 77 } catch (e) {
84 return new Response.formatInvalidFile(request); 78 return new Response.formatInvalidFile(request);
85 } 79 }
86 80
87 String unformattedSource = contents.data;
88
89 int start = params.selectionOffset; 81 int start = params.selectionOffset;
90 int length = params.selectionLength; 82 int length = params.selectionLength;
91 83
92 // No need to preserve 0,0 selection 84 // No need to preserve 0,0 selection
93 if (start == 0 && length == 0) { 85 if (start == 0 && length == 0) {
94 start = null; 86 start = null;
95 length = null; 87 length = null;
96 } 88 }
97 89
98 SourceCode code = new SourceCode(unformattedSource, 90 SourceCode code = new SourceCode(unformattedSource,
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 } 806 }
815 return new RefactoringStatus(); 807 return new RefactoringStatus();
816 } 808 }
817 } 809 }
818 810
819 /** 811 /**
820 * [_RefactoringManager] throws instances of this class internally to stop 812 * [_RefactoringManager] throws instances of this class internally to stop
821 * processing in a manager that was reset. 813 * processing in a manager that was reset.
822 */ 814 */
823 class _ResetError {} 815 class _ResetError {}
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/analysis/driver.dart » ('j') | pkg/analyzer/lib/src/dart/analysis/driver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698