@@ -17,7 +17,7 @@ module Development.IDE.GHC.Util(
1717 prettyPrint,
1818 runGhcEnv,
1919 textToStringBuffer,
20− moduleImportPaths,
20+ moduleImportPath,
2121 HscEnvEq, hscEnv, newHscEnvEq
2222 ) where
2323
@@ -103,16 +103,25 @@ fakeDynFlags = defaultDynFlags settings mempty
103103 , pc_WORD_SIZE=8
104104 }
105105
106−moduleImportPaths :: GHC.ParsedModule -> Maybe FilePath
107−moduleImportPaths pm
108− | rootModDir == "." = Just rootPathDir
109− | otherwise =
110− dropTrailingPathSeparator <$> stripSuffix (normalise rootModDir) (normalise rootPathDir)
106+moduleImportPath :: GHC.ParsedModule -> Maybe FilePath
107+moduleImportPath pm
108+ | rootModDir == "." = Just rootPathDir
109+ | otherwise = do
110+ dir <- dropTrailingPathSeparator <$> stripSuffix (normalise rootModDir) (normalise rootPathDir)
111+ -- For modules with more than one component, this can be empty, e.g.,
112+ -- stripSuffix (normalise ./A) (normalise ./A) for A/B.daml.
113+ -- We make a best effort attemp at not duplicating file paths
114+ -- by mapping the current directory to '.' if 'rootPathDir' starts with '.' and
115+ -- to an empty string otherwise.
116+ pure $! if null dir then dotDir else dir
111117 where
118+ dotDir = if "." `isPrefixOf` rootPathDir then "." else ""
112119 ms = GHC.pm_mod_summary pm
113120 file = GHC.ms_hspp_file ms
114121 mod' = GHC.ms_mod ms
122+ -- ./src/A for file ./src/A/B.daml
115123 rootPathDir = takeDirectory file
124+ -- A for module A.B
116125 rootModDir = takeDirectory . moduleNameSlashes . GHC.moduleName $ mod'
117126
118127-- | An HscEnv with equality.