Fix `swapUri` in Files.hs
[lsp-test.git] / src / Language / LSP / Test / Files.hs
index 8fc78cf608149fa71edce726e7e4d18deae8db73..231f3e6598aa2817e4767fb9c9f938d71307c924 100644 (file)
@@ -11,7 +11,7 @@ module Language.LSP.Test.Files
 where
 
 import           Language.LSP.Types
-import           Language.LSP.Types.Lens
+import           Language.LSP.Types.Lens hiding (id)
 import           Control.Lens
 import qualified Data.HashMap.Strict           as HM
 import qualified Data.Text                     as T
@@ -75,7 +75,14 @@ mapUris f event =
 
     swapWorkspaceEdit :: WorkspaceEdit -> WorkspaceEdit
     swapWorkspaceEdit e =
-      let newDocChanges = fmap (fmap (swapUri textDocument)) $ e ^. documentChanges
+      let swapDocumentChangeUri :: DocumentChange -> DocumentChange
+          swapDocumentChangeUri (InL textDocEdit) = InL $ swapUri textDocument textDocEdit
+          swapDocumentChangeUri (InR (InL createFile)) = InR $ InL $ swapUri id createFile
+          -- for RenameFile, we swap `newUri`
+          swapDocumentChangeUri (InR (InR (InL renameFile))) = InR $ InR $ InL $ newUri .~ f (renameFile ^. newUri) $ renameFile
+          swapDocumentChangeUri (InR (InR (InR deleteFile))) = InR $ InR $ InR $ swapUri id deleteFile
+
+          newDocChanges = fmap (fmap swapDocumentChangeUri) $ e ^. documentChanges
           newChanges = fmap (swapKeys f) $ e ^. changes
        in WorkspaceEdit newChanges newDocChanges