{-# 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.Core.FamInstEnv (FamFlavor(..))
import GHC.Core.TyCon
import GHC.Core.TyCo.Rep     ( mkVisFunTyMany )
import GHC.Hs.Expr ()   -- instance Outputable
import GHC.Tc.Types.Origin ( ClsInstOrQC(..) )
import GHC.Types.Id
import GHC.Types.Name
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."
    SuggestFixOrphanInst { isFamilyInstance :: GhcHint -> Maybe FamFlavor
isFamilyInstance = Maybe FamFlavor
mbFamFlavor }
      -> [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" 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
"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."
              ]
      where
        what :: SDoc
what = case Maybe FamFlavor
mbFamFlavor of
          Maybe FamFlavor
Nothing                  -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"class"
          Just  FamFlavor
SynFamilyInst      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type family"
          Just (DataFamilyInst {}) -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"data family"
    GhcHint
SuggestAddStandaloneDerivation
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use a standalone deriving declaration instead"
    SuggestAddStandaloneKindSignature Name
name
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add a standalone kind signature for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
    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 OccName
occ_name ImportSuggestion
import_suggestion
      -> OccName -> ImportSuggestion -> SDoc
pprImportSuggestion OccName
occ_name ImportSuggestion
import_suggestion
    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
    GhcHint
SuggestRenameTypeVariable
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Consider renaming the type variable."
    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"
    SuggestExplicitBidiPatSyn Name
name LPat GhcRn
pat [LIdP GhcRn]
args
      -> SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Instead use an explicitly bidirectional"
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pattern synonym, e.g.")
            Int
2 (SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pattern" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_args SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
larrow
                     SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> GenLocated SrcSpanAnnA (Pat GhcRn) -> SDoc
forall a. Outputable a => a -> SDoc
ppr LPat GhcRn
GenLocated SrcSpanAnnA (Pat GhcRn)
pat SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"where")
                  Int
2 (SDoc
pp_name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_args SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
forall doc. IsLine doc => doc
equals SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"..."))
         where
           pp_name :: SDoc
pp_name = Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name
           pp_args :: SDoc
pp_args = [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep ((GenLocated SrcSpanAnnN Name -> SDoc)
-> [GenLocated SrcSpanAnnN Name] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnN Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr [LIdP GhcRn]
[GenLocated SrcSpanAnnN Name]
args)
    GhcHint
SuggestSafeHaskell
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Enable Safe Haskell through either Safe, Trustworthy or Unsafe."
    GhcHint
SuggestRemoveRecordWildcard
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Omit the" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"..")
    GhcHint
SuggestIncreaseReductionDepth ->
      [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
        [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use -freduction-depth=0 to disable this check"
        , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"(any upper bound you could choose might fail unpredictably with"
        , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" minor updates to GHC, so disabling the check is recommended if"
        , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" you're sure that type checking should terminate)" ]
    SuggestMoveNonCanonicalDefinition Name
lhs Name
rhs String
refURL ->
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Move definition from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      SDoc -> SDoc
quotes (Name -> SDoc
pprPrefixUnqual Name
rhs) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Name -> SDoc
pprPrefixUnqual Name
lhs) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"See also:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
refURL
    SuggestRemoveNonCanonicalDefinition Name
lhs Name
rhs String
refURL ->
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Either remove definition for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      SDoc -> SDoc
quotes (Name -> SDoc
pprPrefixUnqual Name
lhs) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"(recommended)" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or define as" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
      SDoc -> SDoc
quotes (Name -> SDoc
pprPrefixUnqual Name
lhs 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
<+> Name -> SDoc
pprPrefixUnqual Name
rhs) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"See also:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
refURL
    SuggestEtaReduceAbsDataTySyn TyCon
tc
      -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"If possible, eta-reduce the type synonym" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_tc SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"so that it is nullary."
        where ppr_tc :: SDoc
ppr_tc = SDoc -> SDoc
quotes (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Name -> SDoc) -> Name -> SDoc
forall a b. (a -> b) -> a -> b
$ TyCon -> Name
tyConName TyCon
tc)
    RemindRecordMissingField RuleName
