- mapValue :: (Uri -> Uri) -> Value -> Value
- mapValue f x = case parse parseJSON x :: Result VersionedTextDocumentIdentifier of
- Success doc -> transform doc
- Error _ -> case parse parseJSON x :: Result TextDocumentIdentifier of
- Success doc -> transform doc
- Error _ -> case parse parseJSON x :: Result InitializeParams of
- Success params -> transformInit params
- Error _ -> case parse parseJSON x :: Result Object of
- Success obj -> Object $ HashMap.map (mapValue f) obj
- Error _ -> x
+ 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 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
+ fromServerMsg x = x