packages feed

hothasktags 0.0.1 → 0.1.0

raw patch · 2 files changed

+47/−9 lines, 2 files

Files

Main.hs view
@@ -8,6 +8,7 @@ import qualified Data.Map as Map import Control.Monad (forM, when) import Data.List (sort)+import Data.Maybe (fromMaybe)  type Database = Map.Map String (L.Module L.SrcSpanInfo) @@ -19,10 +20,11 @@     where     extract (L.TypeDecl _ head _) = extractDeclHead head     extract (L.TypeFamDecl _ head _) = extractDeclHead head-    extract (L.DataDecl _ _ _ head _ _) = extractDeclHead head-    extract (L.GDataDecl _ _ _ head _ _ _) = extractDeclHead head+    extract (L.DataDecl _ _ _ head decls _) = extractDeclHead head ++ concatMap extractQualConDecl decls+    extract (L.GDataDecl _ _ _ head _ decls _) = extractDeclHead head ++ concatMap extractGadtDecl decls     extract (L.DataFamDecl _ _ head _) = extractDeclHead head-    extract (L.ClassDecl _ _ head _ _) = extractDeclHead head+    extract (L.ClassDecl _ _ head _ clsdecls) = extractDeclHead head ++ concatMap extractClassDecl (fromMaybe [] clsdecls)+    extract (L.TypeSig _ names _) = concatMap extractName names     extract (L.FunBind _ (L.Match _ name _ _ _ : _)) = extractName name     extract (L.FunBind _ (L.InfixMatch _ _ name _ _ _ : _)) = extractName name     extract (L.PatBind _ pat _ _ _) = extractPat pat@@ -44,6 +46,19 @@     extractPat (L.PBangPat _ pat) = extractPat pat     extractPat _ = [] +    extractQualConDecl (L.QualConDecl _ _ _ (L.ConDecl _ name _)) = extractName name+    extractQualConDecl (L.QualConDecl _ _ _ (L.RecDecl _ name fields)) = extractName name ++ concatMap extractFieldDecl fields+    extractQualConDecl _ = []++    extractFieldDecl (L.FieldDecl _ names _) = concatMap extractName names++    extractGadtDecl (L.GadtDecl _ name _) = extractName name++    extractClassDecl (L.ClsDecl _ decl) = extract decl+    extractClassDecl (L.ClsDataFam _ _ head _) = extractDeclHead head+    extractClassDecl (L.ClsTyFam _ head _) = extractDeclHead head+    extractClassDecl _ = []+     extractName (L.Ident loc name) = [(name, getLoc loc)]     extractName (L.Symbol _ _) = []   -- no symbols for now @@ -92,7 +107,7 @@     matchesSpec name (L.EAbs _ (L.UnQual _ (L.Ident _ name'))) = name == name'     matchesSpec name (L.EThingAll _ (L.UnQual _ (L.Ident _ name'))) = name == name' || (name `elem` thingMembers mod name')     matchesSpec name (L.EThingWith _ (L.UnQual _ (L.Ident _ name')) cnames) = name == name' || any (matchesCName name) cnames-    matchesSpec _    (L.EModuleContents _ _) = False  -- XXX do this!+    matchesSpec _ (L.EModuleContents _ (L.ModuleName _ _)) = False  -- XXX wrong, moduleScope handles it though     matchesSpec _ _ = False          matchesCName name (L.VarName _ (L.Ident _ name')) = name == name'@@ -101,7 +116,7 @@ exported _ _ = True  moduleScope :: Database -> L.Module L.SrcSpanInfo -> Map.Map String Defn-moduleScope db mod@(L.Module _ _ _ imports _) = localDecls mod `Map.union` Map.unions (map extractImport imports)+moduleScope db mod@(L.Module _ modhead _ imports _) = localDecls mod `Map.union` Map.unions (map extractImport imports)     where     extractImport decl@(L.ImportDecl { L.importModule = L.ModuleName _ name, L.importSpecs = spec }) =          Map.unions [@@ -109,7 +124,8 @@             Map.mapKeys ((name ++ ".") ++) names,             case L.importAs decl of                 Nothing -> Map.empty-                Just (L.ModuleName _ name') -> Map.mapKeys ((name' ++ ".") ++) names+                Just (L.ModuleName _ name') -> Map.mapKeys ((name' ++ ".") ++) names,+            extraExports         ]                  where@@ -121,13 +137,18 @@          specName (L.IVar _ (L.Ident _ name)) = [name]         specName (L.IAbs _ (L.Ident _ name)) = [name]-        specName (L.IThingAll _ (L.Ident _ name)) = [name]  -- incorrect, need its member names+        specName (L.IThingAll _ (L.Ident _ name)) = [name]  -- XXX incorrect, need its member names         specName (L.IThingWith _ (L.Ident _ name) cnames) = name : concatMap cname cnames         specName _ = []          cname (L.VarName _ (L.Ident _ name)) = [name]         cname (L.ConName _ (L.Ident _ name)) = [name]         cname _ = []++    extraExports | Just (L.ModuleHead _ _ _ (Just (L.ExportSpecList _ especs))) <- modhead =+            Map.unions [ modExports db modname | L.EModuleContents _ (L.ModuleName _ modname) <- especs ]+                | otherwise = Map.empty+ moduleScope _ _ = Map.empty  makeTag :: FilePath -> (String, Defn) -> String
hothasktags.cabal view
@@ -1,5 +1,5 @@ name: hothasktags-version: 0.0.1+version: 0.1.0 cabal-version: >= 1.6 && < 2 build-type: Simple author: Luke Palmer <lrpalmer@gmail.com>@@ -7,7 +7,24 @@ maintainer: Luke Palmer <lrpalmer@gmail.com> category: Development synopsis: Generates ctags for Haskell, incorporating import lists and qualified imports-description: Generation of ctags files for Haskell, with knowledge of import lists and qualified imports+description: +    hothasktags generates ctags files for Haskell, with knowledge of import lists +    and qualified imports.  It provides a smart go-to-definition for vim, that almost+    always gets it right in the presence of multiple names from different modules.+    +    You will want to configure vim to allow dots in keywords, because hothasktags+    generates tags for qualified names.  You can do this with:+    +    set iskeyword=a-z,A-Z,_,.,39+    +    (The 39 is for the prime character)+    +    Usage is easy, just give hothasktags the names of all the haskell sources you+    want to index and redirect into a tags file.  For example:+    +    find . | egrep '\.hs$' | xargs hothasktags > tags+    +    will index all the hs files under the current directory. homepage: http://github.com/luqui/hothasktags executable hothasktags     build-depends: