on master help sign in
Fix emptyPathUri (#502)

* Fix emptyPathUri * Remove platform dependency

commit9b6e7122516f9de9b0ba20cd37d59c58a4d634ec authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateMon 23 Mar 2020, 12:21 (7 years ago) parent9951f35
3 files changed+13−1
ghcide.cabal+1 src/Development/IDE/Types/Location.hs+4−1 test/exe/Main.hs+8
ghcide.cabal+1
@@ -245,6 +245,7 @@ test-suite ghcide-tests
245245 haddock-library,
246246 haskell-lsp,
247247 haskell-lsp-types,
248+ network-uri,
248249 lens,
249250 lsp-test >= 0.8,
250251 parser-combinators,
src/Development/IDE/Types/Location.hs+4−1
@@ -17,6 +17,7 @@ module Development.IDE.Types.Location
1717 , LSP.NormalizedFilePath
1818 , fromUri
1919 , emptyFilePath
20+ , emptyPathUri
2021 , toNormalizedFilePath'
2122 , LSP.fromNormalizedFilePath
2223 , filePathToUri'
@@ -53,7 +54,9 @@ uriToFilePath' uri
5354 | otherwise = LSP.uriToFilePath uri
5455
5556emptyPathUri :: LSP.NormalizedUri
56−emptyPathUri = LSP.NormalizedUri (hash ("" :: String)) ""
57+emptyPathUri =
58+ let s = "file://"
59+ in LSP.NormalizedUri (hash s) s
5760
5861filePathToUri' :: LSP.NormalizedFilePath -> LSP.NormalizedUri
5962filePathToUri' = LSP.normalizedFilePathToUri
test/exe/Main.hs+8
@@ -31,6 +31,7 @@ import Language.Haskell.LSP.Messages
3131import Language.Haskell.LSP.Types
3232import Language.Haskell.LSP.Types.Capabilities
3333import Language.Haskell.LSP.VFS (applyChange)
34+import Network.URI
3435import System.Environment.Blank (setEnv)
3536import System.FilePath
3637import System.IO.Extra
@@ -2110,6 +2111,13 @@ unitTests = do
21102111 uriToFilePath' (fromNormalizedUri $ filePathToUri' "") @?= Just "."
21112112 , testCase "empty file path works using toNormalizedFilePath'" $
21122113 uriToFilePath' (fromNormalizedUri $ filePathToUri' (toNormalizedFilePath' "")) @?= Just ""
2114+ , testCase "empty path URI" $ do
2115+ Just URI{..} <- pure $ parseURI (T.unpack $ getUri $ fromNormalizedUri emptyPathUri)
2116+ uriScheme @?= "file:"
2117+ uriPath @?= ""
2118+ , testCase "from empty path URI" $ do
2119+ let uri = Uri "file://"
2120+ uriToFilePath' uri @?= Just ""
21132121 ]
21142122
21152123-- | Wrapper around 'LSPTest.openDoc'' that sends file creation events