Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make type lenses plugin configurable #1491

Merged
merged 13 commits into from
Mar 5, 2021
11 changes: 1 addition & 10 deletions ghcide/src/Development/IDE/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ typecheckModule (IdeDefer defer) hsc keep_lbls pm = do

modSummary' <- initPlugins hsc modSummary
(warnings, tcm) <- withWarnings "typecheck" $ \tweak ->
tcRnModule hsc keep_lbls $ enableTopLevelWarnings
$ demoteIfDefer pm{pm_mod_summary = tweak modSummary'}
tcRnModule hsc keep_lbls $ demoteIfDefer pm{pm_mod_summary = tweak modSummary'}
let errorPipeline = unDefer . hideDiag dflags . tagDiag
diags = map errorPipeline warnings
deferedError = any fst diags
Expand Down Expand Up @@ -390,14 +389,6 @@ demoteTypeErrorsToWarnings =
. (`gopt_set` Opt_DeferTypedHoles)
. (`gopt_set` Opt_DeferOutOfScopeVariables)

enableTopLevelWarnings :: ParsedModule -> ParsedModule
enableTopLevelWarnings =
(update_pm_mod_summary . update_hspp_opts)
((`wopt_set` Opt_WarnMissingPatternSynonymSignatures) .
(`wopt_set` Opt_WarnMissingSignatures))
-- the line below would show also warnings for let bindings without signature
-- ((`wopt_set` Opt_WarnMissingSignatures) . (`wopt_set` Opt_WarnMissingLocalSignatures)))

update_hspp_opts :: (DynFlags -> DynFlags) -> ModSummary -> ModSummary
update_hspp_opts up ms = ms{ms_hspp_opts = up $ ms_hspp_opts ms}

Expand Down
19 changes: 13 additions & 6 deletions ghcide/src/Development/IDE/Plugin/CodeAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ import Development.IDE.GHC.Util (prettyPrint,
printRdrName)
import Development.IDE.Plugin.CodeAction.ExactPrint
import Development.IDE.Plugin.CodeAction.PositionIndexed
import Development.IDE.Plugin.TypeLenses (suggestSignature)
import Development.IDE.Plugin.TypeLenses (GetGlobalBindingTypeSigs (GetGlobalBindingTypeSigs),
GlobalBindingTypeSigsResult,
suggestSignature)
import Development.IDE.Spans.Common
import Development.IDE.Spans.LocalBindings (Bindings)
import Development.IDE.Types.Exports
import Development.IDE.Types.HscEnvEq
import Development.IDE.Types.Location
Expand Down Expand Up @@ -97,13 +100,15 @@ codeAction state _ (CodeActionParams _ _ (TextDocumentIdentifier uri) _range Cod
let text = Rope.toText . (_text :: VirtualFile -> Rope.Rope) <$> contents
mbFile = toNormalizedFilePath' <$> uriToFilePath uri
diag <- fmap (\(_, _, d) -> d) . filter (\(p, _, _) -> mbFile == Just p) <$> getDiagnostics state
(ideOptions, join -> parsedModule, join -> env, join -> annotatedPS, join -> tcM, join -> har) <- runAction "CodeAction" state $
(,,,,,) <$> getIdeOptions
(ideOptions, join -> parsedModule, join -> env, join -> annotatedPS, join -> tcM, join -> har, join -> bindings, join -> gblSigs) <- runAction "CodeAction" state $
(,,,,,,,) <$> getIdeOptions
<*> getParsedModule `traverse` mbFile
<*> use GhcSession `traverse` mbFile
<*> use GetAnnotatedParsedSource `traverse` mbFile
<*> use TypeCheck `traverse` mbFile
<*> use GetHieAst `traverse` mbFile
<*> use GetBindings `traverse` mbFile
<*> use GetGlobalBindingTypeSigs `traverse` mbFile
-- This is quite expensive 0.6-0.7s on GHC
pkgExports <- maybe mempty envPackageExports env
localExports <- readVar (exportsMap $ shakeExtras state)
Expand All @@ -112,7 +117,7 @@ codeAction state _ (CodeActionParams _ _ (TextDocumentIdentifier uri) _range Cod
df = ms_hspp_opts . pm_mod_summary <$> parsedModule
actions =
[ mkCA title [x] edit
| x <- xs, (title, tedit) <- suggestAction exportsMap ideOptions parsedModule text df annotatedPS tcM har x
| x <- xs, (title, tedit) <- suggestAction exportsMap ideOptions parsedModule text df annotatedPS tcM har bindings gblSigs x
, let edit = WorkspaceEdit (Just $ Map.singleton uri $ List tedit) Nothing
]
actions' = caRemoveRedundantImports parsedModule text diag xs uri
Expand Down Expand Up @@ -144,12 +149,14 @@ suggestAction
-> Maybe (Annotated ParsedSource)
-> Maybe TcModuleResult
-> Maybe HieAstResult
-> Maybe Bindings
-> Maybe GlobalBindingTypeSigsResult
-> Diagnostic
-> [(T.Text, [TextEdit])]
suggestAction packageExports ideOptions parsedModule text df annSource tcM har diag =
suggestAction packageExports ideOptions parsedModule text df annSource tcM har bindings gblSigs diag =
concat
-- Order these suggestions by priority
[ suggestSignature True diag
[ suggestSignature True gblSigs tcM bindings diag
, rewrite df annSource $ \_ ps -> suggestExtendImport packageExports ps diag
, rewrite df annSource $ \df ps ->
suggestImportDisambiguation df text ps diag
Expand Down
Loading