-emptyFileMap :: FileMap
-emptyFileMap = Map.empty
-
-buildFileMap :: Set.Set Uri -> FilePath -> FilePath -> FileMap -> IO FileMap
-buildFileMap uris oldBaseDir newBaseDir oldMap = foldM transform oldMap uris
- where
- transform map uri = do
- let fp = fromMaybe (error "Couldn't convert file path") $ uriToFilePath uri
- rel = makeRelative oldBaseDir fp
- newFp = newBaseDir </> rel
- newUri <- filePathToUri <$> canonicalizePath newFp
- return $ Map.insert uri newUri map
-
-swapFiles :: FileMap -> FilePath -> FilePath -> [B.ByteString] -> IO ([B.ByteString], FileMap)
-swapFiles fileMap recBaseDir curBaseDir msgs = do
-
- let oldUris = Set.unions $ map extractUris msgs
-
- newMap <- buildFileMap oldUris recBaseDir curBaseDir fileMap
-
- let newMsgs = map (swapUris newMap) msgs
-
- case decode (head newMsgs) :: Maybe InitializeRequest of
- -- If there is an initialize request we will need to swap
- -- the rootUri and rootPath
- Just req -> do
- cd <- getCurrentDirectory
- let newRoot = cd </> curBaseDir
- newRootUri = params . rootUri ?~ filePathToUri newRoot $ req
- newRootPath = params . rootPath ?~ T.pack newRoot $ newRootUri
- newReq = encode newRootPath
- return (newReq:tail newMsgs, newMap)
-
- Nothing -> return (newMsgs, newMap)