Skip to content

Commit

Permalink
Normalise filepaths to match haskell-lsp 0.19 (#266)
Browse files Browse the repository at this point in the history
haskell-lsp 0.19 has started to normalise file paths completely so we
need to make sure that NormalizedFilePath agrees with that, otherwise,
we get a bunch of test failures on the daml repo (they are not
specific to DAML, but atm ghcide CI does not run windows).
  • Loading branch information
cocreature committed Dec 17, 2019
1 parent a698a6f commit e863912
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/Development/IDE/Types/Location.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import Data.Maybe as Maybe
import Data.Hashable
import Data.String
import System.FilePath
import System.Info.Extra
import qualified Language.Haskell.LSP.Types as LSP
import Language.Haskell.LSP.Types as LSP (
filePathToUri
Expand All @@ -49,25 +48,9 @@ instance IsString NormalizedFilePath where
fromString = toNormalizedFilePath

toNormalizedFilePath :: FilePath -> NormalizedFilePath
-- We want to keep empty paths instead of normalising them to "."
toNormalizedFilePath "" = NormalizedFilePath ""
toNormalizedFilePath fp = NormalizedFilePath $ normalise' fp
where
-- We do not use System.FilePath’s normalise here since that
-- also normalises things like the case of the drive letter
-- which NormalizedUri does not normalise so we get VFS lookup failures.
normalise' :: FilePath -> FilePath
normalise' = oneSlash . map (\c -> if isPathSeparator c then pathSeparator else c)

-- Allow double slashes as the very first element of the path for UNC drives on Windows
-- otherwise turn adjacent slashes into one. These slashes often arise from dodgy CPP
oneSlash :: FilePath -> FilePath
oneSlash (x:xs) | isWindows = x : f xs
oneSlash xs = f xs

f (x:y:xs) | isPathSeparator x, isPathSeparator y = f (x:xs)
f (x:xs) = x : f xs
f [] = []

toNormalizedFilePath fp = NormalizedFilePath $ normalise fp

fromNormalizedFilePath :: NormalizedFilePath -> FilePath
fromNormalizedFilePath (NormalizedFilePath fp) = fp
Expand Down

0 comments on commit e863912

Please sign in to comment.