mirror of
https://github.com/haskell/ghcide.git
synced 2024-12-04 15:52:08 +03:00
Normalise filepaths to match haskell-lsp 0.19 (#266)
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).
This commit is contained in:
parent
a698a6f1d0
commit
e863912449
@ -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
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user