@@ -7,7 +7,8 @@ module Development.IDE.Spans.Pragmas
77 , LineSplitTextEdits (.. )
88 , getNextPragmaInfo
99 , insertNewPragma
10- , getFirstPragma ) where
10+ , getFirstPragma
11+ , getFirstPragmaFast ) where
1112
1213import Control.Lens ((&) , (.~) )
1314import Data.Bits (Bits (setBit ))
@@ -17,7 +18,7 @@ import Data.Text (Text, pack)
1718import qualified Data.Text as Text
1819import Data.Text.Utf16.Rope.Mixed (Rope )
1920import qualified Data.Text.Utf16.Rope.Mixed as Rope
20- import Development.IDE (srcSpanToRange , IdeState , NormalizedFilePath , GhcSession (.. ), getFileContents , hscEnv , runAction )
21+ import Development.IDE (srcSpanToRange , IdeState ( .. ) , NormalizedFilePath , GhcSession (.. ), getFileContents , hscEnv , runAction , GetFileContents ( .. ) )
2122import Development.IDE.GHC.Compat
2223import Development.IDE.GHC.Compat.Util
2324import qualified Language.LSP.Protocol.Types as LSP
@@ -61,6 +62,13 @@ getFirstPragma (PluginId pId) state nfp = do
6162 fileContents <- liftIO $ runAction (T. unpack pId <> " .GetFileContents" ) state $ getFileContents nfp
6263 pure $ getNextPragmaInfo sessionDynFlags fileContents
6364
65+ getFirstPragmaFast :: MonadIO m => PluginId -> IdeState -> NormalizedFilePath -> ExceptT PluginError m NextPragmaInfo
66+ getFirstPragmaFast (PluginId pId) state nfp = do
67+ runIdeActionE (T. unpack pId <> " .GhcSession" ) (shakeExtras state) $ do
68+ (hscEnv -> hsc_dflags -> sessionDynFlags, _) <- useWithStaleFastE GhcSession nfp
69+ fileContents <- fmap (snd . fst ) $ useWithStaleFastE GetFileContents nfp
70+ pure $ getNextPragmaInfo sessionDynFlags fileContents
71+
6472-- Pre-declaration comments parser -----------------------------------------------------
6573
6674-- | Each mode represents the "strongest" thing we've seen so far.
0 commit comments