Skip to content

Commit e863912

Browse files
authored
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).
1 parent a698a6f commit e863912

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

Diff for: src/Development/IDE/Types/Location.hs

+2-19
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import Data.Maybe as Maybe
3030
import Data.Hashable
3131
import Data.String
3232
import System.FilePath
33-
import System.Info.Extra
3433
import qualified Language.Haskell.LSP.Types as LSP
3534
import Language.Haskell.LSP.Types as LSP (
3635
filePathToUri
@@ -49,25 +48,9 @@ instance IsString NormalizedFilePath where
4948
fromString = toNormalizedFilePath
5049

5150
toNormalizedFilePath :: FilePath -> NormalizedFilePath
51+
-- We want to keep empty paths instead of normalising them to "."
5252
toNormalizedFilePath "" = NormalizedFilePath ""
53-
toNormalizedFilePath fp = NormalizedFilePath $ normalise' fp
54-
where
55-
-- We do not use System.FilePath’s normalise here since that
56-
-- also normalises things like the case of the drive letter
57-
-- which NormalizedUri does not normalise so we get VFS lookup failures.
58-
normalise' :: FilePath -> FilePath
59-
normalise' = oneSlash . map (\c -> if isPathSeparator c then pathSeparator else c)
60-
61-
-- Allow double slashes as the very first element of the path for UNC drives on Windows
62-
-- otherwise turn adjacent slashes into one. These slashes often arise from dodgy CPP
63-
oneSlash :: FilePath -> FilePath
64-
oneSlash (x:xs) | isWindows = x : f xs
65-
oneSlash xs = f xs
66-
67-
f (x:y:xs) | isPathSeparator x, isPathSeparator y = f (x:xs)
68-
f (x:xs) = x : f xs
69-
f [] = []
70-
53+
toNormalizedFilePath fp = NormalizedFilePath $ normalise fp
7154

7255
fromNormalizedFilePath :: NormalizedFilePath -> FilePath
7356
fromNormalizedFilePath (NormalizedFilePath fp) = fp

0 commit comments

Comments
 (0)