Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Commit

Permalink
Fix check for empty file path
Browse files Browse the repository at this point in the history
I accidentally broke this on Windows in #303 by letting the two
conversirons get out of sync.
  • Loading branch information
cocreature committed Jan 3, 2020
1 parent 7e80629 commit c0e145e
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 c0e145e

Please sign in to comment.