+ 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)
+
+rootDir :: [B.ByteString] -> FilePath
+rootDir msgs = case decode (head msgs) :: Maybe InitializeRequest of
+ Just req -> fromMaybe (error "Couldn't convert root dir") $ do
+ rootUri <- req ^. params . rootUri
+ uriToFilePath rootUri
+ Nothing -> error "Couldn't find root dir"