Skip to content

Commit

Permalink
Don't reuse LSP error code that triggers shutdown for refactor errors
Browse files Browse the repository at this point in the history
Bug: #42573
Change-Id: I615563ed636cf48b4fe84e7588f49bb7137a4f53
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153341
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Danny Tuppeny <danny@tuppeny.com>
  • Loading branch information
DanTup authored and commit-bot@chromium.org committed Jul 6, 2020
1 parent 5d1fbe0 commit 34ad5a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/src/lsp/constants.dart
Expand Up @@ -104,5 +104,5 @@ abstract class ServerErrorCodes {
/// restart the server. However clients should be careful to not restart a
/// crashing server endlessly. VS Code for example doesn't restart a server
/// if it crashes 5 times in the last 180 seconds."
static const ClientServerInconsistentState = ErrorCodes(-32010);
static const ClientServerInconsistentState = ErrorCodes(-32099);
}
26 changes: 26 additions & 0 deletions pkg/analysis_server/test/lsp/rename_test.dart
Expand Up @@ -248,6 +248,16 @@ class RenameTest extends AbstractLspAnalysisServerTest {
expect(error.message, contains('already declares class with name'));
}

Future<void> test_rename_rejectedForSameName() async {
const content = '''
class My^Class {}
''';
final error = await _test_rename_failure(content, 'MyClass');
expect(error.code, equals(ServerErrorCodes.RenameNotValid));
expect(error.message,
contains('new name must be different than the current name'));
}

Future<void> test_rename_rejectedForStaleDocument() async {
const content = '''
class MyClass {}
Expand All @@ -259,6 +269,22 @@ class RenameTest extends AbstractLspAnalysisServerTest {
expect(error.message, contains('Document was modified'));
}

Future<void> test_rename_rejectionsDoNotCrashServer() async {
// Checks that a rename failure does not stop the server from responding
// as was previously the case in https://github.com/dart-lang/sdk/issues/42573
// because the error code was duplicated/reused for ClientServerInconsistentState.
const content = '''
/// Test Class
class My^Class {}
''';
final error = await _test_rename_failure(content, 'MyClass');
expect(error.code, isNotNull);

// Send any other request to ensure the server is still responsive.
final hover = await getHover(mainFileUri, positionFromMarker(content));
expect(hover?.contents, isNotNull);
}

Future<void> test_rename_sdkClass() async {
const content = '''
final a = new [[Ob^ject]]();
Expand Down

0 comments on commit 34ad5a5

Please sign in to comment.