packages feed

haskdogs 0.2 → 0.3

raw patch · 3 files changed

+37/−22 lines, 3 files

Files

README view
@@ -10,9 +10,8 @@ example) to jump directly to definition of any standard or foreign function he/she uses. -Note, that haskdogs calls some Unix shell commands like 'test' or 'mkdir' via-SHS so this tool will probably work on Linuxes and maybe Macs. Pure Windows-will fail to run it.+Note, that haskdogs calls some Unix shell commands like 'test' or 'mkdir'+so this tool will run, but probably fail to work on pure Windows platforms.  INSTALL =======@@ -28,9 +27,8 @@  1. Make sure yoy have installed hasktags and put it in PATH. Hasktags is being called by haskdogs by name.  -2. Make shure that $HOME/.cabal/var/haskdogs does exist.-3. cd to your Haskell project dir-4. run haskdogs+2. cd to your Haskell project dir+3. run haskdogs (cmdline args will be passed to hasktags followed by a filelist generated)  -- Sergey 
haskdogs.cabal view
@@ -3,7 +3,7 @@ -- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr. -- The name of the package. Name:                haskdogs-Version:             0.2+Version:             0.3 Synopsis:            Generate ctags file for haskell project directory and it's deps Homepage:            http://github.com/ierton/haskdogs License:             BSD3@@ -24,9 +24,11 @@     example) to jump directly to definition of any standard or foreign function     he/she uses. -    Note, that haskdogs calls some Unix shell commands like 'test' or 'mkdir' via-    SHS so this tool will probably work on Linuxes and maybe Macs. Pure Windows-    will fail to run it.+    Note, that haskdogs calls some Unix shell commands like 'test' or 'mkdir'+    so this tool will likely fail to work on pure Windows platforms.++    Starting from 0.3, cmdline args will be passed to hasktags followed by a +    filelist generated.  Executable haskdogs   Hs-source-dirs:       src
src/haskdogs.hs view
@@ -1,23 +1,21 @@--- #!/usr/bin/runhaskell- import HSH import Data.List import Control.Monad import System.Exit+import System.Environment import System.FilePath -p :: String -> (String, [String])-p s = let ws = words s in (head ws, tail ws)- find_in_dirs dirs p = ("find", dirs ++ ["-name", p])  ghc_pkg_find m = ("ghc-pkg", ["find-module", m])  cabal_unpack p = ("cabal", ["unpack", p]) +-- Finds *hs in current dir, recursively findSources :: [String] -> IO [String] findSources d = run $ find_in_dirs d "*hs" +-- Produces list of imported modules for file.hs given findImports :: [String] -> IO [String] findImports s = run $ catFrom s -|- extractImports @@ -27,6 +25,7 @@ grepImports ("import":x:_) = x grepImports _ = [] +-- Maps import name to haskel package name iname2module :: String -> IO String iname2module m = run $ ghc_pkg_find m -|- egrep "^ +[a-zA-Z]" -|- map (head . words) -|- highver     where highver [] = []@@ -41,6 +40,7 @@         ExitSuccess -> fyes         _ -> fno +-- Unapcks haskel package to the sourcedir unpackModule p = do     srcdir <- sourcedir     let fullpath = srcdir </> p@@ -73,17 +73,32 @@ -- Directory to unpack sources into sourcedir = glob "~" >>= return . (</> ".haskdogs") . head -main :: IO ()-main = do+gentags flags = do     checkapp "cabal"     checkapp "ghc-pkg"     checkapp "hasktags"     d <- sourcedir     testdir d (return ()) (run ("mkdir",["-p",d]))-    cwd <- run "pwd" >>= return . head-    ss_local <- findSources ["."]-    ss_l1deps <- findImports ss_local >>= inames2modules >>= unpackModules >>= findSources-    cd cwd-    runIO $ ("hasktags", ["-c"] ++ ss_local ++ ss_l1deps)+    files <- bracketCD "." $ do+        ss_local <- findSources ["."]+        ss_l1deps <- findImports ss_local >>= inames2modules >>= unpackModules >>= findSources+        return $ ss_local ++ ss_l1deps+    runIO $ ("hasktags", flags ++ files) +help = do+    putStrLn "haskdogs: generates tags file for haskell project directory"+    putStrLn "Usage:"+    putStrLn "    haskdogs [FLAGS]"+    putStrLn "        FLAGS will be passed to hasktags as-is followed by"+    putStrLn "        a list of files. Defaults to -c."+    return ()++amain [] = gentags ["-c"]+amain ("-h":_) = help+amain ("-?":_) = help+amain ("--help":_) = help+amain flags = gentags flags++main :: IO()+main = getArgs >>= amain