on master help sign in
Fix check for empty file path (#304)
64693edMoritz Kiefer
src/Development/IDE/Types/Location.hs+4−1
@@ -66,9 +66,12 @@ fromNormalizedFilePath (NormalizedFilePath fp) = fp
66-- So we have our own wrapper here that supports empty filepaths.
66-- So we have our own wrapper here that supports empty filepaths.
67uriToFilePath' :: Uri -> Maybe FilePath
67uriToFilePath' :: Uri -> Maybe FilePath
68uriToFilePath' uri
68uriToFilePath' uri
69− | uri == filePathToUri "" = Just ""
69+ | uri == fromNormalizedUri emptyPathUri = Just ""
70 | otherwise = LSP.uriToFilePath uri
70 | otherwise = LSP.uriToFilePath uri
71
71
72+emptyPathUri :: NormalizedUri
73+emptyPathUri = filePathToUri' ""
74+
72filePathToUri' :: NormalizedFilePath -> NormalizedUri
75filePathToUri' :: NormalizedFilePath -> NormalizedUri
73filePathToUri' (NormalizedFilePath fp) = toNormalizedUri $ Uri $ T.pack $ LSP.fileScheme <> "//" <> platformAdjustToUriPath fp
76filePathToUri' (NormalizedFilePath fp) = toNormalizedUri $ Uri $ T.pack $ LSP.fileScheme <> "//" <> platformAdjustToUriPath fp
74 where
77 where
test/exe/Main.hs+9
@@ -18,6 +18,7 @@ import Development.IDE.GHC.Util
18import qualified Data.Text as T
18import qualified Data.Text as T
19import Development.IDE.Test
19import Development.IDE.Test
20import Development.IDE.Test.Runfiles
20import Development.IDE.Test.Runfiles
21+import Development.IDE.Types.Location
21import Language.Haskell.LSP.Test
22import Language.Haskell.LSP.Test
22import Language.Haskell.LSP.Types
23import Language.Haskell.LSP.Types
23import Language.Haskell.LSP.Types.Capabilities
24import Language.Haskell.LSP.Types.Capabilities
@@ -48,6 +49,7 @@ main = defaultMain $ testGroup "HIE"
48 , pluginTests
49 , pluginTests
49 , preprocessorTests
50 , preprocessorTests
50 , thTests
51 , thTests
52+ , unitTests
51 ]
53 ]
52
54
53initializeResponseTests :: TestTree
55initializeResponseTests :: TestTree
@@ -1306,3 +1308,10 @@ openTestDataDoc :: FilePath -> Session TextDocumentIdentifier
1306openTestDataDoc path = do
1308openTestDataDoc path = do
1307 source <- liftIO $ readFileUtf8 $ "test/data" </> path
1309 source <- liftIO $ readFileUtf8 $ "test/data" </> path
1308 openDoc' path "haskell" source
1310 openDoc' path "haskell" source
1311+
1312+unitTests :: TestTree
1313+unitTests = do
1314+ testGroup "Unit"
1315+ [ testCase "empty file path" $
1316+ uriToFilePath' (fromNormalizedUri $ filePathToUri' "") @?= Just ""
1317+ ]