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