{-# LANGUAGE LambdaCase #-}

{-# OPTIONS_GHC -Wno-orphans #-}   -- instance Outputable GhcHint

module GHC.Types.Hint.Ppr (
  perhapsAsPat
  -- also, and more interesting: instance Outputable GhcHint
  ) where

import GHC.Prelude

import GHC.Parser.Errors.Basic
import GHC.Types.Hint

import GHC.Hs.Expr ()   -- instance Outputable
import {-# SOURCE #-} GHC.Tc.Types.Origin ( ClsInstOrQC(..) )
import GHC.Types.Id
import GHC.Types.Name (NameSpace, pprDefinedAt, occNameSpace, pprNameSpace, isValNameSpace, nameModule)
import GHC.Types.Name.Reader (RdrName,ImpDeclSpec (..), rdrNameOcc, rdrNameSpace)
import GHC.Types.SrcLoc (SrcSpan(..), srcSpanStartLine)
import GHC.Unit.Module.Imported (ImportedModsVal(..))
import GHC.Unit.Types
import GHC.Utils.Outputable

import Data.List (intersperse)
import qualified Data.List.NonEmpty as NE

instance Outputable GhcHint where
  ppr :: GhcHint -> SDoc
ppr = \case
    UnknownHint a
m
      -> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
m
    SuggestExtension LanguageExtensionHint
extHint
      -> case LanguageExtensionHint
extHint of
          SuggestSingleExtension SDoc
extraUserInfo Extension
ext ->
            (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you intended to use" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Extension -> SDoc
forall a. Outputable a => a -> SDoc
ppr Extension
ext) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestAnyExtension SDoc
extraUserInfo [Extension]
exts ->
            let header :: SDoc
header = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Enable any of the following extensions:"
            in  SDoc
header SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hcat (SDoc -> [SDoc] -> [SDoc]
forall a. a -> [a] -> [a]
intersperse (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
", ") ((Extension -> SDoc) -> [Extension] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map Extension -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Extension]
exts)) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestExtensions SDoc
extraUserInfo [Extension]
exts ->
            let header :: SDoc
header = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Enable all of the following extensions:"
            in  SDoc
header SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hcat (SDoc -> [SDoc] -> [SDoc]
forall a. a -> [a] -> [a]
intersperse (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
", ") ((Extension -> SDoc) -> [Extension] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map Extension -> SDoc
forall a. Outputable a => a -> SDoc
ppr [Extension]
exts)) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
          SuggestExtensionInOrderTo SDoc
extraUserInfo Extension
ext ->
            (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Extension -> SDoc
forall a. Outputable a => a -> SDoc
ppr Extension
ext) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
extraUserInfo
    SuggestCorrectPragmaName [String]
suggestions
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
quotedListWithOr ((String -> SDoc) -> [String] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map String -> SDoc
forall doc. IsLine doc => String -> doc
text [String]
suggestions)
    GhcHint
SuggestMissingDo
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Possibly caused by a missing 'do'?"
    GhcHint
SuggestLetInDo
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you need a 'let' in a 'do' block?"
           SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"e.g. 'let x = 5' instead of 'x = 5'"
    SuggestAddSignatureCabalFile ModuleName
pi_mod_name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Try adding" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name)
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to the"
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"signatures")
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"field in your Cabal file."
    SuggestSignatureInstantiations ModuleName
pi_mod_name [InstantiationSuggestion]
suggestions
      -> let suggested_instantiated_with :: SDoc
suggested_instantiated_with =
               [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hcat (SDoc -> [SDoc] -> [SDoc]
forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate SDoc
forall doc. IsLine doc => doc
comma ([SDoc] -> [SDoc]) -> [SDoc] -> [SDoc]
forall a b. (a -> b) -> a -> b
$
                   [ ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
k SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"=" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
v
                   | InstantiationSuggestion ModuleName
k Module
v <- [InstantiationSuggestion]
suggestions
                   ])
         in String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Try passing -instantiated-with=\"" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<>
              SDoc
suggested_instantiated_with SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"\"" SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
                String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"replacing <" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
pi_mod_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"> as necessary."
    GhcHint
SuggestUseSpaces
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Please use spaces instead."
    SuggestUseWhitespaceAfter OperatorWhitespaceSymbol
sym
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add whitespace after the"
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (OperatorWhitespaceSymbol -> SDoc
pprOperatorWhitespaceSymbol OperatorWhitespaceSymbol
sym) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'.'
    SuggestUseWhitespaceAround String
sym OperatorWhitespaceOccurrence
_occurrence
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add whitespace around" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
sym) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'.'
    GhcHint
SuggestParentheses
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use parentheses."
    GhcHint
SuggestIncreaseMaxPmCheckModels
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Increase the limit or resolve the warnings to suppress this message."
    SuggestAddTypeSignatures AvailableBindings
bindings
      -> case AvailableBindings
bindings of
          -- This might happen when we have bindings which are /too complicated/,
          -- see for example 'DsCannotMixPolyAndUnliftedBindings' in 'GHC.HsToCore.Errors.Types'.
          -- In this case, we emit a generic message.
          AvailableBindings
UnnamedBinding   -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add a type signature."
          NamedBindings (Name
x NE.:| [Name]
xs) ->
            let nameList :: SDoc
nameList = case [Name]
xs of
                  [] -> SDoc -> SDoc
quotes (SDoc -> SDoc) -> (Name -> SDoc) -> Name -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Name -> SDoc) -> Name -> SDoc
forall a b. (a -> b) -> a -> b
$ Name
x
                  [Name]
