@@ -248,6 +248,16 @@ class RenameTest extends AbstractLspAnalysisServerTest {
248248 expect (error.message, contains ('already declares class with name' ));
249249 }
250250
251+ Future <void > test_rename_rejectedForSameName () async {
252+ const content = '''
253+ class My^Class {}
254+ ''' ;
255+ final error = await _test_rename_failure (content, 'MyClass' );
256+ expect (error.code, equals (ServerErrorCodes .RenameNotValid ));
257+ expect (error.message,
258+ contains ('new name must be different than the current name' ));
259+ }
260+
251261 Future <void > test_rename_rejectedForStaleDocument () async {
252262 const content = '''
253263 class MyClass {}
@@ -259,6 +269,22 @@ class RenameTest extends AbstractLspAnalysisServerTest {
259269 expect (error.message, contains ('Document was modified' ));
260270 }
261271
272+ Future <void > test_rename_rejectionsDoNotCrashServer () async {
273+ // Checks that a rename failure does not stop the server from responding
274+ // as was previously the case in https://github.com/dart-lang/sdk/issues/42573
275+ // because the error code was duplicated/reused for ClientServerInconsistentState.
276+ const content = '''
277+ /// Test Class
278+ class My^Class {}
279+ ''' ;
280+ final error = await _test_rename_failure (content, 'MyClass' );
281+ expect (error.code, isNotNull);
282+
283+ // Send any other request to ensure the server is still responsive.
284+ final hover = await getHover (mainFileUri, positionFromMarker (content));
285+ expect (hover? .contents, isNotNull);
286+ }
287+
262288 Future <void > test_rename_sdkClass () async {
263289 const content = '''
264290 final a = new [[Ob^ject]]();
0 commit comments