Skip to content

Commit 23a59bc

Browse files
authored
Merge pull request #178 from codedownio/code-action-options
Add support CodeActionOptions (added in LSP spec 3.11.0)
2 parents bfbd863 + 3043c68 commit 23a59bc

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

haskell-lsp-types/src/Language/Haskell/LSP/Types/CodeAction.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Code Action Request
2323
2424
https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#code-action-request
2525
26-
The code action request is sent from the client to the server tocompute commands
26+
The code action request is sent from the client to the server to compute commands
2727
for a given text document and range. These commands are typically code fixes to
2828
either fix problems or to beautify/refactor code. The result of a
2929
textDocument/codeAction request is an array of Command literals which are

haskell-lsp-types/src/Language/Haskell/LSP/Types/DataTypesJSON.hs

+30-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Data.Aeson.Types
1818
import Data.Text (Text)
1919
import qualified Data.Text as T
2020
import Language.Haskell.LSP.Types.ClientCapabilities
21+
import Language.Haskell.LSP.Types.CodeAction
2122
import Language.Haskell.LSP.Types.Command
2223
import Language.Haskell.LSP.Types.Constants
2324
import Language.Haskell.LSP.Types.Diagnostic
@@ -259,6 +260,30 @@ data CodeLensOptions =
259260

260261
deriveJSON lspOptions ''CodeLensOptions
261262

263+
-- ---------------------------------------------------------------------
264+
{-
265+
/**
266+
* Code Action options.
267+
*/
268+
export interface CodeActionOptions {
269+
/**
270+
* CodeActionKinds that this server may return.
271+
*
272+
* The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server
273+
* may list out every specific kind they provide.
274+
*/
275+
codeActionKinds?: CodeActionKind[];
276+
}
277+
-}
278+
279+
data CodeActionOptions =
280+
CodeActionOptionsStatic Bool
281+
| CodeActionOptions
282+
{ _codeActionKinds :: Maybe [CodeActionKind]
283+
} deriving (Read,Show,Eq)
284+
285+
deriveJSON (lspOptions { sumEncoding = A.UntaggedValue }) ''CodeActionOptions
286+
262287
-- ---------------------------------------------------------------------
263288
{-
264289
/**
@@ -463,9 +488,11 @@ interface ServerCapabilities {
463488
*/
464489
workspaceSymbolProvider?: boolean;
465490
/**
466-
* The server provides code actions.
491+
* The server provides code actions. The `CodeActionOptions` return type is only
492+
* valid if the client signals code action literal support via the property
493+
* `textDocument.codeAction.codeActionLiteralSupport`.
467494
*/
468-
codeActionProvider?: boolean;
495+
codeActionProvider?: boolean | CodeActionOptions;
469496
/**
470497
* The server provides code lens.
471498
*/
@@ -662,7 +689,7 @@ data InitializeResponseCapabilitiesInner =
662689
-- | The server provides workspace symbol support.
663690
, _workspaceSymbolProvider :: Maybe Bool
664691
-- | The server provides code actions.
665-
, _codeActionProvider :: Maybe Bool
692+
, _codeActionProvider :: Maybe CodeActionOptions
666693
-- | The server provides code lens.
667694
, _codeLensProvider :: Maybe CodeLensOptions
668695
-- | The server provides document formatting.

src/Language/Haskell/LSP/Core.hs

+3-2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ data Options =
105105
, signatureHelpProvider :: Maybe J.SignatureHelpOptions
106106
, typeDefinitionProvider :: Maybe J.GotoOptions
107107
, implementationProvider :: Maybe J.GotoOptions
108+
, codeActionProvider :: Maybe J.CodeActionOptions
108109
, codeLensProvider :: Maybe J.CodeLensOptions
109110
, documentOnTypeFormattingProvider :: Maybe J.DocumentOnTypeFormattingOptions
110111
, documentLinkProvider :: Maybe J.DocumentLinkOptions
@@ -116,7 +117,7 @@ data Options =
116117
instance Default Options where
117118
def = Options Nothing Nothing Nothing Nothing Nothing
118119
Nothing Nothing Nothing Nothing Nothing
119-
Nothing
120+
Nothing Nothing
120121

121122
-- | A function to publish diagnostics. It aggregates all diagnostics pertaining
122123
-- to a particular version of a document, by source, and sends a
@@ -846,7 +847,7 @@ initializeRequestHandler' onStartup mHandler tvarCtx req@(J.RequestMessage _ ori
846847
, J._documentHighlightProvider = supported (documentHighlightHandler h)
847848
, J._documentSymbolProvider = supported (documentSymbolHandler h)
848849
, J._workspaceSymbolProvider = supported (workspaceSymbolHandler h)
849-
, J._codeActionProvider = supported (codeActionHandler h)
850+
, J._codeActionProvider = codeActionProvider o
850851
, J._codeLensProvider = codeLensProvider o
851852
, J._documentFormattingProvider = supported (documentFormattingHandler h)
852853
, J._documentRangeFormattingProvider = supported (documentRangeFormattingHandler h)

0 commit comments

Comments
 (0)