From 8e33dbd88ded6e1166cd26be40db2ee68903329f Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Mon, 14 Mar 2016 21:16:20 +0300 Subject: [PATCH 1/3] [Browse] Option to show symbol parents E.g. Nothing is a constructor of Maybe, so it has parent Maybe. This is useful for completion, e.g. with `(..)` imports --- Language/Haskell/GhcMod/Boot.hs | 3 ++- Language/Haskell/GhcMod/Browse.hs | 15 +++++++++++---- Language/Haskell/GhcMod/Types.hs | 4 +++- src/GHCMod/Options/Commands.hs | 4 ++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Language/Haskell/GhcMod/Boot.hs b/Language/Haskell/GhcMod/Boot.hs index 7399de1..b4652c7 100644 --- a/Language/Haskell/GhcMod/Boot.hs +++ b/Language/Haskell/GhcMod/Boot.hs @@ -7,12 +7,13 @@ import Language.Haskell.GhcMod.Flag import Language.Haskell.GhcMod.Lang import Language.Haskell.GhcMod.Monad import Language.Haskell.GhcMod.Modules +import Language.Haskell.GhcMod.Types (defaultBrowseOpts) -- | Printing necessary information for front-end booting. boot :: IOish m => GhcModT m String boot = concat <$> sequence ms where - ms = [modules False, languages, flags, concat <$> mapM (browse (BrowseOpts False False False)) preBrowsedModules] + ms = [modules False, languages, flags, concat <$> mapM (browse defaultBrowseOpts) preBrowsedModules] preBrowsedModules :: [String] preBrowsedModules = [ diff --git a/Language/Haskell/GhcMod/Browse.hs b/Language/Haskell/GhcMod/Browse.hs index 05bc969..0da75e4 100644 --- a/Language/Haskell/GhcMod/Browse.hs +++ b/Language/Haskell/GhcMod/Browse.hs @@ -11,6 +11,7 @@ import Data.List import Data.Maybe import FastString import GHC +import HscTypes import qualified GHC as G import Language.Haskell.GhcMod.Convert import Language.Haskell.GhcMod.Doc (showPage, styleUnqualified) @@ -96,14 +97,20 @@ showExport opt minfo e = do mqualified = (G.moduleNameString (G.moduleName $ G.nameModule e) ++ ".") `justIf` optBrowseQualified opt mtype :: m (Maybe String) mtype - | optBrowseDetailed opt = do + | optBrowseDetailed opt || optBrowseParents opt = do tyInfo <- G.modInfoLookupName minfo e -- If nothing found, load dependent module and lookup global tyResult <- maybe (inOtherModule e) (return . Just) tyInfo dflag <- G.getSessionDynFlags - return $ do - typeName <- tyResult >>= showThing dflag - (" :: " ++ typeName) `justIf` optBrowseDetailed opt + let sig = do + typeName <- tyResult >>= showThing dflag + (" :: " ++ typeName) `justIf` optBrowseDetailed opt + let parent = do + thing <- fmap getOccString $ tyResult >>= tyThingParent_maybe + (" ; " ++ thing) `justIf` optBrowseParents opt + return $ case concat $ catMaybes [sig, parent] of + [] -> Nothing + x -> Just x | otherwise = return Nothing formatOp nm | null nm = error "formatOp" diff --git a/Language/Haskell/GhcMod/Types.hs b/Language/Haskell/GhcMod/Types.hs index 2281ba9..26ac585 100644 --- a/Language/Haskell/GhcMod/Types.hs +++ b/Language/Haskell/GhcMod/Types.hs @@ -388,13 +388,15 @@ data BrowseOpts = BrowseOpts { -- ^ If 'True', "browseWith" also returns operators. , optBrowseDetailed :: Bool -- ^ If 'True', "browseWith" also returns types. + , optBrowseParents :: Bool + -- ^ If 'True', "browseWith" also returns parents. , optBrowseQualified :: Bool -- ^ If 'True', "browseWith" will return fully qualified name } deriving (Show) -- | Default "BrowseOpts" instance defaultBrowseOpts :: BrowseOpts -defaultBrowseOpts = BrowseOpts False False False +defaultBrowseOpts = BrowseOpts False False False False mkLabel ''GhcModCaches mkLabel ''GhcModState diff --git a/src/GHCMod/Options/Commands.hs b/src/GHCMod/Options/Commands.hs index a2ab3c0..a02c33b 100644 --- a/src/GHCMod/Options/Commands.hs +++ b/src/GHCMod/Options/Commands.hs @@ -255,6 +255,10 @@ browseArgSpec = CmdBrowse $$ long "detailed" <=> short 'd' <=> help "Print symbols with accompanying signature" + <*> switch + $$ long "parents" + <=> short 'p' + <=> help "Print symbols parents" <*> switch $$ long "qualified" <=> short 'q' From 32b18d915b1530a48e45e8dcd9acbd9c13b9faad Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Wed, 11 May 2016 16:53:42 +0300 Subject: [PATCH 2/3] [Browse] Use '--' as parent separator --- Language/Haskell/GhcMod/Browse.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Language/Haskell/GhcMod/Browse.hs b/Language/Haskell/GhcMod/Browse.hs index 0da75e4..7c8b4a3 100644 --- a/Language/Haskell/GhcMod/Browse.hs +++ b/Language/Haskell/GhcMod/Browse.hs @@ -107,7 +107,7 @@ showExport opt minfo e = do (" :: " ++ typeName) `justIf` optBrowseDetailed opt let parent = do thing <- fmap getOccString $ tyResult >>= tyThingParent_maybe - (" ; " ++ thing) `justIf` optBrowseParents opt + (" -- " ++ thing) `justIf` optBrowseParents opt return $ case concat $ catMaybes [sig, parent] of [] -> Nothing x -> Just x From 5a02721fc8161127932a4048a31d251b52214beb Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Wed, 11 May 2016 16:58:46 +0300 Subject: [PATCH 3/3] [Browse] Add 'from:' to parents --- Language/Haskell/GhcMod/Browse.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Language/Haskell/GhcMod/Browse.hs b/Language/Haskell/GhcMod/Browse.hs index 7c8b4a3..882e4ac 100644 --- a/Language/Haskell/GhcMod/Browse.hs +++ b/Language/Haskell/GhcMod/Browse.hs @@ -107,7 +107,7 @@ showExport opt minfo e = do (" :: " ++ typeName) `justIf` optBrowseDetailed opt let parent = do thing <- fmap getOccString $ tyResult >>= tyThingParent_maybe - (" -- " ++ thing) `justIf` optBrowseParents opt + (" -- from:" ++ thing) `justIf` optBrowseParents opt return $ case concat $ catMaybes [sig, parent] of [] -> Nothing x -> Just x