Skip to content

Commit 868ebed

Browse files
committed
Replace GHC.Paths.libdir by querying a ModSummary for the LibDir
1 parent 5b0e7e9 commit 868ebed

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

plugins/hls-retrie-plugin/hls-retrie-plugin.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ library
2525
, extra
2626
, ghc
2727
, ghcide ^>=1.7
28-
, ghc-paths
2928
, hashable
3029
, hls-plugin-api ^>=1.4
3130
, lsp

plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import Development.IDE.GHC.Compat (GenLocated (L), GhcPs,
6666
isQual_maybe, locA,
6767
mi_fixities,
6868
moduleNameString,
69+
ms_hspp_opts,
6970
nameModule_maybe,
7071
nameRdrName, noLocA,
7172
occNameFS, occNameString,
@@ -74,13 +75,13 @@ import Development.IDE.GHC.Compat (GenLocated (L), GhcPs,
7475
pattern RealSrcSpan,
7576
pm_parsed_source,
7677
rdrNameOcc, rds_rules,
77-
srcSpanFile, unLocA)
78+
srcSpanFile, topDir,
79+
unLocA)
7880
import Development.IDE.GHC.Compat.Util hiding (catch, try)
7981
import qualified GHC (Module,
8082
ParsedModule (..),
8183
moduleName, parseModule)
8284
import GHC.Generics (Generic)
83-
import GHC.Paths (libdir)
8485
import Ide.PluginUtils
8586
import Ide.Types
8687
import Language.LSP.Server (LspM,
@@ -330,6 +331,7 @@ suggestRuleRewrites originatingFile pos ms_mod (L _ HsRules {rds_rules}) =
330331
CodeActionRefactor,
331332
RunRetrieParams {..}
332333
)
334+
suggestRuleRewrites _ _ _ _ = []
333335

334336
qualify :: GHC.Module -> String -> String
335337
qualify ms_mod x = T.unpack (printOutputable ms_mod) <> "." <> x
@@ -361,15 +363,19 @@ callRetrie ::
361363
IO ([CallRetrieError], WorkspaceEdit)
362364
callRetrie state session rewrites origin restrictToOriginatingFile = do
363365
knownFiles <- toKnownFiles . unhashed <$> readTVarIO (knownTargetsVar $ shakeExtras state)
366+
#if MIN_VERSION_ghc(9,2,0)
367+
-- retrie needs the libdir for `parseRewriteSpecs`
368+
libdir <- topDir . ms_hspp_opts . msrModSummary <$> useOrFail "Retrie.GetModSummary" (CallRetrieInternalError "file not found") GetModSummary origin
369+
#endif
364370
let reuseParsedModule f = do
365-
pm <- useOrFail "GetParsedModule" NoParse GetParsedModule f
371+
pm <- useOrFail "Retrie.GetParsedModule" NoParse GetParsedModule f
366372
(fixities, pm') <- fixFixities f (fixAnns pm)
367373
return (fixities, pm')
368374
getCPPmodule t = do
369375
nt <- toNormalizedFilePath' <$> makeAbsolute t
370376
let getParsedModule f contents = do
371377
modSummary <- msrModSummary <$>
372-
useOrFail "GetModSummary" (CallRetrieInternalError "file not found") GetModSummary nt
378+
useOrFail "Retrie.GetModSummary" (CallRetrieInternalError "file not found") GetModSummary nt
373379
let ms' =
374380
modSummary
375381
{ ms_hspp_buf =
@@ -427,7 +433,7 @@ callRetrie state session rewrites origin restrictToOriginatingFile = do
427433
(\specs -> apply specs >> addImports annotatedImports)
428434
<$> parseRewriteSpecs
429435
#if MIN_VERSION_ghc(9,2,0)
430-
libdir -- TODO: does this actualy get the proper libdir?
436+
libdir
431437
#endif
432438
(\_f -> return $ NoCPP originParsedModule)
433439
originFixities

0 commit comments

Comments
 (0)