diff --git a/haskell-lsp-types/src/Language/Haskell/LSP/Types/Capabilities.hs b/haskell-lsp-types/src/Language/Haskell/LSP/Types/Capabilities.hs index e0dc42de2..bf911d63c 100644 --- a/haskell-lsp-types/src/Language/Haskell/LSP/Types/Capabilities.hs +++ b/haskell-lsp-types/src/Language/Haskell/LSP/Types/Capabilities.hs @@ -21,6 +21,9 @@ data LSPVersion = LSPVersion Int Int -- ^ Construct a major.minor version -- | Capabilities for full conformance to the LSP specification up until a version. -- Some important milestones: -- +-- * 3.12 textDocument/prepareRename request +-- * 3.11 CodeActionOptions provided by the server +-- * 3.10 hierarchical document symbols, folding ranges -- * 3.9 completion item preselect -- * 3.8 codeAction literals -- * 3.7 related information in diagnostics @@ -99,7 +102,7 @@ capsForVersion (LSPVersion maj min) = ClientCapabilities (Just w) (Just td) Noth (Just (CodeLensClientCapabilities dynamicReg)) (Just (DocumentLinkClientCapabilities dynamicReg)) (since 3 6 (ColorProviderClientCapabilities dynamicReg)) - (Just (RenameClientCapabilities dynamicReg)) + (Just (RenameClientCapabilities dynamicReg (since 3 12 True))) (Just (PublishDiagnosticsClientCapabilities (since 3 7 True))) (since 3 10 foldingRangeCapability) sync = diff --git a/haskell-lsp-types/src/Language/Haskell/LSP/Types/ClientCapabilities.hs b/haskell-lsp-types/src/Language/Haskell/LSP/Types/ClientCapabilities.hs index 242965242..280e4f5ac 100644 --- a/haskell-lsp-types/src/Language/Haskell/LSP/Types/ClientCapabilities.hs +++ b/haskell-lsp-types/src/Language/Haskell/LSP/Types/ClientCapabilities.hs @@ -564,6 +564,13 @@ export interface TextDocumentClientCapabilities { * Whether rename supports dynamic registration. */ dynamicRegistration?: boolean; + /** + * The client supports testing for validity of rename operations + * before execution. + * + * Since 3.12.0 + */ + prepareSupport?: boolean; }; /** @@ -896,6 +903,7 @@ $(deriveJSON lspOptions ''ColorProviderClientCapabilities) data RenameClientCapabilities = RenameClientCapabilities { _dynamicRegistration :: Maybe Bool + , _prepareSupport :: Maybe Bool } deriving (Show, Read, Eq) $(deriveJSON lspOptions ''RenameClientCapabilities) diff --git a/haskell-lsp-types/src/Language/Haskell/LSP/Types/DataTypesJSON.hs b/haskell-lsp-types/src/Language/Haskell/LSP/Types/DataTypesJSON.hs index 053db722c..de3a4b5f5 100644 --- a/haskell-lsp-types/src/Language/Haskell/LSP/Types/DataTypesJSON.hs +++ b/haskell-lsp-types/src/Language/Haskell/LSP/Types/DataTypesJSON.hs @@ -307,6 +307,31 @@ data DocumentLinkOptions = deriveJSON lspOptions ''DocumentLinkOptions +-- --------------------------------------------------------------------- +{- +New in 3.12 +---------- + +/** + * Rename options + */ +export interface RenameOptions { + /** + * Renames should be checked and tested before being executed. + */ + prepareProvider?: boolean; +} +-} + +data RenameOptions = + RenameOptionsStatic Bool + | RenameOptions + { -- |Renames should be checked and tested before being executed. + _prepareProvider :: Maybe Bool + } deriving (Show, Read, Eq) + +deriveJSON lspOptions { sumEncoding = A.UntaggedValue } ''RenameOptions + -- --------------------------------------------------------------------- {- @@ -672,7 +697,7 @@ data InitializeResponseCapabilitiesInner = -- | The server provides document formatting on typing. , _documentOnTypeFormattingProvider :: Maybe DocumentOnTypeFormattingOptions -- | The server provides rename support. - , _renameProvider :: Maybe Bool + , _renameProvider :: Maybe RenameOptions -- | The server provides document link support. , _documentLinkProvider :: Maybe DocumentLinkOptions -- | The server provides color provider support. Since LSP 3.6 @@ -2586,6 +2611,51 @@ deriveJSON lspOptions ''RenameParams type RenameRequest = RequestMessage ClientMethod RenameParams WorkspaceEdit type RenameResponse = ResponseMessage WorkspaceEdit +-- --------------------------------------------------------------------- +{- +Prepare Rename Request + +Since version 3.12.0 + +The prepare rename request is sent from the client to the server to setup +and test the validity of a rename operation at a given location. + +Request: + + method: ‘textDocument/prepareRename’ + params: TextDocumentPositionParams + +Response: + + result: Range | { range: Range, placeholder: string } | null describing + the range of the string to rename and optionally a placeholder + text of the string content to be renamed. If null is returned + then it is deemed that a ‘textDocument/rename’ request is not + valid at the given position. + error: code and message set in case an exception happens during the + prepare rename request. + +-} + +-- {\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"textDocument/rename\",\"params\":{\"textDocument\":{\"uri\":\"file:///home/alanz/mysrc/github/alanz/haskell-lsp/src/HieVscode.hs\"},\"position\":{\"line\":37,\"character\":17},\"newName\":\"getArgs'\"}} + +data RangeWithPlaceholder = + RangeWithPlaceholder + { + _range :: Range + , _placeholder :: Text + } + +deriveJSON lspOptions { sumEncoding = A.UntaggedValue } ''RangeWithPlaceholder + +data RangeOrRangeWithPlaceholder = RangeWithPlaceholderValue RangeWithPlaceholder + | RangeValue Range + +deriveJSON lspOptions { sumEncoding = A.UntaggedValue } ''RangeOrRangeWithPlaceholder + +type PrepareRenameRequest = RequestMessage ClientMethod TextDocumentPositionParams Range +type PrepareRenameResponse = ResponseMessage (Maybe RangeOrRangeWithPlaceholder) + -- --------------------------------------------------------------------- {- New in 3.0 diff --git a/haskell-lsp-types/src/Language/Haskell/LSP/Types/Message.hs b/haskell-lsp-types/src/Language/Haskell/LSP/Types/Message.hs index 44a7e6a2e..c11ff6424 100644 --- a/haskell-lsp-types/src/Language/Haskell/LSP/Types/Message.hs +++ b/haskell-lsp-types/src/Language/Haskell/LSP/Types/Message.hs @@ -112,6 +112,7 @@ data ClientMethod = | TextDocumentRangeFormatting | TextDocumentOnTypeFormatting | TextDocumentRename + | TextDocumentPrepareRename | TextDocumentFoldingRange -- A custom message type. It is not enforced that this starts with $/. | CustomClientMethod Text @@ -158,6 +159,7 @@ instance A.FromJSON ClientMethod where parseJSON (A.String "textDocument/rangeFormatting") = return TextDocumentRangeFormatting parseJSON (A.String "textDocument/onTypeFormatting") = return TextDocumentOnTypeFormatting parseJSON (A.String "textDocument/rename") = return TextDocumentRename + parseJSON (A.String "textDocument/prepareRename") = return TextDocumentPrepareRename parseJSON (A.String "textDocument/foldingRange") = return TextDocumentFoldingRange parseJSON (A.String "window/progress/cancel") = return WindowProgressCancel parseJSON (A.String x) = return (CustomClientMethod x) @@ -202,6 +204,7 @@ instance A.ToJSON ClientMethod where toJSON TextDocumentRangeFormatting = A.String "textDocument/rangeFormatting" toJSON TextDocumentOnTypeFormatting = A.String "textDocument/onTypeFormatting" toJSON TextDocumentRename = A.String "textDocument/rename" + toJSON TextDocumentPrepareRename = A.String "textDocument/prepareRename" toJSON TextDocumentFoldingRange = A.String "textDocument/foldingRange" toJSON TextDocumentDocumentLink = A.String "textDocument/documentLink" toJSON DocumentLinkResolve = A.String "documentLink/resolve" diff --git a/haskell-lsp-types/src/Language/Haskell/LSP/Types/MessageFuncs.hs b/haskell-lsp-types/src/Language/Haskell/LSP/Types/MessageFuncs.hs index 9b0a2005b..cffa96b42 100644 --- a/haskell-lsp-types/src/Language/Haskell/LSP/Types/MessageFuncs.hs +++ b/haskell-lsp-types/src/Language/Haskell/LSP/Types/MessageFuncs.hs @@ -329,3 +329,7 @@ fmClientRenameRequest :: J.LspId -> J.RenameParams -> J.RenameRequest fmClientRenameRequest rid params = J.RequestMessage "2.0" rid J.TextDocumentRename params +-- * :leftwards_arrow_with_hook: [textDocument/prepareRename](#textDocument_prepareRename) +fmClientPrepareRenameRequest :: J.LspId -> J.TextDocumentPositionParams -> J.PrepareRenameRequest +fmClientPrepareRenameRequest rid params + = J.RequestMessage "2.0" rid J.TextDocumentPrepareRename params diff --git a/src/Language/Haskell/LSP/Core.hs b/src/Language/Haskell/LSP/Core.hs index 9a6b6b335..33fe74fe9 100644 --- a/src/Language/Haskell/LSP/Core.hs +++ b/src/Language/Haskell/LSP/Core.hs @@ -107,6 +107,7 @@ data Options = , implementationProvider :: Maybe J.GotoOptions , codeLensProvider :: Maybe J.CodeLensOptions , documentOnTypeFormattingProvider :: Maybe J.DocumentOnTypeFormattingOptions + , renameProvider :: Maybe J.RenameOptions , documentLinkProvider :: Maybe J.DocumentLinkOptions , colorProvider :: Maybe J.ColorOptions , foldingRangeProvider :: Maybe J.FoldingRangeOptions @@ -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 @@ -851,7 +852,7 @@ initializeRequestHandler' onStartup mHandler tvarCtx req@(J.RequestMessage _ ori , J._documentFormattingProvider = supported (documentFormattingHandler h) , J._documentRangeFormattingProvider = supported (documentRangeFormattingHandler h) , J._documentOnTypeFormattingProvider = documentOnTypeFormattingProvider o - , J._renameProvider = supported (renameHandler h) + , J._renameProvider = renameProvider o , J._documentLinkProvider = documentLinkProvider o , J._colorProvider = colorProvider o , J._foldingRangeProvider = foldingRangeProvider o diff --git a/test/MethodSpec.hs b/test/MethodSpec.hs index 964281702..284869f50 100644 --- a/test/MethodSpec.hs +++ b/test/MethodSpec.hs @@ -55,6 +55,7 @@ clientMethods = [ ,"textDocument/documentLink" ,"documentLink/resolve" ,"textDocument/rename" + ,"textDocument/prepareRename" ] serverMethods :: [T.Text]