X-Git-Url: https://git.lukelau.me/?a=blobdiff_plain;f=src%2FLanguage%2FHaskell%2FLSP%2FTest%2FFiles.hs;h=b56f536a660bb9dd5812b019a381cf6ec5714e3b;hb=ddf9bc17ce8a548a927c201c6b0edb8cf1c9fcad;hp=48390940a990419aa7024fe0f65f778200b3ba47;hpb=4de144bafd28f3f2a8067a896bedb1430f68f745;p=lsp-test.git diff --git a/src/Language/Haskell/LSP/Test/Files.hs b/src/Language/Haskell/LSP/Test/Files.hs index 4839094..b56f536 100644 --- a/src/Language/Haskell/LSP/Test/Files.hs +++ b/src/Language/Haskell/LSP/Test/Files.hs @@ -8,7 +8,8 @@ module Language.Haskell.LSP.Test.Files where import Language.Haskell.LSP.Capture -import Language.Haskell.LSP.Types hiding ( error ) +import Language.Haskell.LSP.Types +import Language.Haskell.LSP.Types.Lens import Language.Haskell.LSP.Messages import Control.Lens import qualified Data.HashMap.Strict as HM @@ -44,24 +45,38 @@ mapUris f event = FromServer t msg -> FromServer t (fromServerMsg msg) where - --TODO: Handle all other URLs that might need swapped + --TODO: Handle all other URIs that might need swapped fromClientMsg (NotDidOpenTextDocument n) = NotDidOpenTextDocument $ swapUri (params . textDocument) n fromClientMsg (NotDidChangeTextDocument n) = NotDidChangeTextDocument $ swapUri (params . textDocument) n fromClientMsg (NotWillSaveTextDocument n) = NotWillSaveTextDocument $ swapUri (params . textDocument) n fromClientMsg (NotDidSaveTextDocument n) = NotDidSaveTextDocument $ swapUri (params . textDocument) n fromClientMsg (NotDidCloseTextDocument n) = NotDidCloseTextDocument $ swapUri (params . textDocument) n - fromClientMsg (ReqInitialize r) = ReqInitialize $ params .~ (transformInit (r ^. params)) $ r + fromClientMsg (ReqInitialize r) = ReqInitialize $ params .~ transformInit (r ^. params) $ r + fromClientMsg (ReqDocumentSymbols r) = ReqDocumentSymbols $ swapUri (params . textDocument) r + fromClientMsg (ReqRename r) = ReqRename $ swapUri (params . textDocument) r fromClientMsg x = x fromServerMsg :: FromServerMessage -> FromServerMessage fromServerMsg (ReqApplyWorkspaceEdit r) = - let newDocChanges = fmap (fmap (swapUri textDocument)) $ r ^. params . edit . documentChanges - r1 = (params . edit . documentChanges) .~ newDocChanges $ r - newChanges = fmap (swapKeys f) $ r1 ^. params . edit . changes - r2 = (params . edit . changes) .~ newChanges $ r1 - in ReqApplyWorkspaceEdit r2 + ReqApplyWorkspaceEdit $ params . edit .~ swapWorkspaceEdit (r ^. params . edit) $ r + + fromServerMsg (NotPublishDiagnostics n) = NotPublishDiagnostics $ swapUri params n + + fromServerMsg (RspDocumentSymbols r) = + let swapUri' (DSSymbolInformation si) = DSSymbolInformation (swapUri location <$> si) + swapUri' (DSDocumentSymbols dss) = DSDocumentSymbols dss -- no file locations here + in RspDocumentSymbols $ r & result %~ (fmap swapUri') + + fromServerMsg (RspRename r) = RspRename $ r & result %~ (fmap swapWorkspaceEdit) + fromServerMsg x = x + swapWorkspaceEdit :: WorkspaceEdit -> WorkspaceEdit + swapWorkspaceEdit e = + let newDocChanges = fmap (fmap (swapUri textDocument)) $ e ^. documentChanges + newChanges = fmap (swapKeys f) $ e ^. changes + in WorkspaceEdit newChanges newDocChanges + swapKeys :: (Uri -> Uri) -> HM.HashMap Uri b -> HM.HashMap Uri b swapKeys f = HM.foldlWithKey' (\acc k v -> HM.insert (f k) v acc) HM.empty