Fix `swapUri` in Files.hs
authorTing-Gian LUA <banacorn@gmail.com>
Fri, 11 Dec 2020 10:10:31 +0000 (18:10 +0800)
committerTing-Gian LUA <banacorn@gmail.com>
Fri, 11 Dec 2020 10:10:31 +0000 (18:10 +0800)
cabal.project
src/Language/LSP/Test/Files.hs

index 140bc9564115927623eeef3446f56ab14f124348..add6b6567510e9aaea8b66757848be689e938fa8 100644 (file)
@@ -3,3 +3,14 @@ packages: .
 flags: +DummyServer
 test-show-details: direct
 haddock-quickjump: True
+
+source-repository-package
+    type: git
+    location: https://github.com/banacorn/lsp.git
+    tag: 0556d22fc66f24bb526f671666183a86b485837e
+    subdir: lsp-types
+
+source-repository-package
+    type: git
+    location: https://github.com/banacorn/lsp.git
+    tag: 0556d22fc66f24bb526f671666183a86b485837e
\ No newline at end of file
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