Skip to content

Add support CodeActionOptions (added in LSP spec 3.11.0) #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Code Action Request

https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#code-action-request

The code action request is sent from the client to the server tocompute commands
The code action request is sent from the client to the server to compute commands
for a given text document and range. These commands are typically code fixes to
either fix problems or to beautify/refactor code. The result of a
textDocument/codeAction request is an array of Command literals which are
Expand Down
33 changes: 30 additions & 3 deletions haskell-lsp-types/src/Language/Haskell/LSP/Types/DataTypesJSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Data.Aeson.Types
import Data.Text (Text)
import qualified Data.Text as T
import Language.Haskell.LSP.Types.ClientCapabilities
import Language.Haskell.LSP.Types.CodeAction
import Language.Haskell.LSP.Types.Command
import Language.Haskell.LSP.Types.Constants
import Language.Haskell.LSP.Types.Diagnostic
Expand Down Expand Up @@ -259,6 +260,30 @@ data CodeLensOptions =

deriveJSON lspOptions ''CodeLensOptions

-- ---------------------------------------------------------------------
{-
/**
* Code Action options.
*/
export interface CodeActionOptions {
/**
* CodeActionKinds that this server may return.
*
* The list of kinds may be generic, such as `CodeActionKind.Refactor`, or the server
* may list out every specific kind they provide.
*/
codeActionKinds?: CodeActionKind[];
}
-}

data CodeActionOptions =
CodeActionOptionsStatic Bool
| CodeActionOptions
{ _codeActionKinds :: Maybe [CodeActionKind]
} deriving (Read,Show,Eq)

deriveJSON (lspOptions { sumEncoding = A.UntaggedValue }) ''CodeActionOptions

-- ---------------------------------------------------------------------
{-
/**
Expand Down Expand Up @@ -463,9 +488,11 @@ interface ServerCapabilities {
*/
workspaceSymbolProvider?: boolean;
/**
* The server provides code actions.
* The server provides code actions. The `CodeActionOptions` return type is only
* valid if the client signals code action literal support via the property
* `textDocument.codeAction.codeActionLiteralSupport`.
*/
codeActionProvider?: boolean;
codeActionProvider?: boolean | CodeActionOptions;
/**
* The server provides code lens.
*/
Expand Down Expand Up @@ -662,7 +689,7 @@ data InitializeResponseCapabilitiesInner =
-- | The server provides workspace symbol support.
, _workspaceSymbolProvider :: Maybe Bool
-- | The server provides code actions.
, _codeActionProvider :: Maybe Bool
, _codeActionProvider :: Maybe CodeActionOptions
-- | The server provides code lens.
, _codeLensProvider :: Maybe CodeLensOptions
-- | The server provides document formatting.
Expand Down
5 changes: 3 additions & 2 deletions src/Language/Haskell/LSP/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ data Options =
, signatureHelpProvider :: Maybe J.SignatureHelpOptions
, typeDefinitionProvider :: Maybe J.GotoOptions
, implementationProvider :: Maybe J.GotoOptions
, codeActionProvider :: Maybe J.CodeActionOptions
, codeLensProvider :: Maybe J.CodeLensOptions
, documentOnTypeFormattingProvider :: Maybe J.DocumentOnTypeFormattingOptions
, documentLinkProvider :: Maybe J.DocumentLinkOptions
Expand All @@ -116,7 +117,7 @@ data Options =
instance Default Options where
def = Options Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing
Nothing
Nothing Nothing

-- | A function to publish diagnostics. It aggregates all diagnostics pertaining
-- to a particular version of a document, by source, and sends a
Expand Down Expand Up @@ -846,7 +847,7 @@ initializeRequestHandler' onStartup mHandler tvarCtx req@(J.RequestMessage _ ori
, J._documentHighlightProvider = supported (documentHighlightHandler h)
, J._documentSymbolProvider = supported (documentSymbolHandler h)
, J._workspaceSymbolProvider = supported (workspaceSymbolHandler h)
, J._codeActionProvider = supported (codeActionHandler h)
, J._codeActionProvider = codeActionProvider o
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line of the patch is incorrect. It should be implemented like typeDefinitionProvider.

, J._codeLensProvider = codeLensProvider o
, J._documentFormattingProvider = supported (documentFormattingHandler h)
, J._documentRangeFormattingProvider = supported (documentRangeFormattingHandler h)
Expand Down