Skip to content

Commit 34ad5a5

Browse files
DanTupcommit-bot@chromium.org
authored andcommitted
Don't reuse LSP error code that triggers shutdown for refactor errors
Bug: #42573 Change-Id: I615563ed636cf48b4fe84e7588f49bb7137a4f53 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153341 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Danny Tuppeny <[email protected]>
1 parent 5d1fbe0 commit 34ad5a5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pkg/analysis_server/lib/src/lsp/constants.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ abstract class ServerErrorCodes {
104104
/// restart the server. However clients should be careful to not restart a
105105
/// crashing server endlessly. VS Code for example doesn't restart a server
106106
/// if it crashes 5 times in the last 180 seconds."
107-
static const ClientServerInconsistentState = ErrorCodes(-32010);
107+
static const ClientServerInconsistentState = ErrorCodes(-32099);
108108
}

pkg/analysis_server/test/lsp/rename_test.dart

+26
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)