@@ -14,10 +14,12 @@ module Development.IDE.GHC.Util(
1414 fakeDynFlags,
1515 prettyPrint,
1616 runGhcEnv,
17− textToStringBuffer
17+ textToStringBuffer,
18+ moduleImportPaths
1819 ) where
1920
2021import Config
22+import Data.List.Extra
2123import Fingerprint
2224import GHC
2325import GhcMonad
@@ -28,6 +30,7 @@ import FileCleanup
2830import Platform
2931import qualified Data.Text as T
3032import StringBuffer
33+import System.FilePath
3134
3235
3336----------------------------------------------------------------------
@@ -90,3 +93,15 @@ fakeDynFlags = defaultDynFlags settings ([], [])
9093 { pc_DYNAMIC_BY_DEFAULT=False
9194 , pc_WORD_SIZE=8
9295 }
96+
97+moduleImportPaths :: GHC.ParsedModule -> Maybe FilePath
98+moduleImportPaths pm
99+ | rootModDir == "." = Just rootPathDir
100+ | otherwise =
101+ dropTrailingPathSeparator <$> stripSuffix (normalise rootModDir) (normalise rootPathDir)
102+ where
103+ ms = GHC.pm_mod_summary pm
104+ file = GHC.ms_hspp_file ms
105+ mod' = GHC.ms_mod ms
106+ rootPathDir = takeDirectory file
107+ rootModDir = takeDirectory . moduleNameSlashes . GHC.moduleName $ mod'