x PredType
r PredType
a ->
      String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"NB: There is no field selector" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_sel
        SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"in scope for record type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_r
      where ppr_sel :: SDoc
ppr_sel = SDoc -> SDoc
quotes (RuleName -> SDoc
forall doc. IsLine doc => RuleName -> doc
ftext RuleName
x SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_arr_r_a)
            ppr_arr_r_a :: SDoc
ppr_arr_r_a = PredType -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PredType -> SDoc) -> PredType -> SDoc
forall a b. (a -> b) -> a -> b
$ (() :: Constraint) => PredType -> PredType -> PredType
PredType -> PredType -> PredType
mkVisFunTyMany PredType
r PredType
a
            ppr_r :: SDoc
ppr_r = SDoc -> SDoc
quotes (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ PredType -> SDoc
forall a. Outputable a => a -> SDoc
ppr PredType
r
    SuggestBindTyVarOnLhs RdrName
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 (RdrName -> SDoc
forall a. Outputable a => a -> SDoc
ppr RdrName
tv) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"on the LHS of the type declaration"
    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 :: OccName -> ImportSuggestion -> SDoc
pprImportSuggestion :: OccName -> ImportSuggestion -> SDoc
pprImportSuggestion OccName
occ_name (CouldImportFrom NonEmpty (Module, ImportedModsVal)
mods)
  | (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
"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 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> 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
"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 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> 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 OccName
occ_name (CouldUnhideFrom NonEmpty (Module, ImportedModsVal)
mods)
  | (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
"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 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> 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
"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 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"at" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> 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 OccName
occ_name (CouldAddTypeKeyword ModuleName
mod)
 = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Add the" 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
"keyword to the import statement:"
        , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
            SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
            SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
occ_name)
        ]
  where
    parens_sp :: doc -> doc
parens_sp doc
d = doc -> doc
forall doc. IsLine doc => doc -> doc
parens (doc
forall doc. IsLine doc => doc
space doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
d doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
space)
pprImportSuggestion OccName
occ_name (CouldRemoveTypeKeyword ModuleName
mod)
  = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Remove the" 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
"keyword from the import statement:"
         , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
             SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
             SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
occ_name) ]
  where
    parens_sp :: doc -> doc
parens_sp doc
d = doc -> doc
forall doc. IsLine doc => doc -> doc
parens (doc
forall doc. IsLine doc => doc
space doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
d doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
space)
pprImportSuggestion OccName
dc_occ (ImportDataCon Maybe (ModuleName, Bool)
Nothing OccName
parent_occ)
  = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Import the data constructor" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
dc_occ) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
    String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"of" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
parent_occ)
pprImportSuggestion OccName
dc_occ (ImportDataCon (Just (ModuleName
mod, Bool
patsyns_enabled)) OccName
parent_occ)
  = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Use"
           , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
parent_occ SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
dc_occ))
           , String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or"
           , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
               SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
parent_occ SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"(..)")
           ] [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++ if Bool
patsyns_enabled
                then [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"or"
                     , Int -> SDoc -> SDoc
nest Int
2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import"
                         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod
                         SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens_sp (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"pattern" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc OccName
dc_occ)
                     ]
                else []
  where
    parens_sp :: doc -> doc
parens_sp doc
d = doc -> doc
forall doc. IsLine doc => doc -> doc
parens (doc
forall doc. IsLine doc => doc
space doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
d doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
space)

-- | 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 Maybe HowInScope
how_in_scope)
  = 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 Maybe HowInScope
how_in_scope of
      Maybe HowInScope
Nothing -> SDoc
forall doc. IsOutput doc => doc
empty
      Just HowInScope
scope -> case HowInScope
scope of
        LocallyBoundAt SrcSpan
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 ->
          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 (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName (Module -> ModuleName) -> Module -> ModuleName
forall a b. (a -> b) -> a -> b
$ ImpDeclSpec -> Module
is_mod ImpDeclSpec
is))
    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

pprPrefixUnqual :: Name -> SDoc
pprPrefixUnqual :: Name -> SDoc
pprPrefixUnqual Name
name =
  OccName -> SDoc
forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc (Name -> OccName
forall a. NamedThing a => a -> OccName
getOccName Name
name)