From 1931b729e5e806d4a4a70a455965ae126e6e5e48 Mon Sep 17 00:00:00 2001 From: Nathan Maxson Date: Mon, 26 Jun 2023 16:13:44 +0300 Subject: [PATCH] Fixes pragma plugin offering incorrect code actions #3673 --- plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs index bd37f36a8c..75672fa9a1 100644 --- a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs +++ b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs @@ -137,7 +137,8 @@ warningBlacklist = ["deferred-type-errors"] -- | Offer to add a missing Language Pragma to the top of a file. -- Pragmas are defined by a curated list of known pragmas, see 'possiblePragmas'. suggestAddPragma :: Maybe DynFlags -> Diagnostic -> [PragmaEdit] -suggestAddPragma mDynflags Diagnostic {_message} = genPragma _message +suggestAddPragma mDynflags Diagnostic {_message, _source} + | _source == Just "typecheck" || _source == Just "parser" = genPragma _message where genPragma target = [("Add \"" <> r <> "\"", LangExt r) | r <- findPragma target, r `notElem` disabled] @@ -149,6 +150,7 @@ suggestAddPragma mDynflags Diagnostic {_message} = genPragma _message -- When the module failed to parse, we don't have access to its -- dynFlags. In that case, simply don't disable any pragmas. [] +suggestAddPragma _ _ = [] -- | Find all Pragmas are an infix of the search term. findPragma :: T.Text -> [T.Text]