_  -> (Name -> SDoc) -> [Name] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (SDoc -> SDoc
quotes (SDoc -> SDoc) -> (Name -> SDoc) -> Name -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr) [Name]
xs SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"and" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
x)
            in [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Consider giving"
                    , SDoc
nameList
                    , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"a type signature"]
    SuggestBindToWildcard LHsExpr GhcTc
rhs
      -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Suppress this warning by saying") Int
2 (SDoc -> SDoc
quotes (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"_ <-" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (HsExpr GhcTc) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LHsExpr GhcTc
GenLocated SrcSpanAnnA (HsExpr GhcTc)
rhs)
    SuggestAddInlineOrNoInlinePragma Var
lhs_id Activation
rule_act
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add an INLINE[n] or NOINLINE[n] pragma for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
lhs_id)
              , SDoc -> SDoc
forall doc. IsOutput doc => doc -> doc
whenPprDebug (Activation -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Var -> Activation
idInlineActivation Var
lhs_id) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Activation -> SDoc
forall a. Outputable a => a -> SDoc
ppr Activation
rule_act)
              ]
    SuggestAddPhaseToCompetingRule RuleName
bad_rule
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add phase [n] or [~n] to the competing rule"
              , SDoc -> SDoc
forall doc. IsOutput doc => doc -> doc
whenPprDebug (RuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RuleName
bad_rule) ]
    GhcHint
SuggestIncreaseSimplifierIterations
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Set limit with -fconstraint-solver-iterations=n; n=0 for no limit"
    SuggestUseTypeFromDataKind Maybe RdrName
mb_rdr_name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Type")
         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Data.Kind") SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instead."
         SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
           SDoc -> (RdrName -> SDoc) -> Maybe RdrName -> SDoc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SDoc
forall doc. IsOutput doc => doc
empty
           (\RdrName
rdr_name ->
             String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"NB: with NoStarIsType, " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)
             SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is treated as a regular type operator.")
           Maybe RdrName
mb_rdr_name

    GhcHint
SuggestQualifiedAfterModuleName
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Place" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"qualified")
          SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"after the module name."
    GhcHint
SuggestThQuotationSyntax
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you intended to use quotation syntax of TemplateHaskell,"
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"but the type variable or constructor is missing"
              ]
    SuggestRoles [Role]
nearby
      -> case [Role]
nearby of
               []  -> SDoc
forall doc. IsOutput doc => doc
empty
               [Role
r] -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Role -> SDoc
forall a. Outputable a => a -> SDoc
ppr Role
r)
               -- will this last case ever happen??
               [Role]
_   -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant one of these:")
                           Int
2 ((Role -> SDoc) -> [Role] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (SDoc -> SDoc
quotes (SDoc -> SDoc) -> (Role -> SDoc) -> Role -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Role -> SDoc
forall a. Outputable a => a -> SDoc
ppr) [Role]
nearby)
    GhcHint
SuggestQualifyStarOperator
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"To use (or export) this operator in"
            SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"modules with StarIsType,"
         SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"    including the definition module, you must qualify it."
    GhcHint
SuggestTypeSignatureForm
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"A type signature should be of form <variables> :: <type>"
    SuggestAddToHSigExportList Name
_name Maybe Module
mb_mod
      -> let header :: SDoc
header = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Try adding it to the export list of"
         in case Maybe Module
mb_mod of
              Maybe Module
Nothing -> SDoc
header SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"the hsig file."
              Just Module
mod -> SDoc
header SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"'s hsig file."
    GhcHint
SuggestFixOrphanInstance
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Move the instance declaration to the module of the class or of the type, or"
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"wrap the type with a newtype and declare the instance on the new type."
              ]
    GhcHint
