Skip to content

Commit 9b6e712

Browse files
authored
Fix emptyPathUri (#502)
* Fix emptyPathUri * Remove platform dependency
1 parent 9951f35 commit 9b6e712

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

ghcide.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

5556
emptyPathUri :: LSP.NormalizedUri
56-
emptyPathUri = LSP.NormalizedUri (hash ("" :: String)) ""
57+
emptyPathUri =
58+
let s = "file://"
59+
in LSP.NormalizedUri (hash s) s
5760

5861
filePathToUri' :: LSP.NormalizedFilePath -> LSP.NormalizedUri
5962
filePathToUri' = LSP.normalizedFilePathToUri

test/exe/Main.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Language.Haskell.LSP.Messages
3131
import Language.Haskell.LSP.Types
3232
import Language.Haskell.LSP.Types.Capabilities
3333
import Language.Haskell.LSP.VFS (applyChange)
34+
import Network.URI
3435
import System.Environment.Blank (setEnv)
3536
import System.FilePath
3637
import 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

0 commit comments

Comments
 (0)