Skip to content

Commit fde147a

Browse files
committed
Create .hls directory in lookupMod
1 parent 64589d1 commit fde147a

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

ghcide/src/Development/IDE/Core/Actions.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import qualified HieDb
3535
import Language.LSP.Protocol.Types (DocumentHighlight (..),
3636
SymbolInformation (..))
3737
import Language.LSP.Server (resRootPath)
38-
import System.Directory (doesFileExist)
39-
import System.FilePath ((</>))
38+
import System.Directory (createDirectoryIfMissing, doesFileExist)
39+
import System.FilePath ((</>), takeDirectory)
4040

4141

4242
-- | Generates URIs for files in dependencies, but not in the
@@ -48,13 +48,13 @@ lookupMod
4848
-> Unit
4949
-> Bool -- ^ Is this file a boot file?
5050
-> MaybeT IdeAction Uri
51-
lookupMod _dbchan hieFile moduleName _uid _boot = MaybeT $ do
51+
lookupMod _dbchan hieFile moduleName uid _boot = MaybeT $ do
5252
mProjectRoot <- (resRootPath =<<) <$> asks lspEnv
5353
case mProjectRoot of
5454
Nothing -> pure Nothing
5555
Just projectRoot -> do
5656
let toFilePath :: ModuleName -> FilePath
57-
toFilePath = separateDirectories . show
57+
toFilePath = separateDirectories . prettyModuleName
5858
where
5959
separateDirectories :: FilePath -> FilePath
6060
separateDirectories moduleNameString =
@@ -66,8 +66,14 @@ lookupMod _dbchan hieFile moduleName _uid _boot = MaybeT $ do
6666
replaceDotWithSpace :: Char -> Char
6767
replaceDotWithSpace '.' = ' '
6868
replaceDotWithSpace c = c
69+
prettyModuleName :: ModuleName -> String
70+
prettyModuleName = filter (/= '"')
71+
. concat
72+
. drop 1
73+
. words
74+
. show
6975
writeOutDir :: FilePath
70-
writeOutDir = projectRoot </> ".hls" </> "dependencies"
76+
writeOutDir = projectRoot </> ".hls" </> "dependencies" </> show uid
7177
writeOutFile :: FilePath
7278
writeOutFile = toFilePath moduleName ++ ".hs"
7379
writeOutPath :: FilePath
@@ -80,6 +86,7 @@ lookupMod _dbchan hieFile moduleName _uid _boot = MaybeT $ do
8086
else do
8187
nc <- asks ideNc
8288
liftIO $ do
89+
createDirectoryIfMissing True $ takeDirectory writeOutPath
8390
moduleSource <- hie_hs_src <$> loadHieFile (mkUpdater nc) hieFile
8491
BS.writeFile writeOutPath moduleSource
8592
pure $ Just moduleUri

0 commit comments

Comments
 (0)