Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/fix/fix_core.dart'; | 11 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 11 import 'package:analysis_server/src/analysis_server.dart'; | 12 import 'package:analysis_server/src/analysis_server.dart'; |
| 12 import 'package:analysis_server/src/collections.dart'; | 13 import 'package:analysis_server/src/collections.dart'; |
| 13 import 'package:analysis_server/src/constants.dart'; | 14 import 'package:analysis_server/src/constants.dart'; |
| 14 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 15 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| 15 import 'package:analysis_server/src/services/correction/assist.dart'; | 16 import 'package:analysis_server/src/services/correction/assist.dart'; |
| 17 import 'package:analysis_server/src/services/correction/assist_internal.dart'; | |
| 16 import 'package:analysis_server/src/services/correction/fix.dart'; | 18 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 17 import 'package:analysis_server/src/services/correction/organize_directives.dart '; | 19 import 'package:analysis_server/src/services/correction/organize_directives.dart '; |
| 18 import 'package:analysis_server/src/services/correction/sort_members.dart'; | 20 import 'package:analysis_server/src/services/correction/sort_members.dart'; |
| 19 import 'package:analysis_server/src/services/correction/status.dart'; | 21 import 'package:analysis_server/src/services/correction/status.dart'; |
| 20 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 22 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 21 import 'package:analysis_server/src/services/search/search_engine.dart'; | 23 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 22 import 'package:analyzer/dart/ast/ast.dart'; | 24 import 'package:analyzer/dart/ast/ast.dart'; |
| 23 import 'package:analyzer/dart/element/element.dart'; | 25 import 'package:analyzer/dart/element/element.dart'; |
| 24 import 'package:analyzer/error/error.dart' as engine; | 26 import 'package:analyzer/error/error.dart' as engine; |
| 25 import 'package:analyzer/src/dart/analysis/driver.dart'; | 27 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 } | 127 } |
| 126 if (newLength == null) { | 128 if (newLength == null) { |
| 127 newLength = 0; | 129 newLength = 0; |
| 128 } | 130 } |
| 129 | 131 |
| 130 return new EditFormatResult(edits, newStart, newLength) | 132 return new EditFormatResult(edits, newStart, newLength) |
| 131 .toResponse(request.id); | 133 .toResponse(request.id); |
| 132 } | 134 } |
| 133 | 135 |
| 134 Future getAssists(Request request) async { | 136 Future getAssists(Request request) async { |
| 137 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request); | |
| 138 List<Assist> assists; | |
| 135 if (server.options.enableNewAnalysisDriver) { | 139 if (server.options.enableNewAnalysisDriver) { |
| 136 // TODO(scheglov) implement for the new analysis driver | 140 AnalysisResult result = await server.getAnalysisResult(params.file); |
| 137 return; | 141 CompilationUnit unit = result.unit; |
| 142 DartAssistContext dartAssistContext = new _DartAssistContextForValues( | |
| 143 unit.element.source, | |
| 144 params.offset, | |
| 145 params.length, | |
| 146 unit.element.context, | |
| 147 unit); | |
| 148 try { | |
| 149 AssistProcessor processor = new AssistProcessor(dartAssistContext); | |
| 150 assists = await processor.compute(); | |
| 151 } catch (_) {} | |
| 152 } else { | |
| 153 ContextSourcePair pair = server.getContextSourcePair(params.file); | |
| 154 engine.AnalysisContext context = pair.context; | |
| 155 Source source = pair.source; | |
| 156 if (context != null && source != null) { | |
| 157 assists = await computeAssists( | |
| 158 server.serverPlugin, context, source, params.offset, params.length); | |
| 159 } | |
| 138 } | 160 } |
| 139 EditGetAssistsParams params = new EditGetAssistsParams.fromRequest(request); | 161 // Send the assist changes. |
| 140 ContextSourcePair pair = server.getContextSourcePair(params.file); | |
| 141 engine.AnalysisContext context = pair.context; | |
| 142 Source source = pair.source; | |
| 143 List<SourceChange> changes = <SourceChange>[]; | 162 List<SourceChange> changes = <SourceChange>[]; |
| 144 if (context != null && source != null) { | 163 assists?.forEach((Assist assist) { |
| 145 List<Assist> assists = await computeAssists( | 164 changes.add(assist.change); |
| 146 server.serverPlugin, context, source, params.offset, params.length); | 165 }); |
| 147 assists.forEach((Assist assist) { | |
| 148 changes.add(assist.change); | |
| 149 }); | |
| 150 } | |
| 151 Response response = | 166 Response response = |
| 152 new EditGetAssistsResult(changes).toResponse(request.id); | 167 new EditGetAssistsResult(changes).toResponse(request.id); |
| 153 server.sendResponse(response); | 168 server.sendResponse(response); |
| 154 } | 169 } |
| 155 | 170 |
| 156 Future getFixes(Request request) async { | 171 Future getFixes(Request request) async { |
| 157 if (server.options.enableNewAnalysisDriver) { | 172 if (server.options.enableNewAnalysisDriver) { |
| 158 // TODO(scheglov) implement for the new analysis driver | 173 // TODO(scheglov) implement for the new analysis driver |
| 159 return; | 174 return; |
| 160 } | 175 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 383 for (engine.AnalysisError error in errors) { | 398 for (engine.AnalysisError error in errors) { |
| 384 if (error.errorCode is engine.ScannerErrorCode || | 399 if (error.errorCode is engine.ScannerErrorCode || |
| 385 error.errorCode is engine.ParserErrorCode) { | 400 error.errorCode is engine.ParserErrorCode) { |
| 386 numScanParseErrors++; | 401 numScanParseErrors++; |
| 387 } | 402 } |
| 388 } | 403 } |
| 389 return numScanParseErrors; | 404 return numScanParseErrors; |
| 390 } | 405 } |
| 391 } | 406 } |
| 392 | 407 |
| 408 class _DartAssistContextForValues implements DartAssistContext { | |
|
Paul Berry
2016/11/04 23:25:27
Can you clarify what "ForValues" means?
scheglov
2016/11/04 23:49:20
I will add a documentation comment.
| |
| 409 @override | |
| 410 final Source source; | |
| 411 | |
| 412 @override | |
| 413 final int selectionOffset; | |
| 414 | |
| 415 @override | |
| 416 final int selectionLength; | |
| 417 | |
| 418 @override | |
| 419 final engine.AnalysisContext analysisContext; | |
| 420 | |
| 421 @override | |
| 422 final CompilationUnit unit; | |
| 423 | |
| 424 _DartAssistContextForValues(this.source, this.selectionOffset, | |
| 425 this.selectionLength, this.analysisContext, this.unit); | |
| 426 } | |
| 427 | |
| 393 /** | 428 /** |
| 394 * An object managing a single [Refactoring] instance. | 429 * An object managing a single [Refactoring] instance. |
| 395 * | 430 * |
| 396 * The instance is identified by its kind, file, offset and length. | 431 * The instance is identified by its kind, file, offset and length. |
| 397 * It is initialized when the a set of parameters is given for the first time. | 432 * It is initialized when the a set of parameters is given for the first time. |
| 398 * All subsequent requests are performed on this [Refactoring] instance. | 433 * All subsequent requests are performed on this [Refactoring] instance. |
| 399 * | 434 * |
| 400 * Once new set of parameters is received, the previous [Refactoring] instance | 435 * Once new set of parameters is received, the previous [Refactoring] instance |
| 401 * is invalidated and a new one is created and initialized. | 436 * is invalidated and a new one is created and initialized. |
| 402 */ | 437 */ |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 } | 867 } |
| 833 return new RefactoringStatus(); | 868 return new RefactoringStatus(); |
| 834 } | 869 } |
| 835 } | 870 } |
| 836 | 871 |
| 837 /** | 872 /** |
| 838 * [_RefactoringManager] throws instances of this class internally to stop | 873 * [_RefactoringManager] throws instances of this class internally to stop |
| 839 * processing in a manager that was reset. | 874 * processing in a manager that was reset. |
| 840 */ | 875 */ |
| 841 class _ResetError {} | 876 class _ResetError {} |
| OLD | NEW |