SuggestAddStandaloneDerivation
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use a standalone deriving declaration instead"
    GhcHint
SuggestFillInWildcardConstraint
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Fill in the wildcard constraint yourself"
    GhcHint
SuggestRenameForall
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Consider using another name, such as"
              , SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"forAll") SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
comma SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
                SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"for_all") SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
comma SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
                SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"forall_") SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot ]
    SuggestAppropriateTHTick NameSpace
ns
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps use a" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
how_many SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"tick"
        where
          how_many :: SDoc
how_many
            | NameSpace -> Bool
isValNameSpace NameSpace
ns = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"single"
            | Bool
otherwise         = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"double"
    GhcHint
SuggestDumpSlices
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"If you bound a unique Template Haskell name (NameU)"
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"perhaps via newName,"
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"then -ddump-splices might be useful." ]
    SuggestAddTick (UntickedConstructor LexicalFixity
fixity Name
name)
      -> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use"
              , Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'\'' SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
con
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instead of"
              , SDoc
con SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
mb_dot ]
        where
          con :: SDoc
con = LexicalFixity -> Name -> SDoc
pprUntickedConstructor LexicalFixity
fixity Name
name
          mb_dot :: SDoc
mb_dot
            | LexicalFixity -> Name -> Bool
isBareSymbol LexicalFixity
fixity Name
name
            -- A final dot can be confusing for a symbol without parens, e.g.
            --
            --  * Use ': instead of :.
            = SDoc
forall doc. IsOutput doc => doc
empty
            | Bool
otherwise
            = SDoc
forall doc. IsLine doc => doc
dot

    SuggestAddTick UntickedPromotedThing
UntickedExplicitList
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add a promotion tick, e.g." SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"'[x,y,z]" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
    SuggestMoveToDeclarationSite SDoc
what RdrName
rdr_name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Move the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
what SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to the declaration site of"
         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
    SuggestSimilarNames RdrName
tried_rdr_name NonEmpty SimilarName
similar_names
      -> case NonEmpty SimilarName
similar_names of
            SimilarName
n NE.:| [] -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps use" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SimilarName -> SDoc
pp_item SimilarName
n
            NonEmpty SimilarName
_          -> [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
sep [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps use one of these:"
                              , Int -> SDoc -> SDoc
nest Int
2 ((SimilarName -> SDoc) -> [SimilarName] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas SimilarName -> SDoc
pp_item ([SimilarName] -> SDoc) -> [SimilarName] -> SDoc
forall a b. (a -> b) -> a -> b
$ NonEmpty SimilarName -> [SimilarName]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty SimilarName
similar_names) ]
        where
          tried_ns :: NameSpace
tried_ns = OccName -> NameSpace
occNameSpace (OccName -> NameSpace) -> OccName -> NameSpace
forall a b. (a -> b) -> a -> b
$ RdrName -> OccName
rdrNameOcc RdrName
tried_rdr_name
          pp_item :: SimilarName -> SDoc
pp_item = NameSpace -> SimilarName -> SDoc
pprSimilarName NameSpace
tried_ns
    RemindFieldSelectorSuppressed RdrName
rdr_name [Name]
parents
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Notice that" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name)
         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is a field selector" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
whose
         SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"that has been suppressed by NoFieldSelectors."
      where
        -- parents may be empty if this is a pattern synonym field without a selector
        whose :: SDoc
whose | [Name] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Name]
parents = SDoc
forall doc. IsOutput doc => doc
empty
              | Bool
otherwise    = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"belonging to the type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> [Name] -> SDoc
forall a. [a] -> SDoc
plural [Name]
parents
                                 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [Name] -> SDoc
forall a. Outputable a => [a] -> SDoc
pprQuotedList [Name]
parents
    ImportSuggestion ImportSuggestion
import_suggestion
      -> ImportSuggestion -> SDoc
pprImportSuggestion ImportSuggestion
import_suggestion
    GhcHint
SuggestImportingDataCon
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Import the data constructor to bring it into scope"
    GhcHint
SuggestPlacePragmaInHeader
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant to place it in the module header?"
      SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"The module header is the section at the top of the file, before the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"module") SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"keyword"
    GhcHint
SuggestPatternMatchingSyntax
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use pattern-matching syntax instead"
    SuggestSpecialiseVisibilityHints Name
name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Make sure" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is compiled with -O and that"
           SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"has an INLINABLE pragma"
         where
           mod :: Module
mod = (() :: Constraint) => Name -> Module
Name -> Module
nameModule Name
name
    LoopySuperclassSolveHint PredType
