X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fghci%2FGhciTags.hs;h=9959991fab9297cb1a28b68bfef89ca6abd562aa;hb=131320a1b79d965540449927b640ab037fb7a13a;hp=686633e458c2dff875d42a1943614648483f4e8b;hpb=c5f6a3c65987b467cb64be30abd7a10ea6280b67;p=ghc-hetmet.git diff --git a/compiler/ghci/GhciTags.hs b/compiler/ghci/GhciTags.hs index 686633e..9959991 100644 --- a/compiler/ghci/GhciTags.hs +++ b/compiler/ghci/GhciTags.hs @@ -1,6 +1,6 @@ ----------------------------------------------------------------------------- -- --- GHCi's :ctags and :etags commands +-- GHCi's :ctags and :etags commands -- -- (c) The GHC Team 2005-2007 -- @@ -18,6 +18,7 @@ import Util import Name (nameOccName) import OccName (pprOccName) +import Data.Maybe import Control.Exception import Data.List import Control.Monad @@ -62,11 +63,13 @@ createTagsFile session tagskind tagFile = do ++ GHC.moduleNameString (GHC.moduleName m) ++ "' is not interpreted")) mbModInfo <- GHC.getModuleInfo session m - let unqual - | Just modinfo <- mbModInfo, - Just unqual <- GHC.modInfoPrintUnqualified modinfo = unqual - | otherwise = GHC.alwaysQualify - + unqual <- + case mbModInfo of + Just minf -> do + mb_print_unqual <- GHC.mkPrintUnqualifiedForModule session minf + return (fromMaybe GHC.alwaysQualify mb_print_unqual) + Nothing -> + return GHC.alwaysQualify case mbModInfo of Just modInfo -> return $! listTags unqual modInfo _ -> return [] @@ -81,7 +84,7 @@ listTags :: PrintUnqualified -> GHC.ModuleInfo -> [TagInfo] listTags unqual modInfo = [ tagInfo unqual name loc | name <- GHC.modInfoExports modInfo - , let loc = nameSrcLoc name + , let loc = srcSpanStart (nameSrcSpan name) , isGoodSrcLoc loc ] @@ -110,27 +113,26 @@ collateAndWriteTags ETags file tagInfos = do -- etags style, Emacs/XEmacs tagGroups <- mapM tagFileGroup groups IO.try (writeFile file $ concat tagGroups) where - tagFileGroup group@[] = throwDyn (CmdLineError "empty tag file group??") + tagFileGroup [] = throwDyn (CmdLineError "empty tag file group??") tagFileGroup group@((_,fileName,_,_):_) = do file <- readFile fileName -- need to get additional info from sources.. let byLine (_,_,l1,_) (_,_,l2,_) = l1 <= l2 sortedGroup = sortLe byLine group tags = unlines $ perFile sortedGroup 1 0 $ lines file return $ "\x0c\n" ++ fileName ++ "," ++ show (length tags) ++ "\n" ++ tags - perFile (tagInfo@(tag,file,lNo,colNo):tags) count pos (line:lines) | lNo>count = - perFile (tagInfo:tags) (count+1) (pos+length line) lines - perFile (tagInfo@(tag,file,lNo,colNo):tags) count pos lines@(line:_) | lNo==count = - showETag tagInfo line pos : perFile tags count pos lines - perFile tags count pos lines = [] + perFile (tagInfo@(_tag, _file, lNo, _colNo):tags) count pos lines@(line:lines') + | lNo > count = perFile (tagInfo:tags) (count+1) (pos+length line) lines' + | lNo == count = showETag tagInfo line pos : perFile tags count pos lines + perFile _ _ _ _ = [] -- simple ctags format, for Vim et al showTag :: TagInfo -> String -showTag (tag,file,lineNo,colNo) +showTag (tag, file, lineNo, _colNo) = tag ++ "\t" ++ file ++ "\t" ++ show lineNo -- etags format, for Emacs/XEmacs showETag :: TagInfo -> String -> Int -> String -showETag (tag,file,lineNo,colNo) line charPos +showETag (tag, _file, lineNo, colNo) line charPos = take colNo line ++ tag ++ "\x7f" ++ tag ++ "\x01" ++ show lineNo