@@ -26,7 +26,8 @@ import qualified Data.Text as T
26
26
import Development.IDE (GhcSession (.. ),
27
27
HscEnvEq (hscEnv ),
28
28
RuleResult , Rules , define ,
29
- srcSpanToRange )
29
+ srcSpanToRange ,
30
+ tmrModSummary )
30
31
import Development.IDE.Core.Compile (TcModuleResult (.. ))
31
32
import Development.IDE.Core.RuleTypes (GetBindings (GetBindings ),
32
33
TypeCheck (TypeCheck ))
@@ -97,6 +98,7 @@ codeLensProvider ideState pId CodeLensParams{_textDocument = TextDocumentIdentif
97
98
mode <- usePropertyLsp # mode pId properties
98
99
fmap (Right . List ) $ case uriToFilePath' uri of
99
100
Just (toNormalizedFilePath' -> filePath) -> liftIO $ do
101
+ env <- fmap hscEnv <$> runAction " codeLens.GhcSession" ideState (use GhcSession filePath)
100
102
tmr <- runAction " codeLens.TypeCheck" ideState (use TypeCheck filePath)
101
103
bindings <- runAction " codeLens.GetBindings" ideState (use GetBindings filePath)
102
104
gblSigs <- runAction " codeLens.GetGlobalBindingTypeSigs" ideState (use GetGlobalBindingTypeSigs filePath)
@@ -123,9 +125,9 @@ codeLensProvider ideState pId CodeLensParams{_textDocument = TextDocumentIdentif
123
125
case mode of
124
126
Always ->
125
127
pure (catMaybes $ generateLensForGlobal <$> gblSigs')
126
- <> generateLensFromDiags (suggestLocalSignature False tmr bindings) -- we still need diagnostics for local bindings
128
+ <> generateLensFromDiags (suggestLocalSignature False env tmr bindings) -- we still need diagnostics for local bindings
127
129
Exported -> pure $ catMaybes $ generateLensForGlobal <$> filter gbExported gblSigs'
128
- Diagnostics -> generateLensFromDiags $ suggestSignature False gblSigs tmr bindings
130
+ Diagnostics -> generateLensFromDiags $ suggestSignature False env gblSigs tmr bindings
129
131
Nothing -> pure []
130
132
131
133
generateLens :: PluginId -> Range -> T. Text -> WorkspaceEdit -> CodeLens
@@ -140,9 +142,9 @@ commandHandler _ideState wedit = do
140
142
141
143
--------------------------------------------------------------------------------
142
144
143
- suggestSignature :: Bool -> Maybe GlobalBindingTypeSigsResult -> Maybe TcModuleResult -> Maybe Bindings -> Diagnostic -> [(T. Text , [TextEdit ])]
144
- suggestSignature isQuickFix mGblSigs mTmr mBindings diag =
145
- suggestGlobalSignature isQuickFix mGblSigs diag <> suggestLocalSignature isQuickFix mTmr mBindings diag
145
+ suggestSignature :: Bool -> Maybe HscEnv -> Maybe GlobalBindingTypeSigsResult -> Maybe TcModuleResult -> Maybe Bindings -> Diagnostic -> [(T. Text , [TextEdit ])]
146
+ suggestSignature isQuickFix env mGblSigs mTmr mBindings diag =
147
+ suggestGlobalSignature isQuickFix mGblSigs diag <> suggestLocalSignature isQuickFix env mTmr mBindings diag
146
148
147
149
suggestGlobalSignature :: Bool -> Maybe GlobalBindingTypeSigsResult -> Diagnostic -> [(T. Text , [TextEdit ])]
148
150
suggestGlobalSignature isQuickFix mGblSigs Diagnostic {_message, _range}
@@ -156,19 +158,20 @@ suggestGlobalSignature isQuickFix mGblSigs Diagnostic{_message, _range}
156
158
[(title, [action])]
157
159
| otherwise = []
158
160
159
- suggestLocalSignature :: Bool -> Maybe TcModuleResult -> Maybe Bindings -> Diagnostic -> [(T. Text , [TextEdit ])]
160
- suggestLocalSignature isQuickFix mTmr mBindings Diagnostic {_message, _range = _range@ Range {.. }}
161
+ suggestLocalSignature :: Bool -> Maybe HscEnv -> Maybe TcModuleResult -> Maybe Bindings -> Diagnostic -> [(T. Text , [TextEdit ])]
162
+ suggestLocalSignature isQuickFix mEnv mTmr mBindings Diagnostic {_message, _range = _range@ Range {.. }}
161
163
| Just (_ :: T. Text , _ :: T. Text , _ :: T. Text , [identifier ]) <-
162
164
(T. unwords . T. words $ _message)
163
165
=~~ (" Polymorphic local binding with no type signature: (.*) ::" :: T. Text )
164
166
, Just bindings <- mBindings
167
+ , Just env <- mEnv
165
168
, localScope <- getFuzzyScope bindings _start _end
166
169
, -- we can't use srcspan to lookup scoped bindings, because the error message reported by GHC includes the entire binding, instead of simply the name
167
170
Just (name, ty) <- find (\ (x, _) -> printName x == T. unpack identifier) localScope >>= \ (name, mTy) -> (name,) <$> mTy
168
171
, Just TcModuleResult {tmrTypechecked = TcGblEnv {tcg_rdr_env, tcg_sigs}} <- mTmr
169
172
, -- not a top-level thing, to avoid duplication
170
173
not $ name `elemNameSet` tcg_sigs
171
- , tyMsg <- printSDocQualifiedUnsafe (mkPrintUnqualifiedDefault tcg_rdr_env) $ pprSigmaType ty
174
+ , tyMsg <- printSDocQualifiedUnsafe (mkPrintUnqualifiedDefault env tcg_rdr_env) $ pprSigmaType ty
172
175
, signature <- T. pack $ printName name <> " :: " <> tyMsg
173
176
, startCharacter <- _character _start
174
177
, startOfLine <- Position (_line _start) startCharacter
0 commit comments