Skip to content

Commit 90a5c54

Browse files
committed
Avoid blocking when prepping pragmas for inlay
1 parent 177ca8e commit 90a5c54

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

ghcide/src/Development/IDE/Spans/Pragmas.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ module Development.IDE.Spans.Pragmas
77
, LineSplitTextEdits(..)
88
, getNextPragmaInfo
99
, insertNewPragma
10-
, getFirstPragma ) where
10+
, getFirstPragma
11+
, getFirstPragmaFast ) where
1112

1213
import Control.Lens ((&), (.~))
1314
import Data.Bits (Bits (setBit))
@@ -17,7 +18,7 @@ import Data.Text (Text, pack)
1718
import qualified Data.Text as Text
1819
import Data.Text.Utf16.Rope.Mixed (Rope)
1920
import 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 (..))
2122
import Development.IDE.GHC.Compat
2223
import Development.IDE.GHC.Compat.Util
2324
import 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.

plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ inlayHintProvider _ state _ InlayHintParams {_textDocument = TextDocumentIdentif
197197
if isInlayHintsSupported state
198198
then do
199199
nfp <- getNormalizedFilePathE _uri
200-
(ImportActionsResult {forLens, forResolve}, pm) <- runActionE "ImportActions" state $ useWithStaleE ImportActions nfp
200+
(ImportActionsResult {forLens, forResolve}, pm) <-
201+
runIdeActionE "ImportActions" (shakeExtras state) $ useWithStaleFastE ImportActions nfp
201202
let inlayHints = [ inlayHint
202203
| (range, (int, _)) <- forLens
203204
, Just newRange <- [toCurrentRange pm range]

plugins/hls-explicit-record-fields-plugin/src/Ide/Plugin/ExplicitFields.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import Development.IDE.Graph (RuleResult)
9292
import Development.IDE.Graph.Classes (Hashable, NFData)
9393
import Development.IDE.Spans.Pragmas (NextPragmaInfo (..),
9494
getFirstPragma,
95+
getFirstPragmaFast,
9596
insertNewPragma)
9697
import GHC.Generics (Generic)
9798
import GHC.Iface.Ext.Types (Identifier)
@@ -227,8 +228,8 @@ codeActionResolveProvider ideState pId ca uri uid = do
227228
inlayHintDotdotProvider :: Recorder (WithPriority Log) -> PluginMethodHandler IdeState 'Method_TextDocumentInlayHint
228229
inlayHintDotdotProvider _ state pId InlayHintParams {_textDocument = TextDocumentIdentifier uri, _range = visibleRange} = do
229230
nfp <- getNormalizedFilePathE uri
230-
pragma <- getFirstPragma pId state nfp
231231
runIdeActionE "ExplicitFields.CollectRecords" (shakeExtras state) $ do
232+
pragma <- getFirstPragmaFast pId state nfp
232233
(crr@CRR {crCodeActions, crCodeActionResolve}, pm) <- useWithStaleFastE CollectRecords nfp
233234
let -- Get all records with dotdot in current nfp
234235
records = [ record
@@ -691,4 +692,3 @@ getRecPatterns _ = ([], False)
691692

692693
printFieldName :: Outputable a => a -> Text
693694
printFieldName = stripOccNamePrefix . printOutputable
694-

0 commit comments

Comments
 (0)