Skip to content

Commit

Permalink
Merge pull request #10 from afcowie/file-names
Browse files Browse the repository at this point in the history
Add entry for file names
  • Loading branch information
luqui committed Jan 18, 2013
2 parents 7a43e82 + dfcff0a commit 7d571b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import qualified Language.Preprocessor.Cpphs as CPP
import Control.Monad (forM, when)
import Data.List (sort)
import Data.Maybe (fromMaybe)
import System.FilePath.Posix (takeFileName)

type Database = Map.Map String (L.Module L.SrcSpanInfo)

Expand Down Expand Up @@ -119,11 +120,19 @@ exported mod@(L.Module _ (Just (L.ModuleHead _ _ _ (Just (L.ExportSpecList _ spe
exported _ _ = True

moduleScope :: Database -> L.Module L.SrcSpanInfo -> Map.Map String Defn
moduleScope db mod@(L.Module _ modhead _ imports _) = moduleItself modhead `Map.union` localDecls mod `Map.union` Map.unions (map extractImport imports)
moduleScope db mod@(L.Module _ modhead _ imports _) = moduleItself `Map.union` localDecls mod `Map.union` Map.unions (map extractImport imports)
where
moduleItself (Just (L.ModuleHead l (L.ModuleName _ name) _ _)) = Map.singleton name (getLoc l)
moduleItself _ = Map.empty

moduleItself = moduleDecl modhead `Map.union` enclosingFilename mod

moduleDecl (Just (L.ModuleHead l (L.ModuleName _ name) _ _)) = Map.singleton name (getLoc l)
moduleDecl _ = Map.empty

enclosingFilename (L.Module l _ _ _ _) = Map.singleton (filename l) (getLoc l)
enclosingFilename _ = Map.empty

filename (L.SrcSpanInfo (L.SrcSpan file _ _ _ _) _) = takeFileName file

extractImport decl@(L.ImportDecl { L.importModule = L.ModuleName _ name, L.importSpecs = spec }) =
Map.unions [
if L.importQualified decl then Map.empty else names,
Expand Down
1 change: 1 addition & 0 deletions hothasktags.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ executable hothasktags
build-depends:
base == 4.*,
containers,
filepath,
haskell-src-exts >= 1.11 && < 1.14,
cpphs >= 1.11 && < 1.15
main-is: Main.hs
Expand Down

0 comments on commit 7d571b6

Please sign in to comment.