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

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

Issue 2551023005: Prepare for decoupling analyzer ASTs from element model. (Closed)
Patch Set: Address review comments Created 4 years 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/assist/assist_dart.dart'; 10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart';
11 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 11 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
12 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; 12 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
13 import 'package:analysis_server/src/analysis_server.dart'; 13 import 'package:analysis_server/src/analysis_server.dart';
14 import 'package:analysis_server/src/collections.dart'; 14 import 'package:analysis_server/src/collections.dart';
15 import 'package:analysis_server/src/constants.dart'; 15 import 'package:analysis_server/src/constants.dart';
16 import 'package:analysis_server/src/protocol_server.dart' hide Element; 16 import 'package:analysis_server/src/protocol_server.dart' hide Element;
17 import 'package:analysis_server/src/services/correction/assist.dart'; 17 import 'package:analysis_server/src/services/correction/assist.dart';
18 import 'package:analysis_server/src/services/correction/assist_internal.dart'; 18 import 'package:analysis_server/src/services/correction/assist_internal.dart';
19 import 'package:analysis_server/src/services/correction/fix.dart'; 19 import 'package:analysis_server/src/services/correction/fix.dart';
20 import 'package:analysis_server/src/services/correction/fix_internal.dart'; 20 import 'package:analysis_server/src/services/correction/fix_internal.dart';
21 import 'package:analysis_server/src/services/correction/organize_directives.dart '; 21 import 'package:analysis_server/src/services/correction/organize_directives.dart ';
22 import 'package:analysis_server/src/services/correction/sort_members.dart'; 22 import 'package:analysis_server/src/services/correction/sort_members.dart';
23 import 'package:analysis_server/src/services/correction/status.dart'; 23 import 'package:analysis_server/src/services/correction/status.dart';
24 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 24 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
25 import 'package:analysis_server/src/services/search/search_engine.dart'; 25 import 'package:analysis_server/src/services/search/search_engine.dart';
26 import 'package:analyzer/dart/ast/ast.dart'; 26 import 'package:analyzer/dart/ast/ast.dart';
27 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
27 import 'package:analyzer/dart/element/element.dart'; 28 import 'package:analyzer/dart/element/element.dart';
28 import 'package:analyzer/error/error.dart' as engine; 29 import 'package:analyzer/error/error.dart' as engine;
29 import 'package:analyzer/file_system/file_system.dart'; 30 import 'package:analyzer/file_system/file_system.dart';
30 import 'package:analyzer/src/dart/analysis/driver.dart'; 31 import 'package:analyzer/src/dart/analysis/driver.dart';
31 import 'package:analyzer/src/dart/scanner/scanner.dart' as engine; 32 import 'package:analyzer/src/dart/scanner/scanner.dart' as engine;
32 import 'package:analyzer/src/error/codes.dart' as engine; 33 import 'package:analyzer/src/error/codes.dart' as engine;
33 import 'package:analyzer/src/generated/engine.dart' as engine; 34 import 'package:analyzer/src/generated/engine.dart' as engine;
34 import 'package:analyzer/src/generated/parser.dart' as engine; 35 import 'package:analyzer/src/generated/parser.dart' as engine;
35 import 'package:analyzer/src/generated/source.dart'; 36 import 'package:analyzer/src/generated/source.dart';
36 import 'package:analyzer/task/dart.dart'; 37 import 'package:analyzer/task/dart.dart';
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 .toResponse(request.id); 137 .toResponse(request.id);
137 } 138 }
138 139
139 Future getAssists(Request request) async { 140 Future getAssists(Request request) async {
140 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request); 141 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request);
141 List<Assist> assists; 142 List<Assist> assists;
142 if (server.options.enableNewAnalysisDriver) { 143 if (server.options.enableNewAnalysisDriver) {
143 AnalysisResult result = await server.getAnalysisResult(params.file); 144 AnalysisResult result = await server.getAnalysisResult(params.file);
144 if (result != null) { 145 if (result != null) {
145 CompilationUnit unit = result.unit; 146 CompilationUnit unit = result.unit;
147 CompilationUnitElement compilationUnitElement =
148 resolutionMap.elementForCompilationUnit(unit);
146 DartAssistContext dartAssistContext = new _DartAssistContextForValues( 149 DartAssistContext dartAssistContext = new _DartAssistContextForValues(
147 unit.element.source, 150 compilationUnitElement.source,
148 params.offset, 151 params.offset,
149 params.length, 152 params.length,
150 unit.element.context, 153 compilationUnitElement.context,
151 unit); 154 unit);
152 try { 155 try {
153 AssistProcessor processor = new AssistProcessor(dartAssistContext); 156 AssistProcessor processor = new AssistProcessor(dartAssistContext);
154 assists = await processor.compute(); 157 assists = await processor.compute();
155 } catch (_) {} 158 } catch (_) {}
156 } 159 }
157 } else { 160 } else {
158 ContextSourcePair pair = server.getContextSourcePair(params.file); 161 ContextSourcePair pair = server.getContextSourcePair(params.file);
159 engine.AnalysisContext context = pair.context; 162 engine.AnalysisContext context = pair.context;
160 Source source = pair.source; 163 Source source = pair.source;
(...skipping 21 matching lines...) Expand all
182 if (server.options.enableNewAnalysisDriver) { 185 if (server.options.enableNewAnalysisDriver) {
183 AnalysisResult result = await server.getAnalysisResult(file); 186 AnalysisResult result = await server.getAnalysisResult(file);
184 if (result != null) { 187 if (result != null) {
185 CompilationUnit unit = result.unit; 188 CompilationUnit unit = result.unit;
186 LineInfo lineInfo = result.lineInfo; 189 LineInfo lineInfo = result.lineInfo;
187 int requestLine = lineInfo.getLocation(offset).lineNumber; 190 int requestLine = lineInfo.getLocation(offset).lineNumber;
188 for (engine.AnalysisError error in result.errors) { 191 for (engine.AnalysisError error in result.errors) {
189 int errorLine = lineInfo.getLocation(error.offset).lineNumber; 192 int errorLine = lineInfo.getLocation(error.offset).lineNumber;
190 if (errorLine == requestLine) { 193 if (errorLine == requestLine) {
191 var context = new _DartFixContextImpl( 194 var context = new _DartFixContextImpl(
192 server.resourceProvider, unit.element.context, unit, error); 195 server.resourceProvider,
196 resolutionMap.elementForCompilationUnit(unit).context,
197 unit,
198 error);
193 List<Fix> fixes = 199 List<Fix> fixes =
194 await new DefaultFixContributor().internalComputeFixes(context); 200 await new DefaultFixContributor().internalComputeFixes(context);
195 if (fixes.isNotEmpty) { 201 if (fixes.isNotEmpty) {
196 AnalysisError serverError = 202 AnalysisError serverError =
197 newAnalysisError_fromEngine(lineInfo, error); 203 newAnalysisError_fromEngine(lineInfo, error);
198 AnalysisErrorFixes errorFixes = 204 AnalysisErrorFixes errorFixes =
199 new AnalysisErrorFixes(serverError); 205 new AnalysisErrorFixes(serverError);
200 errorFixesList.add(errorFixes); 206 errorFixesList.add(errorFixes);
201 fixes.forEach((fix) { 207 fixes.forEach((fix) {
202 errorFixes.fixes.add(fix.change); 208 errorFixes.fixes.add(fix.change);
203 }); 209 });
204 } 210 }
205 } 211 }
206 } 212 }
207 } 213 }
208 } else { 214 } else {
209 CompilationUnit unit = await server.getResolvedCompilationUnit(file); 215 CompilationUnit unit = await server.getResolvedCompilationUnit(file);
210 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); 216 engine.AnalysisErrorInfo errorInfo = server.getErrors(file);
211 LineInfo lineInfo = errorInfo?.lineInfo; 217 LineInfo lineInfo = errorInfo?.lineInfo;
212 if (unit != null && errorInfo != null && lineInfo != null) { 218 if (unit != null && errorInfo != null && lineInfo != null) {
213 int requestLine = lineInfo.getLocation(offset).lineNumber; 219 int requestLine = lineInfo.getLocation(offset).lineNumber;
214 for (engine.AnalysisError error in errorInfo.errors) { 220 for (engine.AnalysisError error in errorInfo.errors) {
215 int errorLine = lineInfo.getLocation(error.offset).lineNumber; 221 int errorLine = lineInfo.getLocation(error.offset).lineNumber;
216 if (errorLine == requestLine) { 222 if (errorLine == requestLine) {
217 List<Fix> fixes = await computeFixes(server.serverPlugin, 223 List<Fix> fixes = await computeFixes(
218 server.resourceProvider, unit.element.context, error); 224 server.serverPlugin,
225 server.resourceProvider,
226 resolutionMap.elementForCompilationUnit(unit).context,
227 error);
219 if (fixes.isNotEmpty) { 228 if (fixes.isNotEmpty) {
220 AnalysisError serverError = 229 AnalysisError serverError =
221 newAnalysisError_fromEngine(lineInfo, error); 230 newAnalysisError_fromEngine(lineInfo, error);
222 AnalysisErrorFixes errorFixes = 231 AnalysisErrorFixes errorFixes =
223 new AnalysisErrorFixes(serverError); 232 new AnalysisErrorFixes(serverError);
224 errorFixesList.add(errorFixes); 233 errorFixesList.add(errorFixes);
225 fixes.forEach((fix) { 234 fixes.forEach((fix) {
226 errorFixes.fixes.add(fix.change); 235 errorFixes.fixes.add(fix.change);
227 }); 236 });
228 } 237 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 unit = result.unit; 298 unit = result.unit;
290 errors = result.errors; 299 errors = result.errors;
291 } else { 300 } else {
292 // prepare resolved unit 301 // prepare resolved unit
293 unit = await server.getResolvedCompilationUnit(file); 302 unit = await server.getResolvedCompilationUnit(file);
294 if (unit == null) { 303 if (unit == null) {
295 server.sendResponse(new Response.fileNotAnalyzed(request, file)); 304 server.sendResponse(new Response.fileNotAnalyzed(request, file));
296 return; 305 return;
297 } 306 }
298 // prepare context 307 // prepare context
299 engine.AnalysisContext context = unit.element.context; 308 CompilationUnitElement compilationUnitElement =
300 Source source = unit.element.source; 309 resolutionMap.elementForCompilationUnit(unit);
310 engine.AnalysisContext context = compilationUnitElement.context;
311 Source source = compilationUnitElement.source;
301 errors = context.computeErrors(source); 312 errors = context.computeErrors(source);
302 // prepare code 313 // prepare code
303 fileStamp = context.getModificationStamp(source); 314 fileStamp = context.getModificationStamp(source);
304 code = context.getContents(source).data; 315 code = context.getContents(source).data;
305 } 316 }
306 // check if there are scan/parse errors in the file 317 // check if there are scan/parse errors in the file
307 int numScanParseErrors = _getNumberOfScanParseErrors(errors); 318 int numScanParseErrors = _getNumberOfScanParseErrors(errors);
308 if (numScanParseErrors != 0) { 319 if (numScanParseErrors != 0) {
309 server.sendResponse(new Response.organizeDirectivesError( 320 server.sendResponse(new Response.organizeDirectivesError(
310 request, 'File has $numScanParseErrors scan/parse errors.')); 321 request, 'File has $numScanParseErrors scan/parse errors.'));
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 } 964 }
954 return new RefactoringStatus(); 965 return new RefactoringStatus();
955 } 966 }
956 } 967 }
957 968
958 /** 969 /**
959 * [_RefactoringManager] throws instances of this class internally to stop 970 * [_RefactoringManager] throws instances of this class internally to stop
960 * processing in a manager that was reset. 971 * processing in a manager that was reset.
961 */ 972 */
962 class _ResetError {} 973 class _ResetError {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698