Also return lineInfo and oldName from canRename
Change-Id: I5ae683cdfe3a82d8dea72745d77d8dcb435c0759
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202280
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/cider/rename.dart b/pkg/analysis_server/lib/src/cider/rename.dart
index 72e884b..6ea1b32 100644
--- a/pkg/analysis_server/lib/src/cider/rename.dart
+++ b/pkg/analysis_server/lib/src/cider/rename.dart
@@ -4,10 +4,19 @@
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/micro/resolve_file.dart';
import 'package:analyzer/src/dart/micro/utils.dart';
+class CanRenameResponse {
+ final LineInfo lineInfo;
+ final RenameRefactoringElement refactoringElement;
+ final String oldName;
+
+ CanRenameResponse(this.lineInfo, this.refactoringElement, this.oldName);
+}
+
class CiderRenameComputer {
final FileResolver _fileResolver;
@@ -15,7 +24,7 @@
/// Check if the identifier at the [line], [column] for the file at the
/// [filePath] can be renamed.
- RenameRefactoringElement? canRename(String filePath, int line, int column) {
+ CanRenameResponse? canRename(String filePath, int line, int column) {
var resolvedUnit = _fileResolver.resolve(path: filePath);
var lineInfo = resolvedUnit.lineInfo;
var offset = lineInfo.getOffsetOfLine(line) + column;
@@ -35,7 +44,11 @@
if (!_canRenameElement(element)) {
return null;
}
- return RenameRefactoring.getElementToRename(node, element);
+ var refactoring = RenameRefactoring.getElementToRename(node, element);
+ if (refactoring != null) {
+ return CanRenameResponse(lineInfo, refactoring, element.displayName);
+ }
+ return null;
}
bool _canRenameElement(Element element) {
diff --git a/pkg/analysis_server/test/src/cider/rename_test.dart b/pkg/analysis_server/test/src/cider/rename_test.dart
index 290379f..31c96d5 100644
--- a/pkg/analysis_server/test/src/cider/rename_test.dart
+++ b/pkg/analysis_server/test/src/cider/rename_test.dart
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:analysis_server/src/cider/rename.dart';
-import 'package:analysis_server/src/services/refactoring/refactoring.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -31,8 +30,8 @@
''');
expect(refactor, isNotNull);
- expect(refactor!.element.name, 'bar');
- expect(refactor.offset, _correctionContext.offset);
+ expect(refactor!.refactoringElement.element.name, 'bar');
+ expect(refactor.refactoringElement.offset, _correctionContext.offset);
}
void test_canRename_function() {
@@ -42,8 +41,8 @@
''');
expect(refactor, isNotNull);
- expect(refactor!.element.name, 'foo');
- expect(refactor.offset, _correctionContext.offset);
+ expect(refactor!.refactoringElement.element.name, 'foo');
+ expect(refactor.refactoringElement.offset, _correctionContext.offset);
}
void test_canRename_label() {
@@ -58,8 +57,8 @@
''');
expect(refactor, isNotNull);
- expect(refactor!.element.name, 'myLabel');
- expect(refactor.offset, _correctionContext.offset);
+ expect(refactor!.refactoringElement.element.name, 'myLabel');
+ expect(refactor.refactoringElement.offset, _correctionContext.offset);
}
void test_canRename_local() {
@@ -70,8 +69,8 @@
''');
expect(refactor, isNotNull);
- expect(refactor!.element.name, 'a');
- expect(refactor.offset, _correctionContext.offset);
+ expect(refactor!.refactoringElement.element.name, 'a');
+ expect(refactor.refactoringElement.offset, _correctionContext.offset);
}
void test_canRename_method() {
@@ -82,8 +81,8 @@
''');
expect(refactor, isNotNull);
- expect(refactor!.element.name, 'foo');
- expect(refactor.offset, _correctionContext.offset);
+ expect(refactor!.refactoringElement.element.name, 'foo');
+ expect(refactor.refactoringElement.offset, _correctionContext.offset);
}
void test_canRename_operator() {
@@ -104,11 +103,11 @@
''');
expect(refactor, isNotNull);
- expect(refactor!.element.name, 'bar');
- expect(refactor.offset, _correctionContext.offset);
+ expect(refactor!.refactoringElement.element.name, 'bar');
+ expect(refactor.refactoringElement.offset, _correctionContext.offset);
}
- RenameRefactoringElement? _compute(String content) {
+ CanRenameResponse? _compute(String content) {
_updateFile(content);
return CiderRenameComputer(