From 2ba59fb6f4710999aa444277659659b6ec8586f8 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sat, 16 Apr 2022 21:44:28 +0800 Subject: [PATCH 01/12] Unify showSDocUnsafe --- .../Development/IDE/GHC/Compat/Outputable.hs | 18 ++++++++++- ghcide/src/Development/IDE/GHC/Util.hs | 29 ++++++++++------- ghcide/src/Development/IDE/LSP/Outline.hs | 28 ++++++++--------- .../src/Development/IDE/Plugin/CodeAction.hs | 31 +++++++++---------- .../IDE/Plugin/CodeAction/ExactPrint.hs | 10 +++--- .../src/Development/IDE/Plugin/Completions.hs | 4 +-- .../IDE/Plugin/Completions/Logic.hs | 15 ++++----- ghcide/src/Development/IDE/Spans/AtPoint.hs | 5 +-- ghcide/src/Development/IDE/Spans/Common.hs | 18 +++++------ .../Development/IDE/Spans/Documentation.hs | 5 +-- ghcide/src/Development/IDE/Types/Exports.hs | 2 +- .../src/Ide/Plugin/ChangeTypeSignature.hs | 4 +-- .../src/Ide/Plugin/Eval/CodeLens.hs | 5 +-- .../src/Ide/Plugin/Eval/GHC.hs | 7 +++-- .../src/Ide/Plugin/Eval/Util.hs | 7 +---- .../src/Ide/Plugin/ExplicitImports.hs | 2 +- .../src/Ide/Plugin/Pragmas.hs | 4 +-- .../src/Ide/Plugin/RefineImports.hs | 2 +- .../hls-tactics-plugin/src/Wingman/Debug.hs | 5 +-- 19 files changed, 108 insertions(+), 93 deletions(-) diff --git a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs index f1ace4693b..b45e0b91b0 100644 --- a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs +++ b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs @@ -4,11 +4,11 @@ module Development.IDE.GHC.Compat.Outputable ( SDoc, Outputable, showSDoc, - showSDocUnsafe, showSDocForUser, ppr, pprPanic, text, vcat, (<+>), ($$), empty, hang, nest, printSDocQualifiedUnsafe, printNameWithoutUniques, + printWithoutUniques, printSDocAllTheWay, mkPrintUnqualified, mkPrintUnqualifiedDefault, @@ -68,6 +68,22 @@ import qualified Outputable as Out import SrcLoc #endif +printWithoutUniques :: Outputable a => a -> String +printWithoutUniques = +#if MIN_VERSION_ghc(9,2,0) + renderWithContext (defaultSDocContext + { + sdocStyle = defaultUserStyle + , sdocSuppressUniques = True + , sdocCanUseUnicode = True + }) . ppr +#else + go . ppr + where + go sdoc = oldRenderWithStyle dflags sdoc (mkUserStyle dflags neverQualify AllTheWay) + dflags = unsafeGlobalDynFlags `gopt_set` Opt_SuppressUniques +#endif + printNameWithoutUniques :: Outputable a => a -> String printNameWithoutUniques = #if MIN_VERSION_ghc(9,2,0) diff --git a/ghcide/src/Development/IDE/GHC/Util.hs b/ghcide/src/Development/IDE/GHC/Util.hs index 4e002b13ec..c46a6bb00c 100644 --- a/ghcide/src/Development/IDE/GHC/Util.hs +++ b/ghcide/src/Development/IDE/GHC/Util.hs @@ -8,7 +8,6 @@ module Development.IDE.GHC.Util( evalGhcEnv, -- * GHC wrappers prettyPrint, - unsafePrintSDoc, printRdrName, Development.IDE.GHC.Util.printName, ParseResult(..), runParser, @@ -28,7 +27,11 @@ module Development.IDE.GHC.Util( setHieDir, dontWriteHieFiles, disableWarningsAsErrors, - traceAst) where + traceAst, + showGhc, + showGhcWithUniques, + prettyPrintWithUniques + ) where #if MIN_VERSION_ghc(9,2,0) import GHC.Data.FastString @@ -130,16 +133,9 @@ stringBufferToByteString StringBuffer{..} = PS buf cur len bytestringToStringBuffer :: ByteString -> StringBuffer bytestringToStringBuffer (PS buf cur len) = StringBuffer{..} --- | Pretty print a GHC value using 'unsafeGlobalDynFlags '. -prettyPrint :: Outputable a => a -> String -prettyPrint = unsafePrintSDoc . ppr - -unsafePrintSDoc :: SDoc -> String -unsafePrintSDoc sdoc = showSDocUnsafe sdoc - -- | Pretty print a 'RdrName' wrapping operators in parens printRdrName :: RdrName -> String -printRdrName name = showSDocUnsafe $ parenSymOcc rn (ppr rn) +printRdrName name = prettyPrint $ parenSymOcc rn (ppr rn) where rn = rdrNameOcc name @@ -304,7 +300,7 @@ traceAst lbl x #if MIN_VERSION_ghc(9,2,0) renderDump = renderWithContext defaultSDocContext{sdocStyle = defaultDumpStyle, sdocPprDebug = True} #else - renderDump = unsafePrintSDoc + renderDump = prettyPrintWithUniques #endif htmlDump = showAstDataHtml x doTrace = unsafePerformIO $ do @@ -318,4 +314,15 @@ traceAst lbl x #endif , "file://" ++ htmlDumpFileName] +prettyPrintWithUniques :: Outputable a => a -> String +prettyPrintWithUniques = showSDocUnsafe . ppr + +-- | Pretty print a GHC value using 'unsafeGlobalDynFlags '. +prettyPrint :: Outputable a => a -> String +prettyPrint = printWithoutUniques + +showGhcWithUniques :: Outputable a => a -> T.Text +showGhcWithUniques = T.pack . showSDocUnsafe . ppr +showGhc :: Outputable a => a -> T.Text +showGhc = T.pack . printWithoutUniques diff --git a/ghcide/src/Development/IDE/LSP/Outline.hs b/ghcide/src/Development/IDE/LSP/Outline.hs index 17d6622312..eeffbad0e6 100644 --- a/ghcide/src/Development/IDE/LSP/Outline.hs +++ b/ghcide/src/Development/IDE/LSP/Outline.hs @@ -13,7 +13,7 @@ import Control.Monad.IO.Class import Data.Functor import Data.Generics import Data.Maybe -import Data.Text (Text, pack) +import Data.Text (Text) import qualified Data.Text as T import Development.IDE.Core.Rules import Development.IDE.Core.Shake @@ -31,6 +31,7 @@ import Language.LSP.Types (DocumentSymbol (..), type (|?) (InL), uriToFilePath) #if MIN_VERSION_ghc(9,2,0) import Data.List.NonEmpty (nonEmpty, toList) +import Development.IDE.GHC.Util (showGhc) #endif moduleOutline @@ -47,7 +48,7 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif moduleSymbol = hsmodName >>= \case (L (locA -> (RealSrcSpan l _)) m) -> Just $ (defDocumentSymbol l :: DocumentSymbol) - { _name = pprText m + { _name = showGhc m , _kind = SkFile , _range = Range (Position 0 0) (Position maxBound 0) -- _ltop is 0 0 0 0 } @@ -71,17 +72,17 @@ documentSymbolForDecl :: LHsDecl GhcPs -> Maybe DocumentSymbol documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ FamDecl { tcdFam = FamilyDecl { fdLName = L _ n, fdInfo, fdTyVars } })) = Just (defDocumentSymbol l :: DocumentSymbol) { _name = showRdrName n - <> (case pprText fdTyVars of + <> (case showGhc fdTyVars of "" -> "" t -> " " <> t ) - , _detail = Just $ pprText fdInfo + , _detail = Just $ showGhc fdInfo , _kind = SkFunction } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ ClassDecl { tcdLName = L _ name, tcdSigs, tcdTyVars })) = Just (defDocumentSymbol l :: DocumentSymbol) { _name = showRdrName name - <> (case pprText tcdTyVars of + <> (case showGhc tcdTyVars of "" -> "" t -> " " <> t ) @@ -152,7 +153,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ SynDecl { tcdLName , _selectionRange = realSrcSpanToRange l' } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (InstD _ ClsInstD { cid_inst = ClsInstDecl { cid_poly_ty } })) - = Just (defDocumentSymbol l :: DocumentSymbol) { _name = pprText cid_poly_ty + = Just (defDocumentSymbol l :: DocumentSymbol) { _name = showGhc cid_poly_ty , _kind = SkInterface } #if MIN_VERSION_ghc(9,2,0) @@ -162,7 +163,7 @@ documentSymbolForDecl (L (RealSrcSpan l _) (InstD _ DataFamInstD { dfid_inst = D #endif = Just (defDocumentSymbol l :: DocumentSymbol) { _name = showRdrName (unLoc feqn_tycon) <> " " <> T.unwords - (map pprText feqn_pats) + (map showGhc feqn_pats) , _kind = SkInterface } #if MIN_VERSION_ghc(9,2,0) @@ -172,12 +173,12 @@ documentSymbolForDecl (L (RealSrcSpan l _) (InstD _ TyFamInstD { tfid_inst = TyF #endif = Just (defDocumentSymbol l :: DocumentSymbol) { _name = showRdrName (unLoc feqn_tycon) <> " " <> T.unwords - (map pprText feqn_pats) + (map showGhc feqn_pats) , _kind = SkInterface } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (DerivD _ DerivDecl { deriv_type })) = gfindtype deriv_type <&> \(L (_ :: SrcSpan) name) -> - (defDocumentSymbol l :: DocumentSymbol) { _name = pprText @(HsType GhcPs) + (defDocumentSymbol l :: DocumentSymbol) { _name = showGhc @(HsType GhcPs) name , _kind = SkInterface } @@ -188,7 +189,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (ValD _ FunBind{fun_id = L } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (ValD _ PatBind{pat_lhs})) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = pprText pat_lhs + { _name = showGhc pat_lhs , _kind = SkFunction } @@ -228,7 +229,7 @@ documentSymbolForImportSummary importSymbols = documentSymbolForImport :: LImportDecl GhcPs -> Maybe DocumentSymbol documentSymbolForImport (L (locA -> (RealSrcSpan l _)) ImportDecl { ideclName, ideclQualified }) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = "import " <> pprText ideclName + { _name = "import " <> showGhc ideclName , _kind = SkModule #if MIN_VERSION_ghc(8,10,0) , _detail = case ideclQualified of { NotQualified -> Nothing; _ -> Just "qualified" } @@ -250,10 +251,7 @@ defDocumentSymbol l = DocumentSymbol { .. } where _tags = Nothing showRdrName :: RdrName -> Text -showRdrName = pprText - -pprText :: Outputable a => a -> Text -pprText = pack . showSDocUnsafe . ppr +showRdrName = showGhc -- the version of getConNames for ghc9 is restricted to only the renaming phase #if !MIN_VERSION_ghc(9,2,0) diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction.hs b/ghcide/src/Development/IDE/Plugin/CodeAction.hs index 1585864279..af7902c610 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction.hs @@ -50,8 +50,7 @@ import Development.IDE.GHC.Error import Development.IDE.GHC.ExactPrint import Development.IDE.GHC.Util (prettyPrint, printRdrName, - traceAst, - unsafePrintSDoc) + traceAst, showGhc) import Development.IDE.Plugin.CodeAction.Args import Development.IDE.Plugin.CodeAction.ExactPrint import Development.IDE.Plugin.CodeAction.PositionIndexed @@ -546,7 +545,7 @@ suggestDeleteUnusedBinding isTheBinding span = srcSpanToRange span == Just _range isSameName :: IdP GhcPs -> String -> Bool - isSameName x name = showSDocUnsafe (ppr x) == name + isSameName x name = prettyPrint x == name data ExportsAs = ExportName | ExportPattern | ExportFamily | ExportAll deriving (Eq) @@ -1013,7 +1012,7 @@ occursUnqualified symbol ImportDecl{..} occursUnqualified _ _ = False symbolOccursIn :: T.Text -> IE GhcPs -> Bool -symbolOccursIn symb = any ((== symb). showNameWithoutUniques) . ieNames +symbolOccursIn symb = any ((== symb). showGhc) . ieNames targetModuleName :: ModuleTarget -> ModuleName targetModuleName ImplicitPrelude{} = mkModuleName "Prelude" @@ -1423,7 +1422,7 @@ newImport modName mSymbol mQual hiding = NewImport impStmt symImp | Just symbol <- mSymbol , symOcc <- mkVarOcc $ T.unpack symbol = - " (" <> T.pack (unsafePrintSDoc (parenSymOcc symOcc $ ppr symOcc)) <> ")" + " (" <> showGhc (parenSymOcc symOcc $ ppr symOcc) <> ")" | otherwise = "" impStmt = "import " @@ -1617,32 +1616,32 @@ smallerRangesForBindingExport lies b = b' = wrapOperatorInParens . unqualify $ b #if !MIN_VERSION_ghc(9,2,0) ranges' (L _ (IEThingWith _ thing _ inners labels)) - | showSDocUnsafe (ppr thing) == b' = [] + | prettyPrint thing == b' = [] | otherwise = - [ locA l' | L l' x <- inners, showSDocUnsafe (ppr x) == b'] - ++ [ l' | L l' x <- labels, showSDocUnsafe (ppr x) == b'] + [ locA l' | L l' x <- inners, prettyPrint x == b'] + ++ [ l' | L l' x <- labels, prettyPrint x == b'] #else ranges' (L _ (IEThingWith _ thing _ inners)) - | showSDocUnsafe (ppr thing) == b' = [] + | prettyPrint thing == b' = [] | otherwise = - [ locA l' | L l' x <- inners, showSDocUnsafe (ppr x) == b'] + [ locA l' | L l' x <- inners, prettyPrint x == b'] #endif ranges' _ = [] rangesForBinding' :: String -> LIE GhcPs -> [SrcSpan] -rangesForBinding' b (L (locA -> l) x@IEVar{}) | showSDocUnsafe (ppr x) == b = [l] -rangesForBinding' b (L (locA -> l) x@IEThingAbs{}) | showSDocUnsafe (ppr x) == b = [l] -rangesForBinding' b (L (locA -> l) (IEThingAll _ x)) | showSDocUnsafe (ppr x) == b = [l] +rangesForBinding' b (L (locA -> l) x@IEVar{}) | prettyPrint x == b = [l] +rangesForBinding' b (L (locA -> l) x@IEThingAbs{}) | prettyPrint x == b = [l] +rangesForBinding' b (L (locA -> l) (IEThingAll _ x)) | prettyPrint x == b = [l] #if !MIN_VERSION_ghc(9,2,0) rangesForBinding' b (L l (IEThingWith _ thing _ inners labels)) #else rangesForBinding' b (L (locA -> l) (IEThingWith _ thing _ inners)) #endif - | showSDocUnsafe (ppr thing) == b = [l] + | prettyPrint thing == b = [l] | otherwise = - [ locA l' | L l' x <- inners, showSDocUnsafe (ppr x) == b] + [ locA l' | L l' x <- inners, prettyPrint x == b] #if !MIN_VERSION_ghc(9,2,0) - ++ [ l' | L l' x <- labels, showSDocUnsafe (ppr x) == b] + ++ [ l' | L l' x <- labels, prettyPrint x == b] #endif rangesForBinding' _ _ = [] diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs index 18019b83f6..6e87a55fbf 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs @@ -355,8 +355,8 @@ extendImportTopLevel thing (L l it@ImportDecl{..}) top <- uniqueSrcSpanT let rdr = reLocA $ L src $ mkRdrUnqual $ mkVarOcc thing let alreadyImported = - showNameWithoutUniques (occName (unLoc rdr)) - `elem` map (showNameWithoutUniques @OccName) (listify (const True) lies) + showGhc (occName (unLoc rdr)) + `elem` map (showGhc @OccName) (listify (const True) lies) when alreadyImported $ lift (Left $ thing <> " already imported") @@ -456,8 +456,8 @@ extendImportViaParent df parent child (L l it@ImportDecl{..}) childRdr <- pure $ setEntryDP childRdr $ SameLine $ if hasSibling then 1 else 0 #endif let alreadyImported = - showNameWithoutUniques (occName (unLoc childRdr)) - `elem` map (showNameWithoutUniques @OccName) (listify (const True) lies') + showGhc (occName (unLoc childRdr)) + `elem` map (showGhc @OccName) (listify (const True) lies') when alreadyImported $ lift (Left $ child <> " already included in " <> parent <> " imports") @@ -542,7 +542,7 @@ addCommaInImportList lies x = do #endif unIEWrappedName :: IEWrappedName (IdP GhcPs) -> String -unIEWrappedName (occName -> occ) = showSDocUnsafe $ parenSymOcc occ (ppr occ) +unIEWrappedName (occName -> occ) = prettyPrint $ parenSymOcc occ (ppr occ) hasParen :: String -> Bool hasParen ('(' : _) = True diff --git a/ghcide/src/Development/IDE/Plugin/Completions.hs b/ghcide/src/Development/IDE/Plugin/Completions.hs index edc656ada0..6e37b99a77 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions.hs @@ -27,7 +27,7 @@ import qualified Development.IDE.Core.Shake as Shake import Development.IDE.GHC.Compat import Development.IDE.GHC.Error (rangeToSrcSpan) import Development.IDE.GHC.ExactPrint (GetAnnotatedParsedSource (GetAnnotatedParsedSource)) -import Development.IDE.GHC.Util (prettyPrint) +import Development.IDE.GHC.Util (showGhc) import Development.IDE.Graph import Development.IDE.Plugin.CodeAction (newImport, newImportToEdit) @@ -213,7 +213,7 @@ extendImportHandler ideState edit@ExtendImport {..} = do <> "’ from " <> importName <> " (at " - <> T.pack (prettyPrint srcSpan) + <> showGhc srcSpan <> ")" void $ LSP.sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wedit) (\_ -> pure ()) return $ Right Null diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index 14b8143dbf..b383bee6f8 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -214,7 +214,7 @@ mkCompl pprLineCol :: SrcLoc -> T.Text pprLineCol (UnhelpfulLoc fs) = T.pack $ unpackFS fs pprLineCol (RealSrcLoc loc _) = - "line " <> ppr(srcLocLine loc) <> ", column " <> ppr(srcLocCol loc) + "line " <> showGhc (srcLocLine loc) <> ", column " <> showGhc (srcLocCol loc) mkAdditionalEditsCommand :: PluginId -> ExtendImport -> Command @@ -244,7 +244,7 @@ mkNameCompItem doc thingParent origName provenance thingType isInfix docs !imp = thingParent, importName = showModName $ unLoc $ ideclName $ unLoc x, importQual = getImportQual x, - newThing = showNameWithoutUniques origName + newThing = showGhc origName } stripForall :: T.Text -> T.Text @@ -350,7 +350,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do let packageState = hscEnv env curModName = moduleName curMod - curModNameText = ppr curModName + curModNameText = showGhc curModName importMap = Map.fromList [ (l, imp) | imp@(L (locA -> (RealSrcSpan l _)) _) <- limports ] @@ -384,9 +384,9 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do -- we don't want to extend import if it's already in scope guard . null $ lookupGRE_Name inScopeEnv n -- or if it doesn't have a real location - loc <- realSpan $ is_dloc spec + loc <- realSpan $ is_dloc spec Map.lookup loc importMap - compItem <- toCompItem par curMod (ppr $ is_mod spec) n originalImportDecl + compItem <- toCompItem par curMod (showGhc $ is_mod spec) n originalImportDecl let unqual | is_qual spec = [] | otherwise = compItem @@ -498,7 +498,7 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod findRecordCompl :: Uri -> ParsedModule -> Provenance -> TyClDecl GhcPs -> [CompItem] findRecordCompl uri pmod mn DataDecl {tcdLName, tcdDataDefn} = result where - result = [mkRecordSnippetCompItem uri (Just $ showNameWithoutUniques $ unLoc tcdLName) + result = [mkRecordSnippetCompItem uri (Just $ showGhc $ unLoc tcdLName) (showGhc . unLoc $ con_name) field_labels mn doc Nothing | ConDeclH98{..} <- unLoc <$> dd_cons tcdDataDefn , Just con_details <- [getFlds con_args] @@ -528,9 +528,6 @@ findRecordCompl uri pmod mn DataDecl {tcdLName, tcdDataDefn} = result extract _ = [] findRecordCompl _ _ _ _ = [] -ppr :: Outputable a => a -> T.Text -ppr = T.pack . prettyPrint - toggleSnippets :: ClientCapabilities -> CompletionsConfig -> CompletionItem -> CompletionItem toggleSnippets ClientCapabilities {_textDocument} CompletionsConfig{..} = removeSnippetsWhen (not $ enableSnippets && supported) diff --git a/ghcide/src/Development/IDE/Spans/AtPoint.hs b/ghcide/src/Development/IDE/Spans/AtPoint.hs index 0bdff4aa9b..687b025e39 100644 --- a/ghcide/src/Development/IDE/Spans/AtPoint.hs +++ b/ghcide/src/Development/IDE/Spans/AtPoint.hs @@ -55,6 +55,7 @@ import Data.Version (showVersion) import Development.IDE.Types.Shake (WithHieDb) import HieDb hiding (pointCommand) import System.Directory (doesFileExist) +import Development.IDE.GHC.Util (showGhc) -- | Gives a Uri for the module, given the .hie file location and the the module info -- The Bool denotes if it is a boot module @@ -229,7 +230,7 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p prettyNames :: [T.Text] prettyNames = map prettyName names prettyName (Right n, dets) = T.unlines $ - wrapHaskell (showNameWithoutUniques n <> maybe "" (" :: " <>) ((prettyType <$> identType dets) <|> maybeKind)) + wrapHaskell (showGhc n <> maybe "" (" :: " <>) ((prettyType <$> identType dets) <|> maybeKind)) : definedAt n ++ maybeToList (prettyPackageName n) ++ catMaybes [ T.unlines . spanDocToMarkdown <$> lookupNameEnv dm n @@ -255,7 +256,7 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p -- see the code of 'pprNameDefnLoc' for more information case nameSrcLoc name of UnhelpfulLoc {} | isInternalName name || isSystemName name -> [] - _ -> ["*Defined " <> T.pack (showSDocUnsafe $ pprNameDefnLoc name) <> "*"] + _ -> ["*Defined " <> showGhc (pprNameDefnLoc name) <> "*"] typeLocationsAtPoint :: forall m diff --git a/ghcide/src/Development/IDE/Spans/Common.hs b/ghcide/src/Development/IDE/Spans/Common.hs index 54ee952f49..eeb6811af7 100644 --- a/ghcide/src/Development/IDE/Spans/Common.hs +++ b/ghcide/src/Development/IDE/Spans/Common.hs @@ -3,9 +3,7 @@ {-# LANGUAGE DerivingStrategies #-} module Development.IDE.Spans.Common ( - showGhc -, showNameWithoutUniques -, unqualIEWrapName + unqualIEWrapName , safeTyThingId , safeTyThingType , SpanDoc(..) @@ -34,18 +32,18 @@ import qualified Documentation.Haddock.Types as H type DocMap = NameEnv SpanDoc type KindMap = NameEnv TyThing -showGhc :: Outputable a => a -> T.Text -showGhc = showSD . withPprStyle defaultUserStyle . ppr +-- showGhc :: Outputable a => a -> T.Text +-- showGhc = showSD . withPprStyle defaultUserStyle . ppr -showSD :: SDoc -> T.Text -showSD = T.pack . unsafePrintSDoc +-- showSD :: SDoc -> T.Text +-- showSD = T.pack . unsafePrintSDoc -showNameWithoutUniques :: Outputable a => a -> T.Text -showNameWithoutUniques = T.pack . printNameWithoutUniques +-- showNameWithoutUniques :: Outputable a => a -> T.Text +-- showNameWithoutUniques = T.pack . printNameWithoutUniques -- | Shows IEWrappedName, without any modifier, qualifier or unique identifier. unqualIEWrapName :: IEWrappedName RdrName -> T.Text -unqualIEWrapName = showNameWithoutUniques . rdrNameOcc . ieWrappedName +unqualIEWrapName = showGhc . rdrNameOcc . ieWrappedName -- From haskell-ide-engine/src/Haskell/Ide/Engine/Support/HieExtras.hs safeTyThingType :: TyThing -> Maybe Type diff --git a/ghcide/src/Development/IDE/Spans/Documentation.hs b/ghcide/src/Development/IDE/Spans/Documentation.hs index ffa2a25c6e..ecff0a9a6a 100644 --- a/ghcide/src/Development/IDE/Spans/Documentation.hs +++ b/ghcide/src/Development/IDE/Spans/Documentation.hs @@ -32,6 +32,7 @@ import System.Directory import System.FilePath import Language.LSP.Types (filePathToUri, getUri) +import Development.IDE.GHC.Util (showGhc) mkDocMap :: HscEnv @@ -92,8 +93,8 @@ getDocumentationsTryGhc env mod names = do src <- toFileUriText $ lookupSrcHtmlForModule env mod return (doc, src) Nothing -> pure (Nothing, Nothing) - let docUri = (<> "#" <> selector <> showNameWithoutUniques name) <$> docFu - srcUri = (<> "#" <> showNameWithoutUniques name) <$> srcFu + let docUri = (<> "#" <> selector <> showGhc name) <$> docFu + srcUri = (<> "#" <> showGhc name) <$> srcFu selector | isValName name = "v:" | otherwise = "t:" diff --git a/ghcide/src/Development/IDE/Types/Exports.hs b/ghcide/src/Development/IDE/Types/Exports.hs index f66167a688..ba56a1f8f8 100644 --- a/ghcide/src/Development/IDE/Types/Exports.hs +++ b/ghcide/src/Development/IDE/Types/Exports.hs @@ -178,7 +178,7 @@ unpackAvail mn | otherwise = const [] where !mod = pack $ moduleNameString mn - f id@IdentInfo {..} = (pack (prettyPrint name), moduleNameText,[id]) + f id@IdentInfo {..} = (pack (occNameString name), moduleNameText,[id]) identInfoToKeyVal :: IdentInfo -> (ModuleNameText, IdentInfo) diff --git a/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs b/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs index 7de639c13c..b0d709a5d2 100644 --- a/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs +++ b/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs @@ -19,7 +19,7 @@ import Development.IDE.Core.RuleTypes (GetParsedModule (GetParsedModul import Development.IDE.Core.Service (IdeState, runAction) import Development.IDE.Core.Shake (use) import Development.IDE.GHC.Compat -import Development.IDE.GHC.Util (prettyPrint) +import Development.IDE.GHC.Util (showGhc) import Generics.SYB (extQ, something) import Ide.PluginUtils (getNormalizedFilePath, handleMaybeM, response) @@ -134,7 +134,7 @@ findSigLocOfStringDecl decls expectedType declName = something (const Nothing `e -- | Pretty Print the Type Signature (to validate GHC Error Message) sigToText :: Sig GhcPs -> Maybe Text sigToText = \case - ts@TypeSig {} -> Just $ stripSignature $ T.pack $ prettyPrint ts + ts@TypeSig {} -> Just $ stripSignature $ showGhc ts _ -> Nothing stripSignature :: Text -> Text diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index 3ed51b0e29..797bd5a187 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -82,6 +82,7 @@ import qualified GHC.LanguageExtensions.Type as LangExt (Extension (..)) import Development.IDE.Core.FileStore (setSomethingModified) import Development.IDE.Types.Shake (toKey) +import Development.IDE.GHC.Util (showGhc) import Ide.Plugin.Config (Config) #if MIN_VERSION_ghc(9,2,0) import GHC.Types.SrcLoc (UnhelpfulSpanReason (UnhelpfulInteractive)) @@ -97,7 +98,7 @@ import Ide.Plugin.Eval.Parse.Comments (commentsToSections) import Ide.Plugin.Eval.Parse.Option (parseSetFlags) import Ide.Plugin.Eval.Rules (queueForEvaluation) import Ide.Plugin.Eval.Types -import Ide.Plugin.Eval.Util (asS, gStrictTry, isLiterate, +import Ide.Plugin.Eval.Util (gStrictTry, isLiterate, logWith, response', timed) import Ide.PluginUtils (handleMaybe, handleMaybeM, response) @@ -282,7 +283,7 @@ runEvalCmd plId st EvalParams{..} = -- load the module in the interactive environment loadResult <- perf "loadModule" $ load LoadAllTargets - dbg "LOAD RESULT" $ asS loadResult + dbg "LOAD RESULT" $ showGhc loadResult case loadResult of Failed -> liftIO $ do let err = "" diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs index e5232759ce..e4b09f5d95 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs @@ -19,9 +19,10 @@ import Data.String (fromString) import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import qualified Development.IDE.GHC.Compat.Util as EnumSet +import Development.IDE.GHC.Util (showGhc) import GHC.LanguageExtensions.Type (Extension (..)) -import Ide.Plugin.Eval.Util (asS, gStrictTry) +import Ide.Plugin.Eval.Util (gStrictTry) {- $setup >>> import GHC @@ -66,7 +67,7 @@ pkgNames_ = mapMaybe ( \case ExposePackage _ (PackageArg n) _ -> Just n - ExposePackage _ (UnitIdArg uid) _ -> Just $ asS uid + ExposePackage _ (UnitIdArg uid) _ -> Just $ showGhc uid _ -> Nothing ) @@ -147,7 +148,7 @@ deriving instance Read Extension -- Partial display of DynFlags contents, for testing purposes showDynFlags :: DynFlags -> String showDynFlags df = - showSDocUnsafe . vcat . map (\(n, d) -> text (n ++ ": ") <+> d) $ + prettyPrint . vcat . map (\(n, d) -> text (n ++ ": ") <+> d) $ [ ("extensions", ppr . extensions $ df) , ("extensionFlags", ppr . EnumSet.toList . extensionFlags $ df) , ("importPaths", vList $ importPaths df) diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs index c33d6cbc68..c59ba02f91 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs @@ -4,7 +4,6 @@ -- |Debug utilities module Ide.Plugin.Eval.Util ( - asS, timed, isLiterate, response', @@ -20,8 +19,7 @@ import Data.String (IsString (fromString)) import qualified Data.Text as T import Development.IDE (IdeState, Priority (..), ideLogger, logPriority) -import Development.IDE.GHC.Compat (Outputable, ppr, - showSDocUnsafe) +import Development.IDE.GHC.Compat (Outputable, ppr) import Development.IDE.GHC.Compat.Util (MonadCatch, catch) import GHC.Exts (toList) import GHC.Stack (HasCallStack, callStack, @@ -33,9 +31,6 @@ import System.FilePath (takeExtension) import System.Time.Extra (duration, showDuration) import UnliftIO.Exception (catchAny) -asS :: Outputable a => a -> String -asS = showSDocUnsafe . ppr - timed :: MonadIO m => (t -> String -> m a) -> t -> m b -> m b timed out name op = do (secs, r) <- duration op diff --git a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs index a453a65a1e..e729acacb1 100644 --- a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs +++ b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs @@ -210,7 +210,7 @@ minimalImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \Minimal (imports, mbMinImports) <- liftIO $ extractMinimalImports hsc tmr let importsMap = Map.fromList - [ (realSrcSpanStart l, T.pack (prettyPrint i)) + [ (realSrcSpanStart l, showGhc i) | L (locA -> RealSrcSpan l _) i <- fromMaybe [] mbMinImports ] res = diff --git a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs index 8d3fdb2147..e181727fc5 100644 --- a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs +++ b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs @@ -42,7 +42,7 @@ import Development.IDE as D (Diagnostic (Diagnostic, Range (Range), Uri, getFileContents, getParsedModule, - prettyPrint, runAction, + showGhc, runAction, srcSpanToRange, toNormalizedUri, uriToFilePath', @@ -151,7 +151,7 @@ suggestAddPragma mDynflags Diagnostic {_message} = genPragma _message disabled | Just dynFlags <- mDynflags = -- GHC does not export 'OnOff', so we have to view it as string - catMaybes $ T.stripPrefix "Off " . T.pack . prettyPrint <$> extensions dynFlags + catMaybes $ T.stripPrefix "Off " . showGhc <$> extensions dynFlags | otherwise = -- When the module failed to parse, we don't have access to its -- dynFlags. In that case, simply don't disable any pragmas. diff --git a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs index 2519ce1366..019f0797ca 100644 --- a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs +++ b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs @@ -232,7 +232,7 @@ refineImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \RefineIm let res = [ (i, Just . T.intercalate "\n" - . map (T.pack . prettyPrint . constructImport i) + . map (showGhc . constructImport i) . Map.toList $ filteredInnerImports) -- for every minimal imports diff --git a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs index 4c2768255f..0776532ab3 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs @@ -19,7 +19,8 @@ import Control.DeepSeq import Control.Exception import Data.Either (fromRight) import qualified Debug.Trace -import Development.IDE.GHC.Compat (PlainGhcException, Outputable(..), SDoc, showSDocUnsafe) +import Development.IDE.GHC.Compat (PlainGhcException, Outputable(..), SDoc) +import Development.IDE.GHC.Util (prettyPrint) import System.IO.Unsafe (unsafePerformIO) ------------------------------------------------------------------------------ @@ -30,7 +31,7 @@ unsafeRender = unsafeRender' . ppr unsafeRender' :: SDoc -> String unsafeRender' sdoc = unsafePerformIO $ do - let z = showSDocUnsafe sdoc + let z = prettyPrint sdoc -- We might not have unsafeGlobalDynFlags (like during testing), in which -- case GHC panics. Instead of crashing, let's just fail to print. !res <- try @PlainGhcException $ evaluate $ deepseq z z From 22cf5f30a8252568a42250ebefec551a19bf125b Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sat, 16 Apr 2022 22:25:45 +0800 Subject: [PATCH 02/12] Fix dependency --- ghcide/src/Development/IDE/GHC/Compat/Outputable.hs | 3 ++- ghcide/src/Development/IDE/LSP/Outline.hs | 2 +- plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs index b45e0b91b0..4ef5346fee 100644 --- a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs +++ b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs @@ -4,6 +4,7 @@ module Development.IDE.GHC.Compat.Outputable ( SDoc, Outputable, showSDoc, + showSDocUnsafe, showSDocForUser, ppr, pprPanic, text, vcat, (<+>), ($$), empty, hang, nest, printSDocQualifiedUnsafe, @@ -80,7 +81,7 @@ printWithoutUniques = #else go . ppr where - go sdoc = oldRenderWithStyle dflags sdoc (mkUserStyle dflags neverQualify AllTheWay) + go sdoc = oldRenderWithStyle dflags sdoc (oldMkUserStyle dflags neverQualify AllTheWay) dflags = unsafeGlobalDynFlags `gopt_set` Opt_SuppressUniques #endif diff --git a/ghcide/src/Development/IDE/LSP/Outline.hs b/ghcide/src/Development/IDE/LSP/Outline.hs index eeffbad0e6..5da59a42a6 100644 --- a/ghcide/src/Development/IDE/LSP/Outline.hs +++ b/ghcide/src/Development/IDE/LSP/Outline.hs @@ -21,6 +21,7 @@ import Development.IDE.GHC.Compat import Development.IDE.GHC.Error (rangeToRealSrcSpan, realSrcSpanToRange) import Development.IDE.Types.Location +import Development.IDE.GHC.Util (showGhc) import Language.LSP.Server (LspM) import Language.LSP.Types (DocumentSymbol (..), DocumentSymbolParams (DocumentSymbolParams, _textDocument), @@ -31,7 +32,6 @@ import Language.LSP.Types (DocumentSymbol (..), type (|?) (InL), uriToFilePath) #if MIN_VERSION_ghc(9,2,0) import Data.List.NonEmpty (nonEmpty, toList) -import Development.IDE.GHC.Util (showGhc) #endif moduleOutline diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs index e4b09f5d95..ed8bc849ca 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs @@ -19,7 +19,7 @@ import Data.String (fromString) import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import qualified Development.IDE.GHC.Compat.Util as EnumSet -import Development.IDE.GHC.Util (showGhc) +import Development.IDE.GHC.Util (prettyPrint) import GHC.LanguageExtensions.Type (Extension (..)) import Ide.Plugin.Eval.Util (gStrictTry) @@ -67,7 +67,7 @@ pkgNames_ = mapMaybe ( \case ExposePackage _ (PackageArg n) _ -> Just n - ExposePackage _ (UnitIdArg uid) _ -> Just $ showGhc uid + ExposePackage _ (UnitIdArg uid) _ -> Just $ prettyPrint uid _ -> Nothing ) From c8f5fb869180830b8ee25abadc19c98fafcffbe4 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sat, 16 Apr 2022 22:34:19 +0800 Subject: [PATCH 03/12] Add missing instance --- ghcide/src/Development/IDE/GHC/Orphans.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ghcide/src/Development/IDE/GHC/Orphans.hs b/ghcide/src/Development/IDE/GHC/Orphans.hs index 4eae21c2a3..907c48ce99 100644 --- a/ghcide/src/Development/IDE/GHC/Orphans.hs +++ b/ghcide/src/Development/IDE/GHC/Orphans.hs @@ -209,3 +209,8 @@ instance (NFData (HsModule a)) where instance Show OccName where show = prettyPrint instance Hashable OccName where hashWithSalt s n = hashWithSalt s (getKey $ getUnique n) + +#if !MIN_VERSION_ghc(8,10,0) +instance Outputable SDoc where + ppr = id +#endif From e0efaeedb51050fcf700d953b554877ebaf56ab4 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sat, 16 Apr 2022 22:50:47 +0800 Subject: [PATCH 04/12] Add missing instance --- ghcide/src/Development/IDE/GHC/Orphans.hs | 5 ----- ghcide/src/Development/IDE/GHC/Util.hs | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ghcide/src/Development/IDE/GHC/Orphans.hs b/ghcide/src/Development/IDE/GHC/Orphans.hs index 907c48ce99..4eae21c2a3 100644 --- a/ghcide/src/Development/IDE/GHC/Orphans.hs +++ b/ghcide/src/Development/IDE/GHC/Orphans.hs @@ -209,8 +209,3 @@ instance (NFData (HsModule a)) where instance Show OccName where show = prettyPrint instance Hashable OccName where hashWithSalt s n = hashWithSalt s (getKey $ getUnique n) - -#if !MIN_VERSION_ghc(8,10,0) -instance Outputable SDoc where - ppr = id -#endif diff --git a/ghcide/src/Development/IDE/GHC/Util.hs b/ghcide/src/Development/IDE/GHC/Util.hs index c46a6bb00c..0bc6489aeb 100644 --- a/ghcide/src/Development/IDE/GHC/Util.hs +++ b/ghcide/src/Development/IDE/GHC/Util.hs @@ -314,6 +314,11 @@ traceAst lbl x #endif , "file://" ++ htmlDumpFileName] +#if !MIN_VERSION_ghc(8,10,0) +instance Outputable SDoc where + ppr = id +#endif + prettyPrintWithUniques :: Outputable a => a -> String prettyPrintWithUniques = showSDocUnsafe . ppr From 7b013f04dd6c1409cf6a984447902f5ceae85e71 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sat, 16 Apr 2022 23:28:38 +0800 Subject: [PATCH 05/12] Remove unused imports --- plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs index c59ba02f91..a4acb19caf 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Util.hs @@ -19,7 +19,6 @@ import Data.String (IsString (fromString)) import qualified Data.Text as T import Development.IDE (IdeState, Priority (..), ideLogger, logPriority) -import Development.IDE.GHC.Compat (Outputable, ppr) import Development.IDE.GHC.Compat.Util (MonadCatch, catch) import GHC.Exts (toList) import GHC.Stack (HasCallStack, callStack, From 7768538478d03788a8c2515e1ed11a06f3765dc1 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Mon, 18 Apr 2022 18:35:33 +0800 Subject: [PATCH 06/12] Clean up unused code --- .../Development/IDE/GHC/Compat/Outputable.hs | 19 +----------- ghcide/src/Development/IDE/GHC/Util.hs | 29 +++++++++++++++++-- .../src/Development/IDE/Plugin/CodeAction.hs | 4 +-- ghcide/src/Development/IDE/Spans/Common.hs | 9 ------ .../Development/IDE/Spans/Documentation.hs | 2 +- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs index 4ef5346fee..c44364dba4 100644 --- a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs +++ b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs @@ -8,9 +8,7 @@ module Development.IDE.GHC.Compat.Outputable ( showSDocForUser, ppr, pprPanic, text, vcat, (<+>), ($$), empty, hang, nest, printSDocQualifiedUnsafe, - printNameWithoutUniques, printWithoutUniques, - printSDocAllTheWay, mkPrintUnqualified, mkPrintUnqualifiedDefault, PrintUnqualified(..), @@ -85,16 +83,6 @@ printWithoutUniques = dflags = unsafeGlobalDynFlags `gopt_set` Opt_SuppressUniques #endif -printNameWithoutUniques :: Outputable a => a -> String -printNameWithoutUniques = -#if MIN_VERSION_ghc(9,2,0) - renderWithContext (defaultSDocContext { sdocSuppressUniques = True }) . ppr -#else - printSDocAllTheWay dyn . ppr - where - dyn = unsafeGlobalDynFlags `gopt_set` Opt_SuppressUniques -#endif - printSDocQualifiedUnsafe :: PrintUnqualified -> SDoc -> String #if MIN_VERSION_ghc(9,2,0) printSDocQualifiedUnsafe unqual doc = @@ -108,14 +96,9 @@ printSDocQualifiedUnsafe unqual doc = showSDocForUser unsafeGlobalDynFlags unqual doc #endif -printSDocAllTheWay :: DynFlags -> SDoc -> String + #if MIN_VERSION_ghc(9,2,0) -printSDocAllTheWay dflags sdoc = renderWithContext ctxt sdoc - where - ctxt = initSDocContext dflags (mkUserStyle neverQualify AllTheWay) #else -printSDocAllTheWay dflags sdoc = oldRenderWithStyle dflags sdoc (oldMkUserStyle dflags Out.neverQualify Out.AllTheWay) - #if MIN_VERSION_ghc(9,0,0) oldRenderWithStyle dflags sdoc sty = Out.renderWithStyle (initSDocContext dflags sty) sdoc oldMkUserStyle _ = Out.mkUserStyle diff --git a/ghcide/src/Development/IDE/GHC/Util.hs b/ghcide/src/Development/IDE/GHC/Util.hs index 0bc6489aeb..095e91c467 100644 --- a/ghcide/src/Development/IDE/GHC/Util.hs +++ b/ghcide/src/Development/IDE/GHC/Util.hs @@ -7,7 +7,6 @@ module Development.IDE.GHC.Util( modifyDynFlags, evalGhcEnv, -- * GHC wrappers - prettyPrint, printRdrName, Development.IDE.GHC.Util.printName, ParseResult(..), runParser, @@ -30,6 +29,7 @@ module Development.IDE.GHC.Util( traceAst, showGhc, showGhcWithUniques, + prettyPrint, prettyPrintWithUniques ) where @@ -314,20 +314,45 @@ traceAst lbl x #endif , "file://" ++ htmlDumpFileName] +-- Should in `Development.IDE.GHC.Orphans`, +-- leave it here to prevent cyclic module dependency #if !MIN_VERSION_ghc(8,10,0) instance Outputable SDoc where ppr = id #endif +-- | Print a GHC value by default `showSDocUnsafe`. +-- +-- You may prefer `prettyPrint` unless you know what you are doing. +-- +-- It internal using `unsafeGlobalDynFlags`. +-- +-- `String` version of `showGhcWithUniques`. prettyPrintWithUniques :: Outputable a => a -> String prettyPrintWithUniques = showSDocUnsafe . ppr --- | Pretty print a GHC value using 'unsafeGlobalDynFlags '. +-- | Print a GHC value in `defaultUserStyle` without unique symbols. +-- +-- This is the most common print utility, will print with a user friendly style like: `a_a4ME` as `a`. +-- +-- It internal using `unsafeGlobalDynFlags`. +-- +-- `String` version of `showGhc`. prettyPrint :: Outputable a => a -> String prettyPrint = printWithoutUniques +-- | Print a GHC value by default `showSDocUnsafe`. +-- +-- You may prefer `showGhc` unless you know what you are doing. +-- +-- It internal using `unsafeGlobalDynFlags`. showGhcWithUniques :: Outputable a => a -> T.Text showGhcWithUniques = T.pack . showSDocUnsafe . ppr +-- | Print a GHC value in `defaultUserStyle` without unique symbols. +-- +-- This is the most common print utility, will print with a user friendly style like: `a_a4ME` as `a`. +-- +-- It internal using `unsafeGlobalDynFlags`. showGhc :: Outputable a => a -> T.Text showGhc = T.pack . printWithoutUniques diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction.hs b/ghcide/src/Development/IDE/Plugin/CodeAction.hs index af7902c610..e35896a8cd 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction.hs @@ -50,12 +50,12 @@ import Development.IDE.GHC.Error import Development.IDE.GHC.ExactPrint import Development.IDE.GHC.Util (prettyPrint, printRdrName, - traceAst, showGhc) + traceAst, + showGhc) import Development.IDE.Plugin.CodeAction.Args import Development.IDE.Plugin.CodeAction.ExactPrint import Development.IDE.Plugin.CodeAction.PositionIndexed import Development.IDE.Plugin.TypeLenses (suggestSignature) -import Development.IDE.Spans.Common import Development.IDE.Types.Exports import Development.IDE.Types.Location import Development.IDE.Types.Options diff --git a/ghcide/src/Development/IDE/Spans/Common.hs b/ghcide/src/Development/IDE/Spans/Common.hs index eeb6811af7..746fd27e20 100644 --- a/ghcide/src/Development/IDE/Spans/Common.hs +++ b/ghcide/src/Development/IDE/Spans/Common.hs @@ -32,15 +32,6 @@ import qualified Documentation.Haddock.Types as H type DocMap = NameEnv SpanDoc type KindMap = NameEnv TyThing --- showGhc :: Outputable a => a -> T.Text --- showGhc = showSD . withPprStyle defaultUserStyle . ppr - --- showSD :: SDoc -> T.Text --- showSD = T.pack . unsafePrintSDoc - --- showNameWithoutUniques :: Outputable a => a -> T.Text --- showNameWithoutUniques = T.pack . printNameWithoutUniques - -- | Shows IEWrappedName, without any modifier, qualifier or unique identifier. unqualIEWrapName :: IEWrappedName RdrName -> T.Text unqualIEWrapName = showGhc . rdrNameOcc . ieWrappedName diff --git a/ghcide/src/Development/IDE/Spans/Documentation.hs b/ghcide/src/Development/IDE/Spans/Documentation.hs index ecff0a9a6a..83b011b42c 100644 --- a/ghcide/src/Development/IDE/Spans/Documentation.hs +++ b/ghcide/src/Development/IDE/Spans/Documentation.hs @@ -27,12 +27,12 @@ import Development.IDE.Core.RuleTypes import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import Development.IDE.GHC.Error +import Development.IDE.GHC.Util (showGhc) import Development.IDE.Spans.Common import System.Directory import System.FilePath import Language.LSP.Types (filePathToUri, getUri) -import Development.IDE.GHC.Util (showGhc) mkDocMap :: HscEnv From 02a516edbf785a57f172d5c7c89deb8e1e060c22 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Wed, 20 Apr 2022 15:25:06 +0800 Subject: [PATCH 07/12] Remove unnecessary exports & Rename --- ghcide/src/Development/IDE/Core/Compile.hs | 2 +- .../Development/IDE/GHC/Compat/Outputable.hs | 13 +++-- ghcide/src/Development/IDE/GHC/Orphans.hs | 22 ++++---- ghcide/src/Development/IDE/GHC/Util.hs | 50 +++++++------------ ghcide/src/Development/IDE/LSP/Outline.hs | 50 +++++++++---------- .../src/Development/IDE/Plugin/CodeAction.hs | 36 ++++++------- .../IDE/Plugin/CodeAction/ExactPrint.hs | 10 ++-- .../src/Development/IDE/Plugin/Completions.hs | 4 +- .../IDE/Plugin/Completions/Logic.hs | 22 ++++---- ghcide/src/Development/IDE/Spans/AtPoint.hs | 16 +++--- ghcide/src/Development/IDE/Spans/Common.hs | 2 +- .../Development/IDE/Spans/Documentation.hs | 6 +-- .../src/Ide/Plugin/ChangeTypeSignature.hs | 4 +- .../src/Ide/Plugin/Eval/CodeLens.hs | 8 +-- .../src/Ide/Plugin/Eval/GHC.hs | 6 +-- .../src/Ide/Plugin/ExplicitImports.hs | 4 +- .../src/Ide/Plugin/Pragmas.hs | 4 +- .../src/Ide/Plugin/RefineImports.hs | 4 +- .../src/Ide/Plugin/Retrie.hs | 8 +-- .../hls-tactics-plugin/src/Wingman/Debug.hs | 4 +- 20 files changed, 127 insertions(+), 148 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/Compile.hs b/ghcide/src/Development/IDE/Core/Compile.hs index 99938bd430..adc3a6385a 100644 --- a/ghcide/src/Development/IDE/Core/Compile.hs +++ b/ghcide/src/Development/IDE/Core/Compile.hs @@ -1301,7 +1301,7 @@ getDocsBatch hsc_env _mod _names = do #endif Map.findWithDefault mempty name amap)) case res of - Just x -> return $ map (first $ T.unpack . showGhc) x + Just x -> return $ map (first $ T.unpack . printOutputableText) x Nothing -> throwErrors #if MIN_VERSION_ghc(9,2,0) $ Error.getErrorMessages msgs diff --git a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs index c44364dba4..35521463f2 100644 --- a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs +++ b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs @@ -67,6 +67,10 @@ import qualified Outputable as Out import SrcLoc #endif +-- | A compatible function to print `Outputable` instances +-- without unique symbols. +-- +-- It print with a user-friendly style like: `a_a4ME` as `a`. printWithoutUniques :: Outputable a => a -> String printWithoutUniques = #if MIN_VERSION_ghc(9,2,0) @@ -96,10 +100,7 @@ printSDocQualifiedUnsafe unqual doc = showSDocForUser unsafeGlobalDynFlags unqual doc #endif - -#if MIN_VERSION_ghc(9,2,0) -#else -#if MIN_VERSION_ghc(9,0,0) +#if MIN_VERSION_ghc(9,0,0) && !MIN_VERSION_ghc(9,2,0) oldRenderWithStyle dflags sdoc sty = Out.renderWithStyle (initSDocContext dflags sty) sdoc oldMkUserStyle _ = Out.mkUserStyle oldMkErrStyle _ = Out.mkErrStyle @@ -107,8 +108,7 @@ oldMkErrStyle _ = Out.mkErrStyle oldFormatErrDoc :: DynFlags -> Err.ErrDoc -> Out.SDoc oldFormatErrDoc dflags = Err.formatErrDoc dummySDocContext where dummySDocContext = initSDocContext dflags Out.defaultUserStyle - -#else +#elif !MIN_VERSION_ghc(9,2,0) oldRenderWithStyle :: DynFlags -> Out.SDoc -> Out.PprStyle -> String oldRenderWithStyle = Out.renderWithStyle @@ -121,7 +121,6 @@ oldMkErrStyle = Out.mkErrStyle oldFormatErrDoc :: DynFlags -> Err.ErrDoc -> Out.SDoc oldFormatErrDoc = Err.formatErrDoc #endif -#endif pprWarning :: PsWarning -> MsgEnvelope DecoratedSDoc pprWarning = diff --git a/ghcide/src/Development/IDE/GHC/Orphans.hs b/ghcide/src/Development/IDE/GHC/Orphans.hs index 4eae21c2a3..7bc5ef2fde 100644 --- a/ghcide/src/Development/IDE/GHC/Orphans.hs +++ b/ghcide/src/Development/IDE/GHC/Orphans.hs @@ -46,27 +46,27 @@ import ByteCodeTypes #endif -- Orphan instances for types from the GHC API. -instance Show CoreModule where show = prettyPrint +instance Show CoreModule where show = printOutputable instance NFData CoreModule where rnf = rwhnf -instance Show CgGuts where show = prettyPrint . cg_module +instance Show CgGuts where show = printOutputable . cg_module instance NFData CgGuts where rnf = rwhnf instance Show ModDetails where show = const "" instance NFData ModDetails where rnf = rwhnf instance NFData SafeHaskellMode where rnf = rwhnf -instance Show Linkable where show = prettyPrint +instance Show Linkable where show = printOutputable instance NFData Linkable where rnf (LM a b c) = rnf a `seq` rnf b `seq` rnf c instance NFData Unlinked where rnf (DotO f) = rnf f rnf (DotA f) = rnf f rnf (DotDLL f) = rnf f rnf (BCOs a b) = seqCompiledByteCode a `seq` liftRnf rwhnf b -instance Show PackageFlag where show = prettyPrint -instance Show InteractiveImport where show = prettyPrint -instance Show PackageName where show = prettyPrint +instance Show PackageFlag where show = printOutputable +instance Show InteractiveImport where show = printOutputable +instance Show PackageName where show = printOutputable #if !MIN_VERSION_ghc(9,0,1) -instance Show ComponentId where show = prettyPrint -instance Show SourcePackageId where show = prettyPrint +instance Show ComponentId where show = printOutputable +instance Show SourcePackageId where show = printOutputable instance Show GhcPlugins.InstalledUnitId where show = installedUnitIdString @@ -76,7 +76,7 @@ instance NFData GhcPlugins.InstalledUnitId where rnf = rwhnf . installedUnitIdFS instance Hashable GhcPlugins.InstalledUnitId where hashWithSalt salt = hashWithSalt salt . installedUnitIdString #else -instance Show UnitId where show = prettyPrint +instance Show UnitId where show = printOutputable deriving instance Ord SrcSpan deriving instance Ord UnhelpfulSpanReason #endif @@ -86,7 +86,7 @@ instance NFData SB.StringBuffer where rnf = rwhnf instance Show Module where show = moduleNameString . moduleName -instance Outputable a => Show (GenLocated SrcSpan a) where show = prettyPrint +instance Outputable a => Show (GenLocated SrcSpan a) where show = printOutputable instance (NFData l, NFData e) => NFData (GenLocated l e) where rnf (L l e) = rnf l `seq` rnf e @@ -207,5 +207,5 @@ instance (NFData (HsModule a)) where #endif rnf = rwhnf -instance Show OccName where show = prettyPrint +instance Show OccName where show = printOutputable instance Hashable OccName where hashWithSalt s n = hashWithSalt s (getKey $ getUnique n) diff --git a/ghcide/src/Development/IDE/GHC/Util.hs b/ghcide/src/Development/IDE/GHC/Util.hs index 095e91c467..6d27936ec1 100644 --- a/ghcide/src/Development/IDE/GHC/Util.hs +++ b/ghcide/src/Development/IDE/GHC/Util.hs @@ -27,10 +27,8 @@ module Development.IDE.GHC.Util( dontWriteHieFiles, disableWarningsAsErrors, traceAst, - showGhc, - showGhcWithUniques, - prettyPrint, - prettyPrintWithUniques + printOutputable, + printOutputableText ) where #if MIN_VERSION_ghc(9,2,0) @@ -135,7 +133,7 @@ bytestringToStringBuffer (PS buf cur len) = StringBuffer{..} -- | Pretty print a 'RdrName' wrapping operators in parens printRdrName :: RdrName -> String -printRdrName name = prettyPrint $ parenSymOcc rn (ppr rn) +printRdrName name = printOutputable $ parenSymOcc rn (ppr rn) where rn = rdrNameOcc name @@ -300,7 +298,7 @@ traceAst lbl x #if MIN_VERSION_ghc(9,2,0) renderDump = renderWithContext defaultSDocContext{sdocStyle = defaultDumpStyle, sdocPprDebug = True} #else - renderDump = prettyPrintWithUniques + renderDump = showSDocUnsafe . ppr #endif htmlDump = showAstDataHtml x doTrace = unsafePerformIO $ do @@ -321,38 +319,24 @@ instance Outputable SDoc where ppr = id #endif --- | Print a GHC value by default `showSDocUnsafe`. --- --- You may prefer `prettyPrint` unless you know what you are doing. --- --- It internal using `unsafeGlobalDynFlags`. --- --- `String` version of `showGhcWithUniques`. -prettyPrintWithUniques :: Outputable a => a -> String -prettyPrintWithUniques = showSDocUnsafe . ppr - -- | Print a GHC value in `defaultUserStyle` without unique symbols. -- --- This is the most common print utility, will print with a user friendly style like: `a_a4ME` as `a`. +-- This is the most common print utility, will print with a user-friendly style like: `a_a4ME` as `a`. -- --- It internal using `unsafeGlobalDynFlags`. +-- It internal using `showSDocUnsafe` with `unsafeGlobalDynFlags`. -- --- `String` version of `showGhc`. -prettyPrint :: Outputable a => a -> String -prettyPrint = printWithoutUniques - --- | Print a GHC value by default `showSDocUnsafe`. --- --- You may prefer `showGhc` unless you know what you are doing. --- --- It internal using `unsafeGlobalDynFlags`. -showGhcWithUniques :: Outputable a => a -> T.Text -showGhcWithUniques = T.pack . showSDocUnsafe . ppr +-- You may prefer `printOutputableText` if `Text` is expected to return. +printOutputable :: Outputable a => a -> String +printOutputable = printWithoutUniques +{-# INLINE printOutputable #-} -- | Print a GHC value in `defaultUserStyle` without unique symbols. -- --- This is the most common print utility, will print with a user friendly style like: `a_a4ME` as `a`. +-- This is the most common print utility, will print with a user-friendly style like: `a_a4ME` as `a`. +-- +-- It internal using `showSDocUnsafe` with `unsafeGlobalDynFlags`. -- --- It internal using `unsafeGlobalDynFlags`. -showGhc :: Outputable a => a -> T.Text -showGhc = T.pack . printWithoutUniques +-- You may prefer `printOutputable` if `String` is expected to return. +printOutputableText :: Outputable a => a -> T.Text +printOutputableText = T.pack . printOutputable +{-# INLINE printOutputableText #-} diff --git a/ghcide/src/Development/IDE/LSP/Outline.hs b/ghcide/src/Development/IDE/LSP/Outline.hs index 5da59a42a6..5c52b044c7 100644 --- a/ghcide/src/Development/IDE/LSP/Outline.hs +++ b/ghcide/src/Development/IDE/LSP/Outline.hs @@ -13,7 +13,6 @@ import Control.Monad.IO.Class import Data.Functor import Data.Generics import Data.Maybe -import Data.Text (Text) import qualified Data.Text as T import Development.IDE.Core.Rules import Development.IDE.Core.Shake @@ -21,7 +20,7 @@ import Development.IDE.GHC.Compat import Development.IDE.GHC.Error (rangeToRealSrcSpan, realSrcSpanToRange) import Development.IDE.Types.Location -import Development.IDE.GHC.Util (showGhc) +import Development.IDE.GHC.Util (printOutputableText) import Language.LSP.Server (LspM) import Language.LSP.Types (DocumentSymbol (..), DocumentSymbolParams (DocumentSymbolParams, _textDocument), @@ -48,7 +47,7 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif moduleSymbol = hsmodName >>= \case (L (locA -> (RealSrcSpan l _)) m) -> Just $ (defDocumentSymbol l :: DocumentSymbol) - { _name = showGhc m + { _name = printOutputableText m , _kind = SkFile , _range = Range (Position 0 0) (Position maxBound 0) -- _ltop is 0 0 0 0 } @@ -71,18 +70,18 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif documentSymbolForDecl :: LHsDecl GhcPs -> Maybe DocumentSymbol documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ FamDecl { tcdFam = FamilyDecl { fdLName = L _ n, fdInfo, fdTyVars } })) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName n - <> (case showGhc fdTyVars of + { _name = printOutputableText n + <> (case printOutputableText fdTyVars of "" -> "" t -> " " <> t ) - , _detail = Just $ showGhc fdInfo + , _detail = Just $ printOutputableText fdInfo , _kind = SkFunction } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ ClassDecl { tcdLName = L _ name, tcdSigs, tcdTyVars })) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName name - <> (case showGhc tcdTyVars of + { _name = printOutputableText name + <> (case printOutputableText tcdTyVars of "" -> "" t -> " " <> t ) @@ -91,7 +90,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ ClassDecl { tcdLNa , _children = Just $ List [ (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName n + { _name = printOutputableText n , _kind = SkMethod , _selectionRange = realSrcSpanToRange l' } @@ -101,12 +100,12 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ ClassDecl { tcdLNa } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLName = L _ name, tcdDataDefn = HsDataDefn { dd_cons } })) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName name + { _name = printOutputableText name , _kind = SkStruct , _children = Just $ List [ (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName n + { _name = printOutputableText n , _kind = SkConstructor , _selectionRange = realSrcSpanToRange l' #if MIN_VERSION_ghc(9,2,0) @@ -124,7 +123,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLNam where cvtFld :: LFieldOcc GhcPs -> Maybe DocumentSymbol cvtFld (L (RealSrcSpan l _) n) = Just $ (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName (unLoc (rdrNameFieldOcc n)) + { _name = printOutputableText (unLoc (rdrNameFieldOcc n)) , _kind = SkField } cvtFld _ = Nothing @@ -139,7 +138,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLNam -- | Extract the record fields of a constructor conArgRecordFields (RecCon (L _ lcdfs)) = Just $ List [ (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName n + { _name = printOutputableText n , _kind = SkField } | L _ cdf <- lcdfs @@ -148,12 +147,12 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLNam conArgRecordFields _ = Nothing #endif documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ SynDecl { tcdLName = L (locA -> (RealSrcSpan l' _)) n })) = Just - (defDocumentSymbol l :: DocumentSymbol) { _name = showRdrName n + (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputableText n , _kind = SkTypeParameter , _selectionRange = realSrcSpanToRange l' } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (InstD _ ClsInstD { cid_inst = ClsInstDecl { cid_poly_ty } })) - = Just (defDocumentSymbol l :: DocumentSymbol) { _name = showGhc cid_poly_ty + = Just (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputableText cid_poly_ty , _kind = SkInterface } #if MIN_VERSION_ghc(9,2,0) @@ -162,8 +161,8 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (InstD _ DataFamInstD { dfi documentSymbolForDecl (L (RealSrcSpan l _) (InstD _ DataFamInstD { dfid_inst = DataFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } })) #endif = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName (unLoc feqn_tycon) <> " " <> T.unwords - (map showGhc feqn_pats) + { _name = printOutputableText (unLoc feqn_tycon) <> " " <> T.unwords + (map printOutputableText feqn_pats) , _kind = SkInterface } #if MIN_VERSION_ghc(9,2,0) @@ -172,24 +171,24 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (InstD _ TyFamInstD { tfid_ documentSymbolForDecl (L (RealSrcSpan l _) (InstD _ TyFamInstD { tfid_inst = TyFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } })) #endif = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName (unLoc feqn_tycon) <> " " <> T.unwords - (map showGhc feqn_pats) + { _name = printOutputableText (unLoc feqn_tycon) <> " " <> T.unwords + (map printOutputableText feqn_pats) , _kind = SkInterface } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (DerivD _ DerivDecl { deriv_type })) = gfindtype deriv_type <&> \(L (_ :: SrcSpan) name) -> - (defDocumentSymbol l :: DocumentSymbol) { _name = showGhc @(HsType GhcPs) + (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputableText @(HsType GhcPs) name , _kind = SkInterface } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (ValD _ FunBind{fun_id = L _ name})) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = showRdrName name + { _name = printOutputableText name , _kind = SkFunction } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (ValD _ PatBind{pat_lhs})) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = showGhc pat_lhs + { _name = printOutputableText pat_lhs , _kind = SkFunction } @@ -205,7 +204,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (ForD _ x)) = Just ForeignExport{} -> Just "export" XForeignDecl{} -> Nothing } - where name = showRdrName $ unLoc $ fd_name x + where name = printOutputableText $ unLoc $ fd_name x documentSymbolForDecl _ = Nothing @@ -229,7 +228,7 @@ documentSymbolForImportSummary importSymbols = documentSymbolForImport :: LImportDecl GhcPs -> Maybe DocumentSymbol documentSymbolForImport (L (locA -> (RealSrcSpan l _)) ImportDecl { ideclName, ideclQualified }) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = "import " <> showGhc ideclName + { _name = "import " <> printOutputableText ideclName , _kind = SkModule #if MIN_VERSION_ghc(8,10,0) , _detail = case ideclQualified of { NotQualified -> Nothing; _ -> Just "qualified" } @@ -250,9 +249,6 @@ defDocumentSymbol l = DocumentSymbol { .. } where _children = Nothing _tags = Nothing -showRdrName :: RdrName -> Text -showRdrName = showGhc - -- the version of getConNames for ghc9 is restricted to only the renaming phase #if !MIN_VERSION_ghc(9,2,0) getConNames' :: ConDecl GhcPs -> [Located (IdP GhcPs)] diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction.hs b/ghcide/src/Development/IDE/Plugin/CodeAction.hs index e35896a8cd..1df313cec8 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction.hs @@ -48,10 +48,10 @@ import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import Development.IDE.GHC.Error import Development.IDE.GHC.ExactPrint -import Development.IDE.GHC.Util (prettyPrint, +import Development.IDE.GHC.Util (printOutputable, printRdrName, traceAst, - showGhc) + printOutputableText) import Development.IDE.Plugin.CodeAction.Args import Development.IDE.Plugin.CodeAction.ExactPrint import Development.IDE.Plugin.CodeAction.PositionIndexed @@ -545,7 +545,7 @@ suggestDeleteUnusedBinding isTheBinding span = srcSpanToRange span == Just _range isSameName :: IdP GhcPs -> String -> Bool - isSameName x name = prettyPrint x == name + isSameName x name = printOutputable x == name data ExportsAs = ExportName | ExportPattern | ExportFamily | ExportAll deriving (Eq) @@ -1012,7 +1012,7 @@ occursUnqualified symbol ImportDecl{..} occursUnqualified _ _ = False symbolOccursIn :: T.Text -> IE GhcPs -> Bool -symbolOccursIn symb = any ((== symb). showGhc) . ieNames +symbolOccursIn symb = any ((== symb). printOutputableText) . ieNames targetModuleName :: ModuleTarget -> ModuleName targetModuleName ImplicitPrelude{} = mkModuleName "Prelude" @@ -1046,12 +1046,12 @@ disambiguateSymbol pm fileContents Diagnostic {..} (T.unpack -> symbol) = \case in Right <$> [ if parensed then Rewrite (rangeToSrcSpan "" _range) $ \df -> liftParseAST @(HsExpr GhcPs) df $ - prettyPrint $ + printOutputable $ HsVar @GhcPs noExtField $ reLocA $ L (mkGeneralSrcSpan "") rdr else Rewrite (rangeToSrcSpan "" _range) $ \df -> liftParseAST @RdrName df $ - prettyPrint $ L (mkGeneralSrcSpan "") rdr + printOutputable $ L (mkGeneralSrcSpan "") rdr ] findImportDeclByRange :: [LImportDecl GhcPs] -> Range -> Maybe (LImportDecl GhcPs) findImportDeclByRange xs range = find (\(L (locA -> l) _)-> srcSpanToRange l == Just range) xs @@ -1422,7 +1422,7 @@ newImport modName mSymbol mQual hiding = NewImport impStmt symImp | Just symbol <- mSymbol , symOcc <- mkVarOcc $ T.unpack symbol = - " (" <> showGhc (parenSymOcc symOcc $ ppr symOcc) <> ")" + " (" <> printOutputableText (parenSymOcc symOcc $ ppr symOcc) <> ")" | otherwise = "" impStmt = "import " @@ -1616,32 +1616,32 @@ smallerRangesForBindingExport lies b = b' = wrapOperatorInParens . unqualify $ b #if !MIN_VERSION_ghc(9,2,0) ranges' (L _ (IEThingWith _ thing _ inners labels)) - | prettyPrint thing == b' = [] + | printOutputable thing == b' = [] | otherwise = - [ locA l' | L l' x <- inners, prettyPrint x == b'] - ++ [ l' | L l' x <- labels, prettyPrint x == b'] + [ locA l' | L l' x <- inners, printOutputable x == b'] + ++ [ l' | L l' x <- labels, printOutputable x == b'] #else ranges' (L _ (IEThingWith _ thing _ inners)) - | prettyPrint thing == b' = [] + | printOutputable thing == b' = [] | otherwise = - [ locA l' | L l' x <- inners, prettyPrint x == b'] + [ locA l' | L l' x <- inners, printOutputable x == b'] #endif ranges' _ = [] rangesForBinding' :: String -> LIE GhcPs -> [SrcSpan] -rangesForBinding' b (L (locA -> l) x@IEVar{}) | prettyPrint x == b = [l] -rangesForBinding' b (L (locA -> l) x@IEThingAbs{}) | prettyPrint x == b = [l] -rangesForBinding' b (L (locA -> l) (IEThingAll _ x)) | prettyPrint x == b = [l] +rangesForBinding' b (L (locA -> l) x@IEVar{}) | printOutputable x == b = [l] +rangesForBinding' b (L (locA -> l) x@IEThingAbs{}) | printOutputable x == b = [l] +rangesForBinding' b (L (locA -> l) (IEThingAll _ x)) | printOutputable x == b = [l] #if !MIN_VERSION_ghc(9,2,0) rangesForBinding' b (L l (IEThingWith _ thing _ inners labels)) #else rangesForBinding' b (L (locA -> l) (IEThingWith _ thing _ inners)) #endif - | prettyPrint thing == b = [l] + | printOutputable thing == b = [l] | otherwise = - [ locA l' | L l' x <- inners, prettyPrint x == b] + [ locA l' | L l' x <- inners, printOutputable x == b] #if !MIN_VERSION_ghc(9,2,0) - ++ [ l' | L l' x <- labels, prettyPrint x == b] + ++ [ l' | L l' x <- labels, printOutputable x == b] #endif rangesForBinding' _ _ = [] diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs index 6e87a55fbf..abdcfd67bd 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs @@ -355,8 +355,8 @@ extendImportTopLevel thing (L l it@ImportDecl{..}) top <- uniqueSrcSpanT let rdr = reLocA $ L src $ mkRdrUnqual $ mkVarOcc thing let alreadyImported = - showGhc (occName (unLoc rdr)) - `elem` map (showGhc @OccName) (listify (const True) lies) + printOutputableText (occName (unLoc rdr)) + `elem` map (printOutputableText @OccName) (listify (const True) lies) when alreadyImported $ lift (Left $ thing <> " already imported") @@ -456,8 +456,8 @@ extendImportViaParent df parent child (L l it@ImportDecl{..}) childRdr <- pure $ setEntryDP childRdr $ SameLine $ if hasSibling then 1 else 0 #endif let alreadyImported = - showGhc (occName (unLoc childRdr)) - `elem` map (showGhc @OccName) (listify (const True) lies') + printOutputableText (occName (unLoc childRdr)) + `elem` map (printOutputableText @OccName) (listify (const True) lies') when alreadyImported $ lift (Left $ child <> " already included in " <> parent <> " imports") @@ -542,7 +542,7 @@ addCommaInImportList lies x = do #endif unIEWrappedName :: IEWrappedName (IdP GhcPs) -> String -unIEWrappedName (occName -> occ) = prettyPrint $ parenSymOcc occ (ppr occ) +unIEWrappedName (occName -> occ) = printOutputable $ parenSymOcc occ (ppr occ) hasParen :: String -> Bool hasParen ('(' : _) = True diff --git a/ghcide/src/Development/IDE/Plugin/Completions.hs b/ghcide/src/Development/IDE/Plugin/Completions.hs index 6e37b99a77..43f3a28886 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions.hs @@ -27,7 +27,7 @@ import qualified Development.IDE.Core.Shake as Shake import Development.IDE.GHC.Compat import Development.IDE.GHC.Error (rangeToSrcSpan) import Development.IDE.GHC.ExactPrint (GetAnnotatedParsedSource (GetAnnotatedParsedSource)) -import Development.IDE.GHC.Util (showGhc) +import Development.IDE.GHC.Util (printOutputableText) import Development.IDE.Graph import Development.IDE.Plugin.CodeAction (newImport, newImportToEdit) @@ -213,7 +213,7 @@ extendImportHandler ideState edit@ExtendImport {..} = do <> "’ from " <> importName <> " (at " - <> showGhc srcSpan + <> printOutputableText srcSpan <> ")" void $ LSP.sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wedit) (\_ -> pure ()) return $ Right Null diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index b383bee6f8..dfda9c336b 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -214,7 +214,7 @@ mkCompl pprLineCol :: SrcLoc -> T.Text pprLineCol (UnhelpfulLoc fs) = T.pack $ unpackFS fs pprLineCol (RealSrcLoc loc _) = - "line " <> showGhc (srcLocLine loc) <> ", column " <> showGhc (srcLocCol loc) + "line " <> printOutputableText (srcLocLine loc) <> ", column " <> printOutputableText (srcLocCol loc) mkAdditionalEditsCommand :: PluginId -> ExtendImport -> Command @@ -226,7 +226,7 @@ mkNameCompItem doc thingParent origName provenance thingType isInfix docs !imp = where compKind = occNameToComKind typeText origName isTypeCompl = isTcOcc origName - label = stripPrefix $ showGhc origName + label = stripPrefix $ printOutputableText origName insertText = case isInfix of Nothing -> case getArgText <$> thingType of Nothing -> label @@ -235,7 +235,7 @@ mkNameCompItem doc thingParent origName provenance thingType isInfix docs !imp = Just Surrounded -> label typeText - | Just t <- thingType = Just . stripForall $ showGhc t + | Just t <- thingType = Just . stripForall $ printOutputableText t | otherwise = Nothing additionalTextEdits = imp <&> \x -> @@ -244,7 +244,7 @@ mkNameCompItem doc thingParent origName provenance thingType isInfix docs !imp = thingParent, importName = showModName $ unLoc $ ideclName $ unLoc x, importQual = getImportQual x, - newThing = showGhc origName + newThing = printOutputableText origName } stripForall :: T.Text -> T.Text @@ -295,7 +295,7 @@ showForSnippet x = T.pack $ renderWithContext ctxt $ GHC.ppr x -- FIXme where ctxt = defaultSDocContext{sdocStyle = mkUserStyle neverQualify AllTheWay} #else -showForSnippet x = showGhc x +showForSnippet x = printOutputableText x #endif mkModCompl :: T.Text -> CompletionItem @@ -350,7 +350,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do let packageState = hscEnv env curModName = moduleName curMod - curModNameText = showGhc curModName + curModNameText = printOutputableText curModName importMap = Map.fromList [ (l, imp) | imp@(L (locA -> (RealSrcSpan l _)) _) <- limports ] @@ -386,7 +386,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do -- or if it doesn't have a real location loc <- realSpan $ is_dloc spec Map.lookup loc importMap - compItem <- toCompItem par curMod (showGhc $ is_mod spec) n originalImportDecl + compItem <- toCompItem par curMod (printOutputableText $ is_mod spec) n originalImportDecl let unqual | is_qual spec = [] | otherwise = compItem @@ -498,12 +498,12 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod findRecordCompl :: Uri -> ParsedModule -> Provenance -> TyClDecl GhcPs -> [CompItem] findRecordCompl uri pmod mn DataDecl {tcdLName, tcdDataDefn} = result where - result = [mkRecordSnippetCompItem uri (Just $ showGhc $ unLoc tcdLName) - (showGhc . unLoc $ con_name) field_labels mn doc Nothing + result = [mkRecordSnippetCompItem uri (Just $ printOutputableText $ unLoc tcdLName) + (printOutputableText . unLoc $ con_name) field_labels mn doc Nothing | ConDeclH98{..} <- unLoc <$> dd_cons tcdDataDefn , Just con_details <- [getFlds con_args] , let field_names = concatMap extract con_details - , let field_labels = showGhc <$> field_names + , let field_labels = printOutputableText <$> field_names , (not . List.null) field_labels ] doc = SpanDocText (getDocumentation [pmod] $ reLoc tcdLName) (SpanDocUris Nothing Nothing) @@ -804,7 +804,7 @@ prefixes = safeTyThingForRecord :: TyThing -> Maybe (T.Text, [T.Text]) safeTyThingForRecord (AnId _) = Nothing safeTyThingForRecord (AConLike dc) = - let ctxStr = showGhc . occName . conLikeName $ dc + let ctxStr = printOutputableText . occName . conLikeName $ dc field_names = T.pack . unpackFS . flLabel <$> conLikeFieldLabels dc in Just (ctxStr, field_names) diff --git a/ghcide/src/Development/IDE/Spans/AtPoint.hs b/ghcide/src/Development/IDE/Spans/AtPoint.hs index 687b025e39..5f1bbddb7c 100644 --- a/ghcide/src/Development/IDE/Spans/AtPoint.hs +++ b/ghcide/src/Development/IDE/Spans/AtPoint.hs @@ -55,7 +55,7 @@ import Data.Version (showVersion) import Development.IDE.Types.Shake (WithHieDb) import HieDb hiding (pointCommand) import System.Directory (doesFileExist) -import Development.IDE.GHC.Util (showGhc) +import Development.IDE.GHC.Util (printOutputableText) -- | Gives a Uri for the module, given the .hie file location and the the module info -- The Bool denotes if it is a boot module @@ -230,13 +230,13 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p prettyNames :: [T.Text] prettyNames = map prettyName names prettyName (Right n, dets) = T.unlines $ - wrapHaskell (showGhc n <> maybe "" (" :: " <>) ((prettyType <$> identType dets) <|> maybeKind)) + wrapHaskell (printOutputableText n <> maybe "" (" :: " <>) ((prettyType <$> identType dets) <|> maybeKind)) : definedAt n ++ maybeToList (prettyPackageName n) ++ catMaybes [ T.unlines . spanDocToMarkdown <$> lookupNameEnv dm n ] - where maybeKind = fmap showGhc $ safeTyThingType =<< lookupNameEnv km n - prettyName (Left m,_) = showGhc m + where maybeKind = fmap printOutputableText $ safeTyThingType =<< lookupNameEnv km n + prettyName (Left m,_) = printOutputableText m prettyPackageName n = do m <- nameModule_maybe n @@ -248,15 +248,15 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p prettyTypes = map (("_ :: "<>) . prettyType) types prettyType t = case kind of - HieFresh -> showGhc t - HieFromDisk full_file -> showGhc $ hieTypeToIface $ recoverFullType t (hie_types full_file) + HieFresh -> printOutputableText t + HieFromDisk full_file -> printOutputableText $ hieTypeToIface $ recoverFullType t (hie_types full_file) definedAt name = -- do not show "at " and similar messages -- see the code of 'pprNameDefnLoc' for more information case nameSrcLoc name of UnhelpfulLoc {} | isInternalName name || isSystemName name -> [] - _ -> ["*Defined " <> showGhc (pprNameDefnLoc name) <> "*"] + _ -> ["*Defined " <> printOutputableText (pprNameDefnLoc name) <> "*"] typeLocationsAtPoint :: forall m @@ -381,7 +381,7 @@ toUri = fromNormalizedUri . filePathToUri' . toNormalizedFilePath' defRowToSymbolInfo :: Res DefRow -> Maybe SymbolInformation defRowToSymbolInfo (DefRow{..}:.(modInfoSrcFile -> Just srcFile)) - = Just $ SymbolInformation (showGhc defNameOcc) kind Nothing Nothing loc Nothing + = Just $ SymbolInformation (printOutputableText defNameOcc) kind Nothing Nothing loc Nothing where kind | isVarOcc defNameOcc = SkVariable diff --git a/ghcide/src/Development/IDE/Spans/Common.hs b/ghcide/src/Development/IDE/Spans/Common.hs index 746fd27e20..dd4c15962a 100644 --- a/ghcide/src/Development/IDE/Spans/Common.hs +++ b/ghcide/src/Development/IDE/Spans/Common.hs @@ -34,7 +34,7 @@ type KindMap = NameEnv TyThing -- | Shows IEWrappedName, without any modifier, qualifier or unique identifier. unqualIEWrapName :: IEWrappedName RdrName -> T.Text -unqualIEWrapName = showGhc . rdrNameOcc . ieWrappedName +unqualIEWrapName = printOutputableText . rdrNameOcc . ieWrappedName -- From haskell-ide-engine/src/Haskell/Ide/Engine/Support/HieExtras.hs safeTyThingType :: TyThing -> Maybe Type diff --git a/ghcide/src/Development/IDE/Spans/Documentation.hs b/ghcide/src/Development/IDE/Spans/Documentation.hs index 83b011b42c..7b6d6b13b1 100644 --- a/ghcide/src/Development/IDE/Spans/Documentation.hs +++ b/ghcide/src/Development/IDE/Spans/Documentation.hs @@ -27,7 +27,7 @@ import Development.IDE.Core.RuleTypes import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import Development.IDE.GHC.Error -import Development.IDE.GHC.Util (showGhc) +import Development.IDE.GHC.Util (printOutputableText) import Development.IDE.Spans.Common import System.Directory import System.FilePath @@ -93,8 +93,8 @@ getDocumentationsTryGhc env mod names = do src <- toFileUriText $ lookupSrcHtmlForModule env mod return (doc, src) Nothing -> pure (Nothing, Nothing) - let docUri = (<> "#" <> selector <> showGhc name) <$> docFu - srcUri = (<> "#" <> showGhc name) <$> srcFu + let docUri = (<> "#" <> selector <> printOutputableText name) <$> docFu + srcUri = (<> "#" <> printOutputableText name) <$> srcFu selector | isValName name = "v:" | otherwise = "t:" diff --git a/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs b/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs index b0d709a5d2..a2471391a7 100644 --- a/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs +++ b/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs @@ -19,7 +19,7 @@ import Development.IDE.Core.RuleTypes (GetParsedModule (GetParsedModul import Development.IDE.Core.Service (IdeState, runAction) import Development.IDE.Core.Shake (use) import Development.IDE.GHC.Compat -import Development.IDE.GHC.Util (showGhc) +import Development.IDE.GHC.Util (printOutputableText) import Generics.SYB (extQ, something) import Ide.PluginUtils (getNormalizedFilePath, handleMaybeM, response) @@ -134,7 +134,7 @@ findSigLocOfStringDecl decls expectedType declName = something (const Nothing `e -- | Pretty Print the Type Signature (to validate GHC Error Message) sigToText :: Sig GhcPs -> Maybe Text sigToText = \case - ts@TypeSig {} -> Just $ stripSignature $ showGhc ts + ts@TypeSig {} -> Just $ stripSignature $ printOutputableText ts _ -> Nothing stripSignature :: Text -> Text diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index e92be25ea7..75155ccc49 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -50,7 +50,7 @@ import Development.IDE (GetModSummary (..), NeedsCompilation (NeedsCompilation), evalGhcEnv, hscEnvWithImportPaths, - prettyPrint, runAction, + printOutputable, runAction, textToStringBuffer, toNormalizedFilePath', uriToFilePath', useNoFile_, @@ -83,7 +83,7 @@ import qualified GHC.LanguageExtensions.Type as LangExt (Extension (..)) import Development.IDE.Core.FileStore (setSomethingModified) import Development.IDE.Types.Shake (toKey) -import Development.IDE.GHC.Util (showGhc) +import Development.IDE.GHC.Util (printOutputableText) import Ide.Plugin.Config (Config) #if MIN_VERSION_ghc(9,2,0) import GHC.Types.SrcLoc (UnhelpfulSpanReason (UnhelpfulInteractive)) @@ -284,7 +284,7 @@ runEvalCmd plId st EvalParams{..} = -- load the module in the interactive environment loadResult <- perf "loadModule" $ load LoadAllTargets - dbg "LOAD RESULT" $ showGhc loadResult + dbg "LOAD RESULT" $ printOutputableText loadResult case loadResult of Failed -> liftIO $ do let err = "" @@ -523,7 +523,7 @@ evals mark_exception (st, fp) df stmts = do prettyWarn :: Warn -> String prettyWarn Warn{..} = - prettyPrint (SrcLoc.getLoc warnMsg) <> ": warning:\n" + printOutputable (SrcLoc.getLoc warnMsg) <> ": warning:\n" <> " " <> SrcLoc.unLoc warnMsg runGetSession :: MonadIO m => IdeState -> NormalizedFilePath -> m HscEnv diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs index ed8bc849ca..8789c0d1ad 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs @@ -19,7 +19,7 @@ import Data.String (fromString) import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import qualified Development.IDE.GHC.Compat.Util as EnumSet -import Development.IDE.GHC.Util (prettyPrint) +import Development.IDE.GHC.Util (printOutputable) import GHC.LanguageExtensions.Type (Extension (..)) import Ide.Plugin.Eval.Util (gStrictTry) @@ -67,7 +67,7 @@ pkgNames_ = mapMaybe ( \case ExposePackage _ (PackageArg n) _ -> Just n - ExposePackage _ (UnitIdArg uid) _ -> Just $ prettyPrint uid + ExposePackage _ (UnitIdArg uid) _ -> Just $ printOutputable uid _ -> Nothing ) @@ -148,7 +148,7 @@ deriving instance Read Extension -- Partial display of DynFlags contents, for testing purposes showDynFlags :: DynFlags -> String showDynFlags df = - prettyPrint . vcat . map (\(n, d) -> text (n ++ ": ") <+> d) $ + printOutputable . vcat . map (\(n, d) -> text (n ++ ": ") <+> d) $ [ ("extensions", ppr . extensions $ df) , ("extensionFlags", ppr . EnumSet.toList . extensionFlags $ df) , ("importPaths", vList $ importPaths df) diff --git a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs index e729acacb1..84c85a301d 100644 --- a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs +++ b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs @@ -197,7 +197,7 @@ exportedModuleStrings :: ParsedModule -> [String] exportedModuleStrings ParsedModule{pm_parsed_source = L _ HsModule{..}} | Just export <- hsmodExports, exports <- unLoc export - = map prettyPrint exports + = map printOutputable exports exportedModuleStrings _ = [] minimalImportsRule :: Recorder (WithPriority Log) -> Rules () @@ -210,7 +210,7 @@ minimalImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \Minimal (imports, mbMinImports) <- liftIO $ extractMinimalImports hsc tmr let importsMap = Map.fromList - [ (realSrcSpanStart l, showGhc i) + [ (realSrcSpanStart l, printOutputableText i) | L (locA -> RealSrcSpan l _) i <- fromMaybe [] mbMinImports ] res = diff --git a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs index e181727fc5..b5f04cc6bd 100644 --- a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs +++ b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs @@ -42,7 +42,7 @@ import Development.IDE as D (Diagnostic (Diagnostic, Range (Range), Uri, getFileContents, getParsedModule, - showGhc, runAction, + printOutputableText, runAction, srcSpanToRange, toNormalizedUri, uriToFilePath', @@ -151,7 +151,7 @@ suggestAddPragma mDynflags Diagnostic {_message} = genPragma _message disabled | Just dynFlags <- mDynflags = -- GHC does not export 'OnOff', so we have to view it as string - catMaybes $ T.stripPrefix "Off " . showGhc <$> extensions dynFlags + catMaybes $ T.stripPrefix "Off " . printOutputableText <$> extensions dynFlags | otherwise = -- When the module failed to parse, we don't have access to its -- dynFlags. In that case, simply don't disable any pragmas. diff --git a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs index 019f0797ca..bbe963c2df 100644 --- a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs +++ b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs @@ -232,7 +232,7 @@ refineImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \RefineIm let res = [ (i, Just . T.intercalate "\n" - . map (showGhc . constructImport i) + . map (printOutputableText . constructImport i) . Map.toList $ filteredInnerImports) -- for every minimal imports @@ -251,7 +251,7 @@ refineImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \RefineIm -- Check if a name is exposed by AvailInfo (the available information of a module) containsAvail :: LIE GhcRn -> AvailInfo -> Bool containsAvail name avail = - any (\an -> prettyPrint an == (prettyPrint . ieName . unLoc $ name)) + any (\an -> printOutputable an == (printOutputable . ieName . unLoc $ name)) $ availNamesWithSelectors avail -------------------------------------------------------------------------------- diff --git a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs index f452be189b..c695a9f8cd 100644 --- a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs +++ b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs @@ -167,7 +167,7 @@ runRetrieCmd state RunRetrieParams{originatingFile = uri, ..} = extractImports :: ModSummary -> [HsBindLR GhcRn GhcRn] -> RewriteSpec -> [ImportSpec] extractImports ModSummary{ms_mod} topLevelBinds (Unfold thing) | Just FunBind {fun_matches} - <- find (\case FunBind{fun_id = L _ n} -> prettyPrint n == thing ; _ -> False) topLevelBinds + <- find (\case FunBind{fun_id = L _ n} -> printOutputable n == thing ; _ -> False) topLevelBinds , names <- listify p fun_matches = [ AddImport {..} @@ -249,7 +249,7 @@ suggestBindRewrites :: [(T.Text, CodeActionKind, RunRetrieParams)] suggestBindRewrites originatingFile pos ms_mod FunBind {fun_id = L l' rdrName} | pos `isInsideSrcSpan` l' = - let pprName = prettyPrint rdrName + let pprName = printOutputable rdrName pprNameText = T.pack pprName unfoldRewrite restrictToOriginatingFile = let rewrites = [Unfold (qualify ms_mod pprName)] @@ -273,7 +273,7 @@ suggestTypeRewrites :: TyClDecl pass -> [(T.Text, CodeActionKind, RunRetrieParams)] suggestTypeRewrites originatingFile ms_mod SynDecl {tcdLName = L _ rdrName} = - let pprName = prettyPrint rdrName + let pprName = printOutputable rdrName pprNameText = T.pack pprName unfoldRewrite restrictToOriginatingFile = let rewrites = [TypeForward (qualify ms_mod pprName)] @@ -330,7 +330,7 @@ suggestRuleRewrites originatingFile pos ms_mod (L _ HsRules {rds_rules}) = suggestRuleRewrites _ _ _ _ = [] qualify :: GHC.Module -> String -> String -qualify ms_mod x = prettyPrint ms_mod <> "." <> x +qualify ms_mod x = printOutputable ms_mod <> "." <> x ------------------------------------------------------------------------------- -- Retrie driving code diff --git a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs index 0776532ab3..e2e150e931 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs @@ -20,7 +20,7 @@ import Control.Exception import Data.Either (fromRight) import qualified Debug.Trace import Development.IDE.GHC.Compat (PlainGhcException, Outputable(..), SDoc) -import Development.IDE.GHC.Util (prettyPrint) +import Development.IDE.GHC.Util (printOutputable) import System.IO.Unsafe (unsafePerformIO) ------------------------------------------------------------------------------ @@ -31,7 +31,7 @@ unsafeRender = unsafeRender' . ppr unsafeRender' :: SDoc -> String unsafeRender' sdoc = unsafePerformIO $ do - let z = prettyPrint sdoc + let z = printOutputable sdoc -- We might not have unsafeGlobalDynFlags (like during testing), in which -- case GHC panics. Instead of crashing, let's just fail to print. !res <- try @PlainGhcException $ evaluate $ deepseq z z From 17453bc060992273f6073999fb3192dbc412218d Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Wed, 20 Apr 2022 18:09:42 +0800 Subject: [PATCH 08/12] Unify use printOutputable --- ghcide/src/Development/IDE/Core/Compile.hs | 2 +- .../Development/IDE/GHC/Compat/Outputable.hs | 2 +- ghcide/src/Development/IDE/GHC/Orphans.hs | 22 ++++----- ghcide/src/Development/IDE/GHC/Util.hs | 22 ++------- ghcide/src/Development/IDE/LSP/Outline.hs | 46 +++++++++---------- .../src/Development/IDE/Plugin/CodeAction.hs | 34 +++++++------- .../IDE/Plugin/CodeAction/ExactPrint.hs | 10 ++-- .../src/Development/IDE/Plugin/Completions.hs | 4 +- .../IDE/Plugin/Completions/Logic.hs | 22 ++++----- ghcide/src/Development/IDE/Spans/AtPoint.hs | 16 +++---- ghcide/src/Development/IDE/Spans/Common.hs | 2 +- .../Development/IDE/Spans/Documentation.hs | 6 +-- ghcide/src/Development/IDE/Types/Exports.hs | 2 +- .../src/Ide/Plugin/ChangeTypeSignature.hs | 4 +- .../src/Ide/Plugin/Eval/CodeLens.hs | 5 +- .../src/Ide/Plugin/Eval/GHC.hs | 4 +- .../src/Ide/Plugin/ExplicitImports.hs | 4 +- .../src/Ide/Plugin/Pragmas.hs | 4 +- .../src/Ide/Plugin/RefineImports.hs | 2 +- .../src/Ide/Plugin/Retrie.hs | 12 ++--- .../hls-tactics-plugin/src/Wingman/Debug.hs | 2 +- 21 files changed, 106 insertions(+), 121 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/Compile.hs b/ghcide/src/Development/IDE/Core/Compile.hs index adc3a6385a..7cfbbc893f 100644 --- a/ghcide/src/Development/IDE/Core/Compile.hs +++ b/ghcide/src/Development/IDE/Core/Compile.hs @@ -1301,7 +1301,7 @@ getDocsBatch hsc_env _mod _names = do #endif Map.findWithDefault mempty name amap)) case res of - Just x -> return $ map (first $ T.unpack . printOutputableText) x + Just x -> return $ map (first $ T.unpack . printOutputable) x Nothing -> throwErrors #if MIN_VERSION_ghc(9,2,0) $ Error.getErrorMessages msgs diff --git a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs index 35521463f2..65189a90db 100644 --- a/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs +++ b/ghcide/src/Development/IDE/GHC/Compat/Outputable.hs @@ -108,7 +108,7 @@ oldMkErrStyle _ = Out.mkErrStyle oldFormatErrDoc :: DynFlags -> Err.ErrDoc -> Out.SDoc oldFormatErrDoc dflags = Err.formatErrDoc dummySDocContext where dummySDocContext = initSDocContext dflags Out.defaultUserStyle -#elif !MIN_VERSION_ghc(9,2,0) +#elif !MIN_VERSION_ghc(9,0,0) oldRenderWithStyle :: DynFlags -> Out.SDoc -> Out.PprStyle -> String oldRenderWithStyle = Out.renderWithStyle diff --git a/ghcide/src/Development/IDE/GHC/Orphans.hs b/ghcide/src/Development/IDE/GHC/Orphans.hs index 7bc5ef2fde..125f3f17d1 100644 --- a/ghcide/src/Development/IDE/GHC/Orphans.hs +++ b/ghcide/src/Development/IDE/GHC/Orphans.hs @@ -46,27 +46,27 @@ import ByteCodeTypes #endif -- Orphan instances for types from the GHC API. -instance Show CoreModule where show = printOutputable +instance Show CoreModule where show = show . printOutputable instance NFData CoreModule where rnf = rwhnf -instance Show CgGuts where show = printOutputable . cg_module +instance Show CgGuts where show = show . printOutputable . cg_module instance NFData CgGuts where rnf = rwhnf instance Show ModDetails where show = const "" instance NFData ModDetails where rnf = rwhnf instance NFData SafeHaskellMode where rnf = rwhnf -instance Show Linkable where show = printOutputable +instance Show Linkable where show = show . printOutputable instance NFData Linkable where rnf (LM a b c) = rnf a `seq` rnf b `seq` rnf c instance NFData Unlinked where rnf (DotO f) = rnf f rnf (DotA f) = rnf f rnf (DotDLL f) = rnf f rnf (BCOs a b) = seqCompiledByteCode a `seq` liftRnf rwhnf b -instance Show PackageFlag where show = printOutputable -instance Show InteractiveImport where show = printOutputable -instance Show PackageName where show = printOutputable +instance Show PackageFlag where show = show . printOutputable +instance Show InteractiveImport where show = show . printOutputable +instance Show PackageName where show = show . printOutputable #if !MIN_VERSION_ghc(9,0,1) -instance Show ComponentId where show = printOutputable -instance Show SourcePackageId where show = printOutputable +instance Show ComponentId where show = show . printOutputable +instance Show SourcePackageId where show = show . printOutputable instance Show GhcPlugins.InstalledUnitId where show = installedUnitIdString @@ -76,7 +76,7 @@ instance NFData GhcPlugins.InstalledUnitId where rnf = rwhnf . installedUnitIdFS instance Hashable GhcPlugins.InstalledUnitId where hashWithSalt salt = hashWithSalt salt . installedUnitIdString #else -instance Show UnitId where show = printOutputable +instance Show UnitId where show = show . printOutputable deriving instance Ord SrcSpan deriving instance Ord UnhelpfulSpanReason #endif @@ -86,7 +86,7 @@ instance NFData SB.StringBuffer where rnf = rwhnf instance Show Module where show = moduleNameString . moduleName -instance Outputable a => Show (GenLocated SrcSpan a) where show = printOutputable +instance Outputable a => Show (GenLocated SrcSpan a) where show = show . printOutputable instance (NFData l, NFData e) => NFData (GenLocated l e) where rnf (L l e) = rnf l `seq` rnf e @@ -207,5 +207,5 @@ instance (NFData (HsModule a)) where #endif rnf = rwhnf -instance Show OccName where show = printOutputable +instance Show OccName where show = show . printOutputable instance Hashable OccName where hashWithSalt s n = hashWithSalt s (getKey $ getUnique n) diff --git a/ghcide/src/Development/IDE/GHC/Util.hs b/ghcide/src/Development/IDE/GHC/Util.hs index 6d27936ec1..3f44863f65 100644 --- a/ghcide/src/Development/IDE/GHC/Util.hs +++ b/ghcide/src/Development/IDE/GHC/Util.hs @@ -27,8 +27,7 @@ module Development.IDE.GHC.Util( dontWriteHieFiles, disableWarningsAsErrors, traceAst, - printOutputable, - printOutputableText + printOutputable ) where #if MIN_VERSION_ghc(9,2,0) @@ -133,7 +132,7 @@ bytestringToStringBuffer (PS buf cur len) = StringBuffer{..} -- | Pretty print a 'RdrName' wrapping operators in parens printRdrName :: RdrName -> String -printRdrName name = printOutputable $ parenSymOcc rn (ppr rn) +printRdrName name = show $ printOutputable $ parenSymOcc rn (ppr rn) where rn = rdrNameOcc name @@ -324,19 +323,6 @@ instance Outputable SDoc where -- This is the most common print utility, will print with a user-friendly style like: `a_a4ME` as `a`. -- -- It internal using `showSDocUnsafe` with `unsafeGlobalDynFlags`. --- --- You may prefer `printOutputableText` if `Text` is expected to return. -printOutputable :: Outputable a => a -> String -printOutputable = printWithoutUniques +printOutputable :: Outputable a => a -> T.Text +printOutputable = T.pack . printWithoutUniques {-# INLINE printOutputable #-} - --- | Print a GHC value in `defaultUserStyle` without unique symbols. --- --- This is the most common print utility, will print with a user-friendly style like: `a_a4ME` as `a`. --- --- It internal using `showSDocUnsafe` with `unsafeGlobalDynFlags`. --- --- You may prefer `printOutputable` if `String` is expected to return. -printOutputableText :: Outputable a => a -> T.Text -printOutputableText = T.pack . printOutputable -{-# INLINE printOutputableText #-} diff --git a/ghcide/src/Development/IDE/LSP/Outline.hs b/ghcide/src/Development/IDE/LSP/Outline.hs index 5c52b044c7..0a45688fef 100644 --- a/ghcide/src/Development/IDE/LSP/Outline.hs +++ b/ghcide/src/Development/IDE/LSP/Outline.hs @@ -20,7 +20,7 @@ import Development.IDE.GHC.Compat import Development.IDE.GHC.Error (rangeToRealSrcSpan, realSrcSpanToRange) import Development.IDE.Types.Location -import Development.IDE.GHC.Util (printOutputableText) +import Development.IDE.GHC.Util (printOutputable) import Language.LSP.Server (LspM) import Language.LSP.Types (DocumentSymbol (..), DocumentSymbolParams (DocumentSymbolParams, _textDocument), @@ -47,7 +47,7 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif moduleSymbol = hsmodName >>= \case (L (locA -> (RealSrcSpan l _)) m) -> Just $ (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText m + { _name = printOutputable m , _kind = SkFile , _range = Range (Position 0 0) (Position maxBound 0) -- _ltop is 0 0 0 0 } @@ -70,18 +70,18 @@ moduleOutline ideState DocumentSymbolParams{ _textDocument = TextDocumentIdentif documentSymbolForDecl :: LHsDecl GhcPs -> Maybe DocumentSymbol documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ FamDecl { tcdFam = FamilyDecl { fdLName = L _ n, fdInfo, fdTyVars } })) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText n - <> (case printOutputableText fdTyVars of + { _name = printOutputable n + <> (case printOutputable fdTyVars of "" -> "" t -> " " <> t ) - , _detail = Just $ printOutputableText fdInfo + , _detail = Just $ printOutputable fdInfo , _kind = SkFunction } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ ClassDecl { tcdLName = L _ name, tcdSigs, tcdTyVars })) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText name - <> (case printOutputableText tcdTyVars of + { _name = printOutputable name + <> (case printOutputable tcdTyVars of "" -> "" t -> " " <> t ) @@ -90,7 +90,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ ClassDecl { tcdLNa , _children = Just $ List [ (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText n + { _name = printOutputable n , _kind = SkMethod , _selectionRange = realSrcSpanToRange l' } @@ -100,12 +100,12 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ ClassDecl { tcdLNa } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLName = L _ name, tcdDataDefn = HsDataDefn { dd_cons } })) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText name + { _name = printOutputable name , _kind = SkStruct , _children = Just $ List [ (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText n + { _name = printOutputable n , _kind = SkConstructor , _selectionRange = realSrcSpanToRange l' #if MIN_VERSION_ghc(9,2,0) @@ -123,7 +123,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLNam where cvtFld :: LFieldOcc GhcPs -> Maybe DocumentSymbol cvtFld (L (RealSrcSpan l _) n) = Just $ (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText (unLoc (rdrNameFieldOcc n)) + { _name = printOutputable (unLoc (rdrNameFieldOcc n)) , _kind = SkField } cvtFld _ = Nothing @@ -138,7 +138,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLNam -- | Extract the record fields of a constructor conArgRecordFields (RecCon (L _ lcdfs)) = Just $ List [ (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText n + { _name = printOutputable n , _kind = SkField } | L _ cdf <- lcdfs @@ -147,12 +147,12 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ DataDecl { tcdLNam conArgRecordFields _ = Nothing #endif documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (TyClD _ SynDecl { tcdLName = L (locA -> (RealSrcSpan l' _)) n })) = Just - (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputableText n + (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputable n , _kind = SkTypeParameter , _selectionRange = realSrcSpanToRange l' } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (InstD _ ClsInstD { cid_inst = ClsInstDecl { cid_poly_ty } })) - = Just (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputableText cid_poly_ty + = Just (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputable cid_poly_ty , _kind = SkInterface } #if MIN_VERSION_ghc(9,2,0) @@ -161,8 +161,8 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (InstD _ DataFamInstD { dfi documentSymbolForDecl (L (RealSrcSpan l _) (InstD _ DataFamInstD { dfid_inst = DataFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } })) #endif = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText (unLoc feqn_tycon) <> " " <> T.unwords - (map printOutputableText feqn_pats) + { _name = printOutputable (unLoc feqn_tycon) <> " " <> T.unwords + (map printOutputable feqn_pats) , _kind = SkInterface } #if MIN_VERSION_ghc(9,2,0) @@ -171,24 +171,24 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (InstD _ TyFamInstD { tfid_ documentSymbolForDecl (L (RealSrcSpan l _) (InstD _ TyFamInstD { tfid_inst = TyFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } })) #endif = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText (unLoc feqn_tycon) <> " " <> T.unwords - (map printOutputableText feqn_pats) + { _name = printOutputable (unLoc feqn_tycon) <> " " <> T.unwords + (map printOutputable feqn_pats) , _kind = SkInterface } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (DerivD _ DerivDecl { deriv_type })) = gfindtype deriv_type <&> \(L (_ :: SrcSpan) name) -> - (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputableText @(HsType GhcPs) + (defDocumentSymbol l :: DocumentSymbol) { _name = printOutputable @(HsType GhcPs) name , _kind = SkInterface } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (ValD _ FunBind{fun_id = L _ name})) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText name + { _name = printOutputable name , _kind = SkFunction } documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (ValD _ PatBind{pat_lhs})) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = printOutputableText pat_lhs + { _name = printOutputable pat_lhs , _kind = SkFunction } @@ -204,7 +204,7 @@ documentSymbolForDecl (L (locA -> (RealSrcSpan l _)) (ForD _ x)) = Just ForeignExport{} -> Just "export" XForeignDecl{} -> Nothing } - where name = printOutputableText $ unLoc $ fd_name x + where name = printOutputable $ unLoc $ fd_name x documentSymbolForDecl _ = Nothing @@ -228,7 +228,7 @@ documentSymbolForImportSummary importSymbols = documentSymbolForImport :: LImportDecl GhcPs -> Maybe DocumentSymbol documentSymbolForImport (L (locA -> (RealSrcSpan l _)) ImportDecl { ideclName, ideclQualified }) = Just (defDocumentSymbol l :: DocumentSymbol) - { _name = "import " <> printOutputableText ideclName + { _name = "import " <> printOutputable ideclName , _kind = SkModule #if MIN_VERSION_ghc(8,10,0) , _detail = case ideclQualified of { NotQualified -> Nothing; _ -> Just "qualified" } diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction.hs b/ghcide/src/Development/IDE/Plugin/CodeAction.hs index 1df313cec8..249214081f 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction.hs @@ -51,7 +51,7 @@ import Development.IDE.GHC.ExactPrint import Development.IDE.GHC.Util (printOutputable, printRdrName, traceAst, - printOutputableText) + printOutputable) import Development.IDE.Plugin.CodeAction.Args import Development.IDE.Plugin.CodeAction.ExactPrint import Development.IDE.Plugin.CodeAction.PositionIndexed @@ -545,7 +545,7 @@ suggestDeleteUnusedBinding isTheBinding span = srcSpanToRange span == Just _range isSameName :: IdP GhcPs -> String -> Bool - isSameName x name = printOutputable x == name + isSameName x name = show (printOutputable x) == name data ExportsAs = ExportName | ExportPattern | ExportFamily | ExportAll deriving (Eq) @@ -1012,7 +1012,7 @@ occursUnqualified symbol ImportDecl{..} occursUnqualified _ _ = False symbolOccursIn :: T.Text -> IE GhcPs -> Bool -symbolOccursIn symb = any ((== symb). printOutputableText) . ieNames +symbolOccursIn symb = any ((== symb). printOutputable) . ieNames targetModuleName :: ModuleTarget -> ModuleName targetModuleName ImplicitPrelude{} = mkModuleName "Prelude" @@ -1046,12 +1046,12 @@ disambiguateSymbol pm fileContents Diagnostic {..} (T.unpack -> symbol) = \case in Right <$> [ if parensed then Rewrite (rangeToSrcSpan "" _range) $ \df -> liftParseAST @(HsExpr GhcPs) df $ - printOutputable $ + show $ printOutputable $ HsVar @GhcPs noExtField $ reLocA $ L (mkGeneralSrcSpan "") rdr else Rewrite (rangeToSrcSpan "" _range) $ \df -> liftParseAST @RdrName df $ - printOutputable $ L (mkGeneralSrcSpan "") rdr + show $ printOutputable $ L (mkGeneralSrcSpan "") rdr ] findImportDeclByRange :: [LImportDecl GhcPs] -> Range -> Maybe (LImportDecl GhcPs) findImportDeclByRange xs range = find (\(L (locA -> l) _)-> srcSpanToRange l == Just range) xs @@ -1422,7 +1422,7 @@ newImport modName mSymbol mQual hiding = NewImport impStmt symImp | Just symbol <- mSymbol , symOcc <- mkVarOcc $ T.unpack symbol = - " (" <> printOutputableText (parenSymOcc symOcc $ ppr symOcc) <> ")" + " (" <> printOutputable (parenSymOcc symOcc $ ppr symOcc) <> ")" | otherwise = "" impStmt = "import " @@ -1616,32 +1616,32 @@ smallerRangesForBindingExport lies b = b' = wrapOperatorInParens . unqualify $ b #if !MIN_VERSION_ghc(9,2,0) ranges' (L _ (IEThingWith _ thing _ inners labels)) - | printOutputable thing == b' = [] + | show (printOutputable thing) == b' = [] | otherwise = - [ locA l' | L l' x <- inners, printOutputable x == b'] - ++ [ l' | L l' x <- labels, printOutputable x == b'] + [ locA l' | L l' x <- inners, show (printOutputable x) == b'] + ++ [ l' | L l' x <- labels, show (printOutputable x) == b'] #else ranges' (L _ (IEThingWith _ thing _ inners)) - | printOutputable thing == b' = [] + | show (printOutputable thing) == b' = [] | otherwise = - [ locA l' | L l' x <- inners, printOutputable x == b'] + [ locA l' | L l' x <- inners, show (printOutputable x) == b'] #endif ranges' _ = [] rangesForBinding' :: String -> LIE GhcPs -> [SrcSpan] -rangesForBinding' b (L (locA -> l) x@IEVar{}) | printOutputable x == b = [l] -rangesForBinding' b (L (locA -> l) x@IEThingAbs{}) | printOutputable x == b = [l] -rangesForBinding' b (L (locA -> l) (IEThingAll _ x)) | printOutputable x == b = [l] +rangesForBinding' b (L (locA -> l) x@IEVar{}) | show (printOutputable x) == b = [l] +rangesForBinding' b (L (locA -> l) x@IEThingAbs{}) | show (printOutputable x) == b = [l] +rangesForBinding' b (L (locA -> l) (IEThingAll _ x)) | show (printOutputable x) == b = [l] #if !MIN_VERSION_ghc(9,2,0) rangesForBinding' b (L l (IEThingWith _ thing _ inners labels)) #else rangesForBinding' b (L (locA -> l) (IEThingWith _ thing _ inners)) #endif - | printOutputable thing == b = [l] + | show (printOutputable thing) == b = [l] | otherwise = - [ locA l' | L l' x <- inners, printOutputable x == b] + [ locA l' | L l' x <- inners, show (printOutputable x) == b] #if !MIN_VERSION_ghc(9,2,0) - ++ [ l' | L l' x <- labels, printOutputable x == b] + ++ [ l' | L l' x <- labels, show (printOutputable x) == b] #endif rangesForBinding' _ _ = [] diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs index abdcfd67bd..b958be33c2 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs @@ -355,8 +355,8 @@ extendImportTopLevel thing (L l it@ImportDecl{..}) top <- uniqueSrcSpanT let rdr = reLocA $ L src $ mkRdrUnqual $ mkVarOcc thing let alreadyImported = - printOutputableText (occName (unLoc rdr)) - `elem` map (printOutputableText @OccName) (listify (const True) lies) + printOutputable (occName (unLoc rdr)) + `elem` map (printOutputable @OccName) (listify (const True) lies) when alreadyImported $ lift (Left $ thing <> " already imported") @@ -456,8 +456,8 @@ extendImportViaParent df parent child (L l it@ImportDecl{..}) childRdr <- pure $ setEntryDP childRdr $ SameLine $ if hasSibling then 1 else 0 #endif let alreadyImported = - printOutputableText (occName (unLoc childRdr)) - `elem` map (printOutputableText @OccName) (listify (const True) lies') + printOutputable (occName (unLoc childRdr)) + `elem` map (printOutputable @OccName) (listify (const True) lies') when alreadyImported $ lift (Left $ child <> " already included in " <> parent <> " imports") @@ -542,7 +542,7 @@ addCommaInImportList lies x = do #endif unIEWrappedName :: IEWrappedName (IdP GhcPs) -> String -unIEWrappedName (occName -> occ) = printOutputable $ parenSymOcc occ (ppr occ) +unIEWrappedName (occName -> occ) = show $ printOutputable $ parenSymOcc occ (ppr occ) hasParen :: String -> Bool hasParen ('(' : _) = True diff --git a/ghcide/src/Development/IDE/Plugin/Completions.hs b/ghcide/src/Development/IDE/Plugin/Completions.hs index 43f3a28886..51eee11e27 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions.hs @@ -27,7 +27,7 @@ import qualified Development.IDE.Core.Shake as Shake import Development.IDE.GHC.Compat import Development.IDE.GHC.Error (rangeToSrcSpan) import Development.IDE.GHC.ExactPrint (GetAnnotatedParsedSource (GetAnnotatedParsedSource)) -import Development.IDE.GHC.Util (printOutputableText) +import Development.IDE.GHC.Util (printOutputable) import Development.IDE.Graph import Development.IDE.Plugin.CodeAction (newImport, newImportToEdit) @@ -213,7 +213,7 @@ extendImportHandler ideState edit@ExtendImport {..} = do <> "’ from " <> importName <> " (at " - <> printOutputableText srcSpan + <> printOutputable srcSpan <> ")" void $ LSP.sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing wedit) (\_ -> pure ()) return $ Right Null diff --git a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs index dfda9c336b..ae0ad5969b 100644 --- a/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs +++ b/ghcide/src/Development/IDE/Plugin/Completions/Logic.hs @@ -214,7 +214,7 @@ mkCompl pprLineCol :: SrcLoc -> T.Text pprLineCol (UnhelpfulLoc fs) = T.pack $ unpackFS fs pprLineCol (RealSrcLoc loc _) = - "line " <> printOutputableText (srcLocLine loc) <> ", column " <> printOutputableText (srcLocCol loc) + "line " <> printOutputable (srcLocLine loc) <> ", column " <> printOutputable (srcLocCol loc) mkAdditionalEditsCommand :: PluginId -> ExtendImport -> Command @@ -226,7 +226,7 @@ mkNameCompItem doc thingParent origName provenance thingType isInfix docs !imp = where compKind = occNameToComKind typeText origName isTypeCompl = isTcOcc origName - label = stripPrefix $ printOutputableText origName + label = stripPrefix $ printOutputable origName insertText = case isInfix of Nothing -> case getArgText <$> thingType of Nothing -> label @@ -235,7 +235,7 @@ mkNameCompItem doc thingParent origName provenance thingType isInfix docs !imp = Just Surrounded -> label typeText - | Just t <- thingType = Just . stripForall $ printOutputableText t + | Just t <- thingType = Just . stripForall $ printOutputable t | otherwise = Nothing additionalTextEdits = imp <&> \x -> @@ -244,7 +244,7 @@ mkNameCompItem doc thingParent origName provenance thingType isInfix docs !imp = thingParent, importName = showModName $ unLoc $ ideclName $ unLoc x, importQual = getImportQual x, - newThing = printOutputableText origName + newThing = printOutputable origName } stripForall :: T.Text -> T.Text @@ -295,7 +295,7 @@ showForSnippet x = T.pack $ renderWithContext ctxt $ GHC.ppr x -- FIXme where ctxt = defaultSDocContext{sdocStyle = mkUserStyle neverQualify AllTheWay} #else -showForSnippet x = printOutputableText x +showForSnippet x = printOutputable x #endif mkModCompl :: T.Text -> CompletionItem @@ -350,7 +350,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do let packageState = hscEnv env curModName = moduleName curMod - curModNameText = printOutputableText curModName + curModNameText = printOutputable curModName importMap = Map.fromList [ (l, imp) | imp@(L (locA -> (RealSrcSpan l _)) _) <- limports ] @@ -386,7 +386,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do -- or if it doesn't have a real location loc <- realSpan $ is_dloc spec Map.lookup loc importMap - compItem <- toCompItem par curMod (printOutputableText $ is_mod spec) n originalImportDecl + compItem <- toCompItem par curMod (printOutputable $ is_mod spec) n originalImportDecl let unqual | is_qual spec = [] | otherwise = compItem @@ -498,12 +498,12 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod findRecordCompl :: Uri -> ParsedModule -> Provenance -> TyClDecl GhcPs -> [CompItem] findRecordCompl uri pmod mn DataDecl {tcdLName, tcdDataDefn} = result where - result = [mkRecordSnippetCompItem uri (Just $ printOutputableText $ unLoc tcdLName) - (printOutputableText . unLoc $ con_name) field_labels mn doc Nothing + result = [mkRecordSnippetCompItem uri (Just $ printOutputable $ unLoc tcdLName) + (printOutputable . unLoc $ con_name) field_labels mn doc Nothing | ConDeclH98{..} <- unLoc <$> dd_cons tcdDataDefn , Just con_details <- [getFlds con_args] , let field_names = concatMap extract con_details - , let field_labels = printOutputableText <$> field_names + , let field_labels = printOutputable <$> field_names , (not . List.null) field_labels ] doc = SpanDocText (getDocumentation [pmod] $ reLoc tcdLName) (SpanDocUris Nothing Nothing) @@ -804,7 +804,7 @@ prefixes = safeTyThingForRecord :: TyThing -> Maybe (T.Text, [T.Text]) safeTyThingForRecord (AnId _) = Nothing safeTyThingForRecord (AConLike dc) = - let ctxStr = printOutputableText . occName . conLikeName $ dc + let ctxStr = printOutputable . occName . conLikeName $ dc field_names = T.pack . unpackFS . flLabel <$> conLikeFieldLabels dc in Just (ctxStr, field_names) diff --git a/ghcide/src/Development/IDE/Spans/AtPoint.hs b/ghcide/src/Development/IDE/Spans/AtPoint.hs index 5f1bbddb7c..0ad8b86e9c 100644 --- a/ghcide/src/Development/IDE/Spans/AtPoint.hs +++ b/ghcide/src/Development/IDE/Spans/AtPoint.hs @@ -34,6 +34,7 @@ import Development.IDE.GHC.Compat import qualified Development.IDE.GHC.Compat.Util as Util import Development.IDE.Spans.Common import Development.IDE.Types.Options +import Development.IDE.GHC.Util (printOutputable) import Control.Applicative import Control.Monad.Extra @@ -55,7 +56,6 @@ import Data.Version (showVersion) import Development.IDE.Types.Shake (WithHieDb) import HieDb hiding (pointCommand) import System.Directory (doesFileExist) -import Development.IDE.GHC.Util (printOutputableText) -- | Gives a Uri for the module, given the .hie file location and the the module info -- The Bool denotes if it is a boot module @@ -230,13 +230,13 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p prettyNames :: [T.Text] prettyNames = map prettyName names prettyName (Right n, dets) = T.unlines $ - wrapHaskell (printOutputableText n <> maybe "" (" :: " <>) ((prettyType <$> identType dets) <|> maybeKind)) + wrapHaskell (printOutputable n <> maybe "" (" :: " <>) ((prettyType <$> identType dets) <|> maybeKind)) : definedAt n ++ maybeToList (prettyPackageName n) ++ catMaybes [ T.unlines . spanDocToMarkdown <$> lookupNameEnv dm n ] - where maybeKind = fmap printOutputableText $ safeTyThingType =<< lookupNameEnv km n - prettyName (Left m,_) = printOutputableText m + where maybeKind = fmap printOutputable $ safeTyThingType =<< lookupNameEnv km n + prettyName (Left m,_) = printOutputable m prettyPackageName n = do m <- nameModule_maybe n @@ -248,15 +248,15 @@ atPoint IdeOptions{} (HAR _ hf _ _ kind) (DKMap dm km) env pos = listToMaybe $ p prettyTypes = map (("_ :: "<>) . prettyType) types prettyType t = case kind of - HieFresh -> printOutputableText t - HieFromDisk full_file -> printOutputableText $ hieTypeToIface $ recoverFullType t (hie_types full_file) + HieFresh -> printOutputable t + HieFromDisk full_file -> printOutputable $ hieTypeToIface $ recoverFullType t (hie_types full_file) definedAt name = -- do not show "at " and similar messages -- see the code of 'pprNameDefnLoc' for more information case nameSrcLoc name of UnhelpfulLoc {} | isInternalName name || isSystemName name -> [] - _ -> ["*Defined " <> printOutputableText (pprNameDefnLoc name) <> "*"] + _ -> ["*Defined " <> printOutputable (pprNameDefnLoc name) <> "*"] typeLocationsAtPoint :: forall m @@ -381,7 +381,7 @@ toUri = fromNormalizedUri . filePathToUri' . toNormalizedFilePath' defRowToSymbolInfo :: Res DefRow -> Maybe SymbolInformation defRowToSymbolInfo (DefRow{..}:.(modInfoSrcFile -> Just srcFile)) - = Just $ SymbolInformation (printOutputableText defNameOcc) kind Nothing Nothing loc Nothing + = Just $ SymbolInformation (printOutputable defNameOcc) kind Nothing Nothing loc Nothing where kind | isVarOcc defNameOcc = SkVariable diff --git a/ghcide/src/Development/IDE/Spans/Common.hs b/ghcide/src/Development/IDE/Spans/Common.hs index dd4c15962a..2225246982 100644 --- a/ghcide/src/Development/IDE/Spans/Common.hs +++ b/ghcide/src/Development/IDE/Spans/Common.hs @@ -34,7 +34,7 @@ type KindMap = NameEnv TyThing -- | Shows IEWrappedName, without any modifier, qualifier or unique identifier. unqualIEWrapName :: IEWrappedName RdrName -> T.Text -unqualIEWrapName = printOutputableText . rdrNameOcc . ieWrappedName +unqualIEWrapName = printOutputable . rdrNameOcc . ieWrappedName -- From haskell-ide-engine/src/Haskell/Ide/Engine/Support/HieExtras.hs safeTyThingType :: TyThing -> Maybe Type diff --git a/ghcide/src/Development/IDE/Spans/Documentation.hs b/ghcide/src/Development/IDE/Spans/Documentation.hs index 7b6d6b13b1..c5a9190652 100644 --- a/ghcide/src/Development/IDE/Spans/Documentation.hs +++ b/ghcide/src/Development/IDE/Spans/Documentation.hs @@ -27,7 +27,7 @@ import Development.IDE.Core.RuleTypes import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import Development.IDE.GHC.Error -import Development.IDE.GHC.Util (printOutputableText) +import Development.IDE.GHC.Util (printOutputable) import Development.IDE.Spans.Common import System.Directory import System.FilePath @@ -93,8 +93,8 @@ getDocumentationsTryGhc env mod names = do src <- toFileUriText $ lookupSrcHtmlForModule env mod return (doc, src) Nothing -> pure (Nothing, Nothing) - let docUri = (<> "#" <> selector <> printOutputableText name) <$> docFu - srcUri = (<> "#" <> printOutputableText name) <$> srcFu + let docUri = (<> "#" <> selector <> printOutputable name) <$> docFu + srcUri = (<> "#" <> printOutputable name) <$> srcFu selector | isValName name = "v:" | otherwise = "t:" diff --git a/ghcide/src/Development/IDE/Types/Exports.hs b/ghcide/src/Development/IDE/Types/Exports.hs index ba56a1f8f8..faef7d9001 100644 --- a/ghcide/src/Development/IDE/Types/Exports.hs +++ b/ghcide/src/Development/IDE/Types/Exports.hs @@ -178,7 +178,7 @@ unpackAvail mn | otherwise = const [] where !mod = pack $ moduleNameString mn - f id@IdentInfo {..} = (pack (occNameString name), moduleNameText,[id]) + f id@IdentInfo {..} = (printOutputable name, moduleNameText,[id]) identInfoToKeyVal :: IdentInfo -> (ModuleNameText, IdentInfo) diff --git a/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs b/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs index a2471391a7..3d833a9cd5 100644 --- a/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs +++ b/plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs @@ -19,7 +19,7 @@ import Development.IDE.Core.RuleTypes (GetParsedModule (GetParsedModul import Development.IDE.Core.Service (IdeState, runAction) import Development.IDE.Core.Shake (use) import Development.IDE.GHC.Compat -import Development.IDE.GHC.Util (printOutputableText) +import Development.IDE.GHC.Util (printOutputable) import Generics.SYB (extQ, something) import Ide.PluginUtils (getNormalizedFilePath, handleMaybeM, response) @@ -134,7 +134,7 @@ findSigLocOfStringDecl decls expectedType declName = something (const Nothing `e -- | Pretty Print the Type Signature (to validate GHC Error Message) sigToText :: Sig GhcPs -> Maybe Text sigToText = \case - ts@TypeSig {} -> Just $ stripSignature $ printOutputableText ts + ts@TypeSig {} -> Just $ stripSignature $ printOutputable ts _ -> Nothing stripSignature :: Text -> Text diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index 75155ccc49..7e069f798b 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -83,7 +83,6 @@ import qualified GHC.LanguageExtensions.Type as LangExt (Extension (..)) import Development.IDE.Core.FileStore (setSomethingModified) import Development.IDE.Types.Shake (toKey) -import Development.IDE.GHC.Util (printOutputableText) import Ide.Plugin.Config (Config) #if MIN_VERSION_ghc(9,2,0) import GHC.Types.SrcLoc (UnhelpfulSpanReason (UnhelpfulInteractive)) @@ -284,7 +283,7 @@ runEvalCmd plId st EvalParams{..} = -- load the module in the interactive environment loadResult <- perf "loadModule" $ load LoadAllTargets - dbg "LOAD RESULT" $ printOutputableText loadResult + dbg "LOAD RESULT" $ printOutputable loadResult case loadResult of Failed -> liftIO $ do let err = "" @@ -523,7 +522,7 @@ evals mark_exception (st, fp) df stmts = do prettyWarn :: Warn -> String prettyWarn Warn{..} = - printOutputable (SrcLoc.getLoc warnMsg) <> ": warning:\n" + show (printOutputable $ SrcLoc.getLoc warnMsg) <> ": warning:\n" <> " " <> SrcLoc.unLoc warnMsg runGetSession :: MonadIO m => IdeState -> NormalizedFilePath -> m HscEnv diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs index 8789c0d1ad..9224594501 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs @@ -67,7 +67,7 @@ pkgNames_ = mapMaybe ( \case ExposePackage _ (PackageArg n) _ -> Just n - ExposePackage _ (UnitIdArg uid) _ -> Just $ printOutputable uid + ExposePackage _ (UnitIdArg uid) _ -> Just $ show $ printOutputable uid _ -> Nothing ) @@ -148,7 +148,7 @@ deriving instance Read Extension -- Partial display of DynFlags contents, for testing purposes showDynFlags :: DynFlags -> String showDynFlags df = - printOutputable . vcat . map (\(n, d) -> text (n ++ ": ") <+> d) $ + show . printOutputable . vcat . map (\(n, d) -> text (n ++ ": ") <+> d) $ [ ("extensions", ppr . extensions $ df) , ("extensionFlags", ppr . EnumSet.toList . extensionFlags $ df) , ("importPaths", vList $ importPaths df) diff --git a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs index 84c85a301d..45b125414d 100644 --- a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs +++ b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs @@ -197,7 +197,7 @@ exportedModuleStrings :: ParsedModule -> [String] exportedModuleStrings ParsedModule{pm_parsed_source = L _ HsModule{..}} | Just export <- hsmodExports, exports <- unLoc export - = map printOutputable exports + = map (show . printOutputable) exports exportedModuleStrings _ = [] minimalImportsRule :: Recorder (WithPriority Log) -> Rules () @@ -210,7 +210,7 @@ minimalImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \Minimal (imports, mbMinImports) <- liftIO $ extractMinimalImports hsc tmr let importsMap = Map.fromList - [ (realSrcSpanStart l, printOutputableText i) + [ (realSrcSpanStart l, printOutputable i) | L (locA -> RealSrcSpan l _) i <- fromMaybe [] mbMinImports ] res = diff --git a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs index b5f04cc6bd..bb7a809744 100644 --- a/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs +++ b/plugins/hls-pragmas-plugin/src/Ide/Plugin/Pragmas.hs @@ -42,7 +42,7 @@ import Development.IDE as D (Diagnostic (Diagnostic, Range (Range), Uri, getFileContents, getParsedModule, - printOutputableText, runAction, + printOutputable, runAction, srcSpanToRange, toNormalizedUri, uriToFilePath', @@ -151,7 +151,7 @@ suggestAddPragma mDynflags Diagnostic {_message} = genPragma _message disabled | Just dynFlags <- mDynflags = -- GHC does not export 'OnOff', so we have to view it as string - catMaybes $ T.stripPrefix "Off " . printOutputableText <$> extensions dynFlags + catMaybes $ T.stripPrefix "Off " . printOutputable <$> extensions dynFlags | otherwise = -- When the module failed to parse, we don't have access to its -- dynFlags. In that case, simply don't disable any pragmas. diff --git a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs index bbe963c2df..582fba0a72 100644 --- a/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs +++ b/plugins/hls-refine-imports-plugin/src/Ide/Plugin/RefineImports.hs @@ -232,7 +232,7 @@ refineImportsRule recorder = define (cmapWithPrio LogShake recorder) $ \RefineIm let res = [ (i, Just . T.intercalate "\n" - . map (printOutputableText . constructImport i) + . map (printOutputable . constructImport i) . Map.toList $ filteredInnerImports) -- for every minimal imports diff --git a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs index c695a9f8cd..3ea4e7a2c7 100644 --- a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs +++ b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs @@ -167,7 +167,7 @@ runRetrieCmd state RunRetrieParams{originatingFile = uri, ..} = extractImports :: ModSummary -> [HsBindLR GhcRn GhcRn] -> RewriteSpec -> [ImportSpec] extractImports ModSummary{ms_mod} topLevelBinds (Unfold thing) | Just FunBind {fun_matches} - <- find (\case FunBind{fun_id = L _ n} -> printOutputable n == thing ; _ -> False) topLevelBinds + <- find (\case FunBind{fun_id = L _ n} -> show (printOutputable n) == thing ; _ -> False) topLevelBinds , names <- listify p fun_matches = [ AddImport {..} @@ -249,8 +249,8 @@ suggestBindRewrites :: [(T.Text, CodeActionKind, RunRetrieParams)] suggestBindRewrites originatingFile pos ms_mod FunBind {fun_id = L l' rdrName} | pos `isInsideSrcSpan` l' = - let pprName = printOutputable rdrName - pprNameText = T.pack pprName + let pprNameText = printOutputable rdrName + pprName = show pprNameText unfoldRewrite restrictToOriginatingFile = let rewrites = [Unfold (qualify ms_mod pprName)] description = "Unfold " <> pprNameText <> describeRestriction restrictToOriginatingFile @@ -273,8 +273,8 @@ suggestTypeRewrites :: TyClDecl pass -> [(T.Text, CodeActionKind, RunRetrieParams)] suggestTypeRewrites originatingFile ms_mod SynDecl {tcdLName = L _ rdrName} = - let pprName = printOutputable rdrName - pprNameText = T.pack pprName + let pprNameText = printOutputable rdrName + pprName = show pprNameText unfoldRewrite restrictToOriginatingFile = let rewrites = [TypeForward (qualify ms_mod pprName)] description = "Unfold " <> pprNameText <> describeRestriction restrictToOriginatingFile @@ -330,7 +330,7 @@ suggestRuleRewrites originatingFile pos ms_mod (L _ HsRules {rds_rules}) = suggestRuleRewrites _ _ _ _ = [] qualify :: GHC.Module -> String -> String -qualify ms_mod x = printOutputable ms_mod <> "." <> x +qualify ms_mod x = show (printOutputable ms_mod) <> "." <> x ------------------------------------------------------------------------------- -- Retrie driving code diff --git a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs index e2e150e931..73e95a974a 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs @@ -31,7 +31,7 @@ unsafeRender = unsafeRender' . ppr unsafeRender' :: SDoc -> String unsafeRender' sdoc = unsafePerformIO $ do - let z = printOutputable sdoc + let z = show $ printOutputable sdoc -- We might not have unsafeGlobalDynFlags (like during testing), in which -- case GHC panics. Instead of crashing, let's just fail to print. !res <- try @PlainGhcException $ evaluate $ deepseq z z From 4308b75a46f9188ad85974a4ed502be5240cfdf9 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Wed, 20 Apr 2022 18:19:13 +0800 Subject: [PATCH 09/12] Remove redundant import --- ghcide/src/Development/IDE/Plugin/CodeAction.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction.hs b/ghcide/src/Development/IDE/Plugin/CodeAction.hs index 249214081f..e1f1314e81 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction.hs @@ -50,8 +50,7 @@ import Development.IDE.GHC.Error import Development.IDE.GHC.ExactPrint import Development.IDE.GHC.Util (printOutputable, printRdrName, - traceAst, - printOutputable) + traceAst) import Development.IDE.Plugin.CodeAction.Args import Development.IDE.Plugin.CodeAction.ExactPrint import Development.IDE.Plugin.CodeAction.PositionIndexed From 32edde4cd41cc68eb82336400cb09411f0a80bce Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Wed, 20 Apr 2022 23:55:10 +0800 Subject: [PATCH 10/12] Replace show with unpack --- ghcide/src/Development/IDE/GHC/Orphans.hs | 23 +++++++-------- ghcide/src/Development/IDE/GHC/Util.hs | 2 +- .../src/Development/IDE/Plugin/CodeAction.hs | 28 +++++++++---------- .../IDE/Plugin/CodeAction/ExactPrint.hs | 2 +- .../src/Ide/Plugin/Eval/CodeLens.hs | 2 +- .../src/Ide/Plugin/Eval/GHC.hs | 5 ++-- .../src/Ide/Plugin/ExplicitImports.hs | 2 +- .../src/Ide/Plugin/Retrie.hs | 8 +++--- .../hls-tactics-plugin/src/Wingman/Debug.hs | 3 +- 9 files changed, 39 insertions(+), 36 deletions(-) diff --git a/ghcide/src/Development/IDE/GHC/Orphans.hs b/ghcide/src/Development/IDE/GHC/Orphans.hs index 125f3f17d1..11905b22d1 100644 --- a/ghcide/src/Development/IDE/GHC/Orphans.hs +++ b/ghcide/src/Development/IDE/GHC/Orphans.hs @@ -39,6 +39,7 @@ import Data.Aeson import Data.Bifunctor (Bifunctor (..)) import Data.Hashable import Data.String (IsString (fromString)) +import Data.Text (unpack) #if MIN_VERSION_ghc(9,0,0) import GHC.ByteCode.Types #else @@ -46,27 +47,27 @@ import ByteCodeTypes #endif -- Orphan instances for types from the GHC API. -instance Show CoreModule where show = show . printOutputable +instance Show CoreModule where show = unpack . printOutputable instance NFData CoreModule where rnf = rwhnf -instance Show CgGuts where show = show . printOutputable . cg_module +instance Show CgGuts where show = unpack . printOutputable . cg_module instance NFData CgGuts where rnf = rwhnf instance Show ModDetails where show = const "" instance NFData ModDetails where rnf = rwhnf instance NFData SafeHaskellMode where rnf = rwhnf -instance Show Linkable where show = show . printOutputable +instance Show Linkable where show = unpack . printOutputable instance NFData Linkable where rnf (LM a b c) = rnf a `seq` rnf b `seq` rnf c instance NFData Unlinked where rnf (DotO f) = rnf f rnf (DotA f) = rnf f rnf (DotDLL f) = rnf f rnf (BCOs a b) = seqCompiledByteCode a `seq` liftRnf rwhnf b -instance Show PackageFlag where show = show . printOutputable -instance Show InteractiveImport where show = show . printOutputable -instance Show PackageName where show = show . printOutputable +instance Show PackageFlag where show = unpack . printOutputable +instance Show InteractiveImport where show = unpack . printOutputable +instance Show PackageName where show = unpack . printOutputable #if !MIN_VERSION_ghc(9,0,1) -instance Show ComponentId where show = show . printOutputable -instance Show SourcePackageId where show = show . printOutputable +instance Show ComponentId where show = unpack . printOutputable +instance Show SourcePackageId where show = unpack . printOutputable instance Show GhcPlugins.InstalledUnitId where show = installedUnitIdString @@ -76,7 +77,7 @@ instance NFData GhcPlugins.InstalledUnitId where rnf = rwhnf . installedUnitIdFS instance Hashable GhcPlugins.InstalledUnitId where hashWithSalt salt = hashWithSalt salt . installedUnitIdString #else -instance Show UnitId where show = show . printOutputable +instance Show UnitId where show = unpack . printOutputable deriving instance Ord SrcSpan deriving instance Ord UnhelpfulSpanReason #endif @@ -86,7 +87,7 @@ instance NFData SB.StringBuffer where rnf = rwhnf instance Show Module where show = moduleNameString . moduleName -instance Outputable a => Show (GenLocated SrcSpan a) where show = show . printOutputable +instance Outputable a => Show (GenLocated SrcSpan a) where show = unpack . printOutputable instance (NFData l, NFData e) => NFData (GenLocated l e) where rnf (L l e) = rnf l `seq` rnf e @@ -207,5 +208,5 @@ instance (NFData (HsModule a)) where #endif rnf = rwhnf -instance Show OccName where show = show . printOutputable +instance Show OccName where show = unpack . printOutputable instance Hashable OccName where hashWithSalt s n = hashWithSalt s (getKey $ getUnique n) diff --git a/ghcide/src/Development/IDE/GHC/Util.hs b/ghcide/src/Development/IDE/GHC/Util.hs index 3f44863f65..0ddd12faf6 100644 --- a/ghcide/src/Development/IDE/GHC/Util.hs +++ b/ghcide/src/Development/IDE/GHC/Util.hs @@ -132,7 +132,7 @@ bytestringToStringBuffer (PS buf cur len) = StringBuffer{..} -- | Pretty print a 'RdrName' wrapping operators in parens printRdrName :: RdrName -> String -printRdrName name = show $ printOutputable $ parenSymOcc rn (ppr rn) +printRdrName name = T.unpack $ printOutputable $ parenSymOcc rn (ppr rn) where rn = rdrNameOcc name diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction.hs b/ghcide/src/Development/IDE/Plugin/CodeAction.hs index e1f1314e81..b939c46538 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction.hs @@ -544,7 +544,7 @@ suggestDeleteUnusedBinding isTheBinding span = srcSpanToRange span == Just _range isSameName :: IdP GhcPs -> String -> Bool - isSameName x name = show (printOutputable x) == name + isSameName x name = T.unpack (printOutputable x) == name data ExportsAs = ExportName | ExportPattern | ExportFamily | ExportAll deriving (Eq) @@ -1045,12 +1045,12 @@ disambiguateSymbol pm fileContents Diagnostic {..} (T.unpack -> symbol) = \case in Right <$> [ if parensed then Rewrite (rangeToSrcSpan "" _range) $ \df -> liftParseAST @(HsExpr GhcPs) df $ - show $ printOutputable $ + T.unpack $ printOutputable $ HsVar @GhcPs noExtField $ reLocA $ L (mkGeneralSrcSpan "") rdr else Rewrite (rangeToSrcSpan "" _range) $ \df -> liftParseAST @RdrName df $ - show $ printOutputable $ L (mkGeneralSrcSpan "") rdr + T.unpack $ printOutputable $ L (mkGeneralSrcSpan "") rdr ] findImportDeclByRange :: [LImportDecl GhcPs] -> Range -> Maybe (LImportDecl GhcPs) findImportDeclByRange xs range = find (\(L (locA -> l) _)-> srcSpanToRange l == Just range) xs @@ -1615,32 +1615,32 @@ smallerRangesForBindingExport lies b = b' = wrapOperatorInParens . unqualify $ b #if !MIN_VERSION_ghc(9,2,0) ranges' (L _ (IEThingWith _ thing _ inners labels)) - | show (printOutputable thing) == b' = [] + | T.unpack (printOutputable thing) == b' = [] | otherwise = - [ locA l' | L l' x <- inners, show (printOutputable x) == b'] - ++ [ l' | L l' x <- labels, show (printOutputable x) == b'] + [ locA l' | L l' x <- inners, T.unpack (printOutputable x) == b'] + ++ [ l' | L l' x <- labels, T.unpack (printOutputable x) == b'] #else ranges' (L _ (IEThingWith _ thing _ inners)) - | show (printOutputable thing) == b' = [] + | T.unpack (printOutputable thing) == b' = [] | otherwise = - [ locA l' | L l' x <- inners, show (printOutputable x) == b'] + [ locA l' | L l' x <- inners, T.unpack (printOutputable x) == b'] #endif ranges' _ = [] rangesForBinding' :: String -> LIE GhcPs -> [SrcSpan] -rangesForBinding' b (L (locA -> l) x@IEVar{}) | show (printOutputable x) == b = [l] -rangesForBinding' b (L (locA -> l) x@IEThingAbs{}) | show (printOutputable x) == b = [l] -rangesForBinding' b (L (locA -> l) (IEThingAll _ x)) | show (printOutputable x) == b = [l] +rangesForBinding' b (L (locA -> l) x@IEVar{}) | T.unpack (printOutputable x) == b = [l] +rangesForBinding' b (L (locA -> l) x@IEThingAbs{}) | T.unpack (printOutputable x) == b = [l] +rangesForBinding' b (L (locA -> l) (IEThingAll _ x)) | T.unpack (printOutputable x) == b = [l] #if !MIN_VERSION_ghc(9,2,0) rangesForBinding' b (L l (IEThingWith _ thing _ inners labels)) #else rangesForBinding' b (L (locA -> l) (IEThingWith _ thing _ inners)) #endif - | show (printOutputable thing) == b = [l] + | T.unpack (printOutputable thing) == b = [l] | otherwise = - [ locA l' | L l' x <- inners, show (printOutputable x) == b] + [ locA l' | L l' x <- inners, T.unpack (printOutputable x) == b] #if !MIN_VERSION_ghc(9,2,0) - ++ [ l' | L l' x <- labels, show (printOutputable x) == b] + ++ [ l' | L l' x <- labels, T.unpack (printOutputable x) == b] #endif rangesForBinding' _ _ = [] diff --git a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs index b958be33c2..1e6675275d 100644 --- a/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs +++ b/ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs @@ -542,7 +542,7 @@ addCommaInImportList lies x = do #endif unIEWrappedName :: IEWrappedName (IdP GhcPs) -> String -unIEWrappedName (occName -> occ) = show $ printOutputable $ parenSymOcc occ (ppr occ) +unIEWrappedName (occName -> occ) = T.unpack $ printOutputable $ parenSymOcc occ (ppr occ) hasParen :: String -> Bool hasParen ('(' : _) = True diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index 7e069f798b..70d7c7d130 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -522,7 +522,7 @@ evals mark_exception (st, fp) df stmts = do prettyWarn :: Warn -> String prettyWarn Warn{..} = - show (printOutputable $ SrcLoc.getLoc warnMsg) <> ": warning:\n" + T.unpack (printOutputable $ SrcLoc.getLoc warnMsg) <> ": warning:\n" <> " " <> SrcLoc.unLoc warnMsg runGetSession :: MonadIO m => IdeState -> NormalizedFilePath -> m HscEnv diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs index 9224594501..68ea0a4050 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/GHC.hs @@ -16,6 +16,7 @@ module Ide.Plugin.Eval.GHC ( import Data.List (isPrefixOf) import Data.Maybe (mapMaybe) import Data.String (fromString) +import qualified Data.Text as T import Development.IDE.GHC.Compat import Development.IDE.GHC.Compat.Util import qualified Development.IDE.GHC.Compat.Util as EnumSet @@ -67,7 +68,7 @@ pkgNames_ = mapMaybe ( \case ExposePackage _ (PackageArg n) _ -> Just n - ExposePackage _ (UnitIdArg uid) _ -> Just $ show $ printOutputable uid + ExposePackage _ (UnitIdArg uid) _ -> Just $ T.unpack $ printOutputable uid _ -> Nothing ) @@ -148,7 +149,7 @@ deriving instance Read Extension -- Partial display of DynFlags contents, for testing purposes showDynFlags :: DynFlags -> String showDynFlags df = - show . printOutputable . vcat . map (\(n, d) -> text (n ++ ": ") <+> d) $ + T.unpack . printOutputable . vcat . map (\(n, d) -> text (n ++ ": ") <+> d) $ [ ("extensions", ppr . extensions $ df) , ("extensionFlags", ppr . EnumSet.toList . extensionFlags $ df) , ("importPaths", vList $ importPaths df) diff --git a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs index 45b125414d..09743f7e0c 100644 --- a/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs +++ b/plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs @@ -197,7 +197,7 @@ exportedModuleStrings :: ParsedModule -> [String] exportedModuleStrings ParsedModule{pm_parsed_source = L _ HsModule{..}} | Just export <- hsmodExports, exports <- unLoc export - = map (show . printOutputable) exports + = map (T.unpack . printOutputable) exports exportedModuleStrings _ = [] minimalImportsRule :: Recorder (WithPriority Log) -> Rules () diff --git a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs index 3ea4e7a2c7..8075282807 100644 --- a/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs +++ b/plugins/hls-retrie-plugin/src/Ide/Plugin/Retrie.hs @@ -167,7 +167,7 @@ runRetrieCmd state RunRetrieParams{originatingFile = uri, ..} = extractImports :: ModSummary -> [HsBindLR GhcRn GhcRn] -> RewriteSpec -> [ImportSpec] extractImports ModSummary{ms_mod} topLevelBinds (Unfold thing) | Just FunBind {fun_matches} - <- find (\case FunBind{fun_id = L _ n} -> show (printOutputable n) == thing ; _ -> False) topLevelBinds + <- find (\case FunBind{fun_id = L _ n} -> T.unpack (printOutputable n) == thing ; _ -> False) topLevelBinds , names <- listify p fun_matches = [ AddImport {..} @@ -250,7 +250,7 @@ suggestBindRewrites :: suggestBindRewrites originatingFile pos ms_mod FunBind {fun_id = L l' rdrName} | pos `isInsideSrcSpan` l' = let pprNameText = printOutputable rdrName - pprName = show pprNameText + pprName = T.unpack pprNameText unfoldRewrite restrictToOriginatingFile = let rewrites = [Unfold (qualify ms_mod pprName)] description = "Unfold " <> pprNameText <> describeRestriction restrictToOriginatingFile @@ -274,7 +274,7 @@ suggestTypeRewrites :: [(T.Text, CodeActionKind, RunRetrieParams)] suggestTypeRewrites originatingFile ms_mod SynDecl {tcdLName = L _ rdrName} = let pprNameText = printOutputable rdrName - pprName = show pprNameText + pprName = T.unpack pprNameText unfoldRewrite restrictToOriginatingFile = let rewrites = [TypeForward (qualify ms_mod pprName)] description = "Unfold " <> pprNameText <> describeRestriction restrictToOriginatingFile @@ -330,7 +330,7 @@ suggestRuleRewrites originatingFile pos ms_mod (L _ HsRules {rds_rules}) = suggestRuleRewrites _ _ _ _ = [] qualify :: GHC.Module -> String -> String -qualify ms_mod x = show (printOutputable ms_mod) <> "." <> x +qualify ms_mod x = T.unpack (printOutputable ms_mod) <> "." <> x ------------------------------------------------------------------------------- -- Retrie driving code diff --git a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs index 73e95a974a..e637779824 100644 --- a/plugins/hls-tactics-plugin/src/Wingman/Debug.hs +++ b/plugins/hls-tactics-plugin/src/Wingman/Debug.hs @@ -18,6 +18,7 @@ module Wingman.Debug import Control.DeepSeq import Control.Exception import Data.Either (fromRight) +import qualified Data.Text as T import qualified Debug.Trace import Development.IDE.GHC.Compat (PlainGhcException, Outputable(..), SDoc) import Development.IDE.GHC.Util (printOutputable) @@ -31,7 +32,7 @@ unsafeRender = unsafeRender' . ppr unsafeRender' :: SDoc -> String unsafeRender' sdoc = unsafePerformIO $ do - let z = show $ printOutputable sdoc + let z = T.unpack $ printOutputable sdoc -- We might not have unsafeGlobalDynFlags (like during testing), in which -- case GHC panics. Instead of crashing, let's just fail to print. !res <- try @PlainGhcException $ evaluate $ deepseq z z From 04856adadfdd6212b788189e594e59c31858dcae Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sun, 24 Apr 2022 14:05:33 +0800 Subject: [PATCH 11/12] Rerun tests From bf53d21bf20b4788471f50bfa5b43df0c486f6d4 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Wed, 27 Apr 2022 12:57:48 +0800 Subject: [PATCH 12/12] Rerun tests