@@ -35,8 +35,8 @@ import qualified HieDb
35
35
import Language.LSP.Protocol.Types (DocumentHighlight (.. ),
36
36
SymbolInformation (.. ))
37
37
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 )
40
40
41
41
42
42
-- | Generates URIs for files in dependencies, but not in the
@@ -48,13 +48,13 @@ lookupMod
48
48
-> Unit
49
49
-> Bool -- ^ Is this file a boot file?
50
50
-> MaybeT IdeAction Uri
51
- lookupMod _dbchan hieFile moduleName _uid _boot = MaybeT $ do
51
+ lookupMod _dbchan hieFile moduleName uid _boot = MaybeT $ do
52
52
mProjectRoot <- (resRootPath =<< ) <$> asks lspEnv
53
53
case mProjectRoot of
54
54
Nothing -> pure Nothing
55
55
Just projectRoot -> do
56
56
let toFilePath :: ModuleName -> FilePath
57
- toFilePath = separateDirectories . show
57
+ toFilePath = separateDirectories . prettyModuleName
58
58
where
59
59
separateDirectories :: FilePath -> FilePath
60
60
separateDirectories moduleNameString =
@@ -66,8 +66,14 @@ lookupMod _dbchan hieFile moduleName _uid _boot = MaybeT $ do
66
66
replaceDotWithSpace :: Char -> Char
67
67
replaceDotWithSpace ' .' = ' '
68
68
replaceDotWithSpace c = c
69
+ prettyModuleName :: ModuleName -> String
70
+ prettyModuleName = filter (/= ' "' )
71
+ . concat
72
+ . drop 1
73
+ . words
74
+ . show
69
75
writeOutDir :: FilePath
70
- writeOutDir = projectRoot </> " .hls" </> " dependencies"
76
+ writeOutDir = projectRoot </> " .hls" </> " dependencies" </> show uid
71
77
writeOutFile :: FilePath
72
78
writeOutFile = toFilePath moduleName ++ " .hs"
73
79
writeOutPath :: FilePath
@@ -80,6 +86,7 @@ lookupMod _dbchan hieFile moduleName _uid _boot = MaybeT $ do
80
86
else do
81
87
nc <- asks ideNc
82
88
liftIO $ do
89
+ createDirectoryIfMissing True $ takeDirectory writeOutPath
83
90
moduleSource <- hie_hs_src <$> loadHieFile (mkUpdater nc) hieFile
84
91
BS. writeFile writeOutPath moduleSource
85
92
pure $ Just moduleUri
0 commit comments