Ensure LSP server advertises it has QuickFixes
Also ensure we only return a bool for code action capabilities if the client doesn't support code action literals.
Change-Id: I277fc406ecdee6b0ee1c284f283cd3cb64fb5bdb
Reviewed-on: https://dart-review.googlesource.com/c/88721
Commit-Queue: Danny Tuppeny <dantup@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/lsp/constants.dart b/pkg/analysis_server/lib/src/lsp/constants.dart
index 74a7949..7674d6f 100644
--- a/pkg/analysis_server/lib/src/lsp/constants.dart
+++ b/pkg/analysis_server/lib/src/lsp/constants.dart
@@ -23,6 +23,7 @@
// We have to explicitly list this for the client to enable built-in command.
CodeActionKind.SourceOrganizeImports,
SortMembers,
+ CodeActionKind.QuickFix,
];
static const SortMembers = const CodeActionKind('source.sortMembers');
}
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart
index 7783434..cdee37d 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_initialize.dart
@@ -38,6 +38,9 @@
server.messageHandler =
new InitializingStateMessageHandler(server, openWorkspacePaths);
+ final codeActionLiteralSupport =
+ params.capabilities.textDocument?.codeAction?.codeActionLiteralSupport;
+
return success(new InitializeResult(new ServerCapabilities(
Either2<TextDocumentSyncOptions, num>.t1(new TextDocumentSyncOptions(
true,
@@ -69,8 +72,13 @@
null,
true, // documentSymbolProvider
null,
- Either2<bool, CodeActionOptions>.t2(
- new CodeActionOptions(DartCodeActionKind.serverSupportedKinds)),
+ // "The `CodeActionOptions` return type is only valid if the client
+ // signals code action literal support via the property
+ // `textDocument.codeAction.codeActionLiteralSupport`."
+ codeActionLiteralSupport != null
+ ? Either2<bool, CodeActionOptions>.t2(
+ new CodeActionOptions(DartCodeActionKind.serverSupportedKinds))
+ : Either2<bool, CodeActionOptions>.t1(true),
null,
true, // documentFormattingProvider
false, // documentRangeFormattingProvider
diff --git a/pkg/analysis_server/tool/lsp_spec/README.md b/pkg/analysis_server/tool/lsp_spec/README.md
index a8ad68e..462d652 100644
--- a/pkg/analysis_server/tool/lsp_spec/README.md
+++ b/pkg/analysis_server/tool/lsp_spec/README.md
@@ -60,8 +60,8 @@
| textDocument/codeAction (sortMembers) | ✅ | ✅ | ✅ | ✅ |
| textDocument/codeAction (organiseImports) | ✅ | ✅ | ✅ | ✅ |
| textDocument/codeAction (refactors) | | | | |
-| textDocument/codeAction (assists) | ✅ | ✅ | ✅ | |
-| textDocument/codeAction (fixes) | ✅ | ✅ | ✅ | |
+| textDocument/codeAction (assists) | ✅ | ✅ | ✅ | ✅ |
+| textDocument/codeAction (fixes) | ✅ | ✅ | ✅ | ✅ |
| textDocument/codeLens | | | | |
| codeLens/resolve | | | | |
| textDocument/documentLink | | | | |