Skip to content

Commit 6399425

Browse files
committed
Get import paths directly from session
1 parent 6ab0630 commit 6399425

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

plugins/default/src/Ide/Plugin/ModuleName.hs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import Data.Maybe (listToMaybe)
2828
import Data.String (IsString)
2929
import Data.Text (Text)
3030
import qualified Data.Text as T
31-
import Development.IDE (GetParsedModule (GetParsedModule),
31+
import Development.IDE (hscEnvWithImportPaths, GetParsedModule (GetParsedModule),
3232
GhcSession (GhcSession),
33-
HscEnvEq (hscEnv), IdeState,
33+
HscEnvEq, IdeState,
3434
List (..), NormalizedFilePath,
3535
Position (Position), Range (Range),
3636
evalGhcEnv, realSrcSpanToRange,
@@ -39,12 +39,9 @@ import Development.IDE (GetParsedModule (GetParsedModule),
3939
import Development.IDE.Plugin (getPid)
4040
import GHC (DynFlags (importPaths),
4141
GenLocated (L),
42-
GhcMonad (getSession),
4342
HsModule (hsmodName),
4443
ParsedModule (pm_parsed_source),
45-
SrcSpan (RealSrcSpan), unLoc)
46-
import GhcPlugins (HscEnv (hsc_IC),
47-
InteractiveContext (ic_dflags))
44+
SrcSpan (RealSrcSpan), unLoc,getSessionDynFlags)
4845
import Ide.Types (CommandFunction, CommandId (..),
4946
PluginCommand (..),
5047
PluginDescriptor (..),
@@ -124,11 +121,10 @@ actions convert lsp state uri = do
124121
pathModuleName :: IdeState -> NormalizedFilePath -> String -> IO (Maybe Text)
125122
pathModuleName state nfp fp = do
126123
session :: HscEnvEq <- runAction "ModuleName.ghcSession" state $ use_ GhcSession nfp
127-
paths <- evalGhcEnv (hscEnv session) $ do
128-
env <- getSession
129-
let df = ic_dflags . hsc_IC $ env
130-
return $ importPaths df
124+
125+
paths <- evalGhcEnv (hscEnvWithImportPaths session) $ importPaths <$> getSessionDynFlags
131126
out ["import paths",show paths]
127+
132128
let maybePrefix = listToMaybe . filter (`isPrefixOf` fp) $ paths
133129
out ["prefix",show maybePrefix]
134130
let maybeMdlName = (\prefix -> replace "/" "." . drop (length prefix+1) $ dropExtension fp) <$> maybePrefix
@@ -158,5 +154,5 @@ asTextEdits :: Action -> [TextEdit]
158154
asTextEdits Action{..} = [TextEdit aRange aCode]
159155

160156
out :: [String] -> IO ()
161-
-- out = print . unwords . ("Plugin ModuleName " :)
162-
out _ = return ()
157+
out = print . unwords . ("Plugin ModuleName " :)
158+
-- out _ = return ()

0 commit comments

Comments
 (0)