Skip to content

Commit

Permalink
Fix check for empty file path (haskell#304)
Browse files Browse the repository at this point in the history
I accidentally broke this on Windows in haskell#303 by letting the two
conversirons get out of sync.
  • Loading branch information
cocreature authored and pepeiborra committed Feb 1, 2020
1 parent 2b37a02 commit 8bce668
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Development/IDE/Types/Location.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ fromNormalizedFilePath (NormalizedFilePath fp) = fp
-- So we have our own wrapper here that supports empty filepaths.
uriToFilePath' :: Uri -> Maybe FilePath
uriToFilePath' uri
| uri == filePathToUri "" = Just ""
| uri == fromNormalizedUri emptyPathUri = Just ""
| otherwise = LSP.uriToFilePath uri

emptyPathUri :: NormalizedUri
emptyPathUri = filePathToUri' ""

filePathToUri' :: NormalizedFilePath -> NormalizedUri
filePathToUri' (NormalizedFilePath fp) = toNormalizedUri $ Uri $ T.pack $ LSP.fileScheme <> "//" <> platformAdjustToUriPath fp
where
Expand Down
9 changes: 9 additions & 0 deletions test/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Development.IDE.GHC.Util
import qualified Data.Text as T
import Development.IDE.Test
import Development.IDE.Test.Runfiles
import Development.IDE.Types.Location
import Language.Haskell.LSP.Test
import Language.Haskell.LSP.Types
import Language.Haskell.LSP.Types.Capabilities
Expand Down Expand Up @@ -48,6 +49,7 @@ main = defaultMain $ testGroup "HIE"
, pluginTests
, preprocessorTests
, thTests
, unitTests
]

initializeResponseTests :: TestTree
Expand Down Expand Up @@ -1306,3 +1308,10 @@ openTestDataDoc :: FilePath -> Session TextDocumentIdentifier
openTestDataDoc path = do
source <- liftIO $ readFileUtf8 $ "test/data" </> path
openDoc' path "haskell" source

unitTests :: TestTree
unitTests = do
testGroup "Unit"
[ testCase "empty file path" $
uriToFilePath' (fromNormalizedUri $ filePathToUri' "") @?= Just ""
]

0 comments on commit 8bce668

Please sign in to comment.