Skip to content

Commit b0af06f

Browse files
committed
Prevent GhcSession call on open dependency
1 parent 4e84b99 commit b0af06f

File tree

1 file changed

+48
-45
lines changed

1 file changed

+48
-45
lines changed

ghcide/src/Development/IDE/Plugin/TypeLenses.hs

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -107,52 +107,55 @@ codeLensProvider :: PluginMethodHandler IdeState Method_TextDocumentCodeLens
107107
codeLensProvider ideState pId CodeLensParams{_textDocument = TextDocumentIdentifier uri} = pluginResponse $ do
108108
mode <- liftIO $ runAction "codeLens.config" ideState $ usePropertyAction #mode pId properties
109109
nfp <- getNormalizedFilePath uri
110-
env <- hscEnv . fst
111-
<$> (handleMaybeM "Unable to get GhcSession"
112-
$ liftIO
113-
$ runAction "codeLens.GhcSession" ideState (useWithStale GhcSession nfp)
114-
)
115-
tmr <- fst <$> (
116-
handleMaybeM "Unable to TypeCheck"
110+
case Shake.getSourceFileOrigin nfp of
111+
Shake.FromDependency -> pure $ InL []
112+
Shake.FromProject -> do
113+
env <- hscEnv . fst
114+
<$> (handleMaybeM "Unable to get GhcSession"
115+
$ liftIO
116+
$ runAction "codeLens.GhcSession" ideState (useWithStale GhcSession nfp)
117+
)
118+
tmr <- fst <$> (
119+
handleMaybeM "Unable to TypeCheck"
120+
$ liftIO
121+
$ runAction "codeLens.TypeCheck" ideState (useWithStale TypeCheck nfp)
122+
)
123+
bindings <- fst <$> (
124+
handleMaybeM "Unable to GetBindings"
125+
$ liftIO
126+
$ runAction "codeLens.GetBindings" ideState (useWithStale GetBindings nfp)
127+
)
128+
(gblSigs@(GlobalBindingTypeSigsResult gblSigs'), gblSigsMp) <-
129+
handleMaybeM "Unable to GetGlobalBindingTypeSigs"
117130
$ liftIO
118-
$ runAction "codeLens.TypeCheck" ideState (useWithStale TypeCheck nfp)
119-
)
120-
bindings <- fst <$> (
121-
handleMaybeM "Unable to GetBindings"
122-
$ liftIO
123-
$ runAction "codeLens.GetBindings" ideState (useWithStale GetBindings nfp)
124-
)
125-
(gblSigs@(GlobalBindingTypeSigsResult gblSigs'), gblSigsMp) <-
126-
handleMaybeM "Unable to GetGlobalBindingTypeSigs"
127-
$ liftIO
128-
$ runAction "codeLens.GetGlobalBindingTypeSigs" ideState (useWithStale GetGlobalBindingTypeSigs nfp)
129-
130-
diag <- liftIO $ atomically $ getDiagnostics ideState
131-
hDiag <- liftIO $ atomically $ getHiddenDiagnostics ideState
132-
133-
let toWorkSpaceEdit tedit = WorkspaceEdit (Just $ Map.singleton uri $ tedit) Nothing Nothing
134-
generateLensForGlobal mp sig@GlobalBindingTypeSig{gbRendered} = do
135-
range <- toCurrentRange mp =<< srcSpanToRange (gbSrcSpan sig)
136-
tedit <- gblBindingTypeSigToEdit sig (Just gblSigsMp)
137-
let wedit = toWorkSpaceEdit [tedit]
138-
pure $ generateLens pId range (T.pack gbRendered) wedit
139-
generateLensFromDiags f =
140-
[ generateLens pId _range title edit
141-
| (dFile, _, dDiag@Diagnostic{_range = _range}) <- diag ++ hDiag
142-
, dFile == nfp
143-
, (title, tedit) <- f dDiag
144-
, let edit = toWorkSpaceEdit tedit
145-
]
146-
-- `suggestLocalSignature` relies on diagnostic, if diagnostics don't have the local signature warning,
147-
-- the `bindings` is useless, and if diagnostic has, that means we parsed success, and the `bindings` is fresh.
148-
pure $ InL $ case mode of
149-
Always ->
150-
mapMaybe (generateLensForGlobal gblSigsMp) gblSigs'
151-
<> generateLensFromDiags
152-
(suggestLocalSignature False (Just env) (Just tmr) (Just bindings)) -- we still need diagnostics for local bindings
153-
Exported -> mapMaybe (generateLensForGlobal gblSigsMp) (filter gbExported gblSigs')
154-
Diagnostics -> generateLensFromDiags
155-
$ suggestSignature False (Just env) (Just gblSigs) (Just tmr) (Just bindings)
131+
$ runAction "codeLens.GetGlobalBindingTypeSigs" ideState (useWithStale GetGlobalBindingTypeSigs nfp)
132+
133+
diag <- liftIO $ atomically $ getDiagnostics ideState
134+
hDiag <- liftIO $ atomically $ getHiddenDiagnostics ideState
135+
136+
let toWorkSpaceEdit tedit = WorkspaceEdit (Just $ Map.singleton uri $ tedit) Nothing Nothing
137+
generateLensForGlobal mp sig@GlobalBindingTypeSig{gbRendered} = do
138+
range <- toCurrentRange mp =<< srcSpanToRange (gbSrcSpan sig)
139+
tedit <- gblBindingTypeSigToEdit sig (Just gblSigsMp)
140+
let wedit = toWorkSpaceEdit [tedit]
141+
pure $ generateLens pId range (T.pack gbRendered) wedit
142+
generateLensFromDiags f =
143+
[ generateLens pId _range title edit
144+
| (dFile, _, dDiag@Diagnostic{_range = _range}) <- diag ++ hDiag
145+
, dFile == nfp
146+
, (title, tedit) <- f dDiag
147+
, let edit = toWorkSpaceEdit tedit
148+
]
149+
-- `suggestLocalSignature` relies on diagnostic, if diagnostics don't have the local signature warning,
150+
-- the `bindings` is useless, and if diagnostic has, that means we parsed success, and the `bindings` is fresh.
151+
pure $ InL $ case mode of
152+
Always ->
153+
mapMaybe (generateLensForGlobal gblSigsMp) gblSigs'
154+
<> generateLensFromDiags
155+
(suggestLocalSignature False (Just env) (Just tmr) (Just bindings)) -- we still need diagnostics for local bindings
156+
Exported -> mapMaybe (generateLensForGlobal gblSigsMp) (filter gbExported gblSigs')
157+
Diagnostics -> generateLensFromDiags
158+
$ suggestSignature False (Just env) (Just gblSigs) (Just tmr) (Just bindings)
156159

157160
generateLens :: PluginId -> Range -> T.Text -> WorkspaceEdit -> CodeLens
158161
generateLens pId _range title edit =

0 commit comments

Comments
 (0)