pty ClsInstOrQC
cls_or_qc
      -> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add the constraint" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (PredType -> SDoc
forall a. Outputable a => a -> SDoc
ppr PredType
pty) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
what SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
comma
              , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"even though it seems logically implied by other constraints in the context." ]
        where
          what :: SDoc
          what :: SDoc
what = case ClsInstOrQC
cls_or_qc of
            ClsInstOrQC
IsClsInst -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instance context"
            IsQC {}   -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"context of the quantified constraint"
    SuggestBindTyVarExplicitly Name
tv
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"bind" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tv)
         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"explicitly with" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Char -> SDoc
forall doc. IsLine doc => Char -> doc
char Char
'@' SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tv)

perhapsAsPat :: SDoc
perhapsAsPat :: SDoc
perhapsAsPat = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you meant an as-pattern, which must not be surrounded by whitespace"

-- | Pretty-print an 'ImportSuggestion'.
pprImportSuggestion :: ImportSuggestion -> SDoc
pprImportSuggestion :: ImportSuggestion -> SDoc
pprImportSuggestion (CouldImportFrom NonEmpty (Module, ImportedModsVal)
mods OccName
occ_name)
  | (Module
mod, ImportedModsVal
imv) NE.:| [] <- NonEmpty (Module, ImportedModsVal)
mods
  = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep
      [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you want to add"
      , SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to the import list"
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"in the import of"
      , SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
      , SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv)) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
      ]
  | Bool
otherwise
  = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep
      [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you want to add"
      , SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to one of these import lists:"
      ]
    SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
    Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
        [ SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv))
        | (Module
mod,ImportedModsVal
imv) <- NonEmpty (Module, ImportedModsVal) -> [(Module, ImportedModsVal)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Module, ImportedModsVal)
mods
        ])
pprImportSuggestion (CouldUnhideFrom NonEmpty (Module, ImportedModsVal)
mods OccName
occ_name)
  | (Module
mod, ImportedModsVal
imv) NE.:| [] <- NonEmpty (Module, ImportedModsVal)
mods
  = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep
      [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you want to remove"
      , SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"from the explicit hiding list"
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"in the import of"
      , SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
      , SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv)) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
dot
      ]
  | Bool
otherwise
  = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
fsep
      [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Perhaps you want to remove"
      , SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
occ_name)
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"from the hiding clauses"
      , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"in one of these imports:"
      ]
    SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
    Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
        [ SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (SrcSpan -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImportedModsVal -> SrcSpan
imv_span ImportedModsVal
imv))
        | (Module
mod,ImportedModsVal
imv) <- NonEmpty (Module, ImportedModsVal) -> [(Module, ImportedModsVal)]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty (Module, ImportedModsVal)
mods
        ])

-- | Pretty-print a 'SimilarName'.
pprSimilarName :: NameSpace -> SimilarName -> SDoc
pprSimilarName :: NameSpace -> SimilarName -> SDoc
pprSimilarName NameSpace
_ (SimilarName Name
name)
  = SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (Name -> SDoc
pprDefinedAt Name
name)
pprSimilarName NameSpace
tried_ns (SimilarRdrName RdrName
rdr_name HowInScope
how_in_scope)
  = case HowInScope
how_in_scope of
      LocallyBoundAt SrcSpan
loc ->
        RdrName -> SDoc
pp_ns RdrName
rdr_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
loc'
          where
            loc' :: SDoc
loc' = case SrcSpan
loc of
              UnhelpfulSpan UnhelpfulSpanReason
l -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (UnhelpfulSpanReason -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnhelpfulSpanReason
l)
              RealSrcSpan RealSrcSpan
l Maybe BufSpan
_ -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"line" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (RealSrcSpan -> Int
srcSpanStartLine RealSrcSpan
l))
      ImportedBy ImpDeclSpec
is ->
        RdrName -> SDoc
pp_ns RdrName
rdr_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
rdr_name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
        SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"imported from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ImpDeclSpec -> ModuleName
is_mod ImpDeclSpec
is))

  where
    pp_ns :: RdrName -> SDoc
    pp_ns :: RdrName -> SDoc
pp_ns RdrName
rdr | NameSpace
ns NameSpace -> NameSpace -> Bool
forall a. Eq a => a -> a -> Bool
/= NameSpace
tried_ns = NameSpace -> SDoc
pprNameSpace NameSpace
ns
              | Bool
otherwise      = SDoc
forall doc. IsOutput doc => doc
empty
      where ns :: NameSpace
ns = RdrName -> NameSpace
rdrNameSpace RdrName
rdr