haskdogs 0.5.3 → 0.5.4
raw patch · 3 files changed
+64/−39 lines, 3 files
Files
- README.md +31/−27
- haskdogs.cabal +1/−1
- src/Main.hs +32/−11
README.md view
@@ -1,14 +1,15 @@ HaskDogs ======== -Haskdogs is a shellscript-like tool which creates tag file for entire-haskell project directory. It takes into account first-level dependencies by-recursively scanning imports and adding matching packages to the final-tag list.+Haskdogs is a shellscript-like tool which creates tag file for entire haskell+project directory. It takes into account first-level dependencies by recursively+scanning imports and adding matching projects to the dependency list. Next,+Haskdogs uses cabal or stack to unpack their sources into a temporary directory,+which is `~/.haskdogs` by default. Finally, hasktags is called to produce the+`tags` file. -As a result, programmer can use his/her text editor supporting tags (vim, for-example) to jump directly to definition of any standard or foreign function-he/she uses.+As a result, programmer can use his/her text editor supporting tags (e.g. vim)+to jump directly to definition of any standard or foreign function he/she uses. Note, that haskdogs relies on some GNU programs as well as on Unix shell commands such as 'cd', 'mkdir' and so on. Also it would run 'stack' and ghc-pkg'@@ -33,34 +34,41 @@ 2. cd to your Haskell project dir - $ cd $HOME/my-haskell-project+ $ cd $HOME/my-haskell-project 3. Run haskdogs without arguments to generate tags file in Vim-compatible format - $ haskdogs+ $ haskdogs Emacs users would probably want to add -e hasktags option to build Emacs-compatible TAGS. -- $ haskdogs --help haskdogs - Recursive hasktags-based TAGS generator for a Haskell project Usage: haskdogs [--version] [-d|--dir-list FILE] [-f|--file-list FILE]- [--hasktags-args OPTS] [--ghc-pkg-args OPTS] [--use-stack ARG]- [OPTS]+ [--hasktags-args OPTS] [--stack-args OPTS] [--ghc-pkg-args OPTS]+ [--use-stack ARG] [--deps-dir PATH] [--raw] [OPTS] Available options: -h,--help Show this help text --version Show version number- -d,--dir-list FILE File containing directory list to process- -f,--file-list FILE File containing Haskell sources to process- --hasktags-args OPTS Arguments to pass to hasktags. -c -x is the default+ -d,--dir-list FILE File containing directory list to process (use '-' to+ read from stdin)+ -f,--file-list FILE File containing Haskell sources to process (use '-'+ to read from stdin)+ --hasktags-args OPTS Arguments to pass to hasktags. -c -x is the default.+ Not for raw mode.+ --stack-args OPTS Arguments to pass to stack --ghc-pkg-args OPTS Arguments to pass to ghc-pkgs --use-stack ARG Execute ghc-pkg via stack, arg is ON, OFF or AUTO (the default)+ --deps-dir PATH Specify the directory PATH to place the dependencies+ of the project. Default is [/home/grwlf/.haskdogs]+ --raw Don't execute hasktags, print list of files to tag on+ the STDOUT. The output may be piped into hasktags+ like this: `haskdogs --raw | hasktags -c -x STDIN' OPTS More hasktags options, use `--' to pass flags- starting with `-'+ starting with `-'. Not for raw mode. The following error could be caused by (over)strict Haskell policy regarding@@ -113,17 +121,13 @@ Just copy the code above to your ~/.vimrc and reload the vim. -NIXOS Note-------------The easiest way to generate tags file on NixOS is to open a shell containing-neccesary programs. Nix-shell should do it if run as follows:-- nix-shell -p haskellPackages.haskdogs haskellPackages.hasktags haskellPackages.Cabal ghc+NIX NOTE+-------- +The easiest way to generate Hakell tags on [Nix](https://nixos.org/nix)-machine+is to run Haskdogs from `nix-shell` as follows: ----Sergey-<grrwlf@gmail.com>+ nix-shell -p haskellPackages.haskdogs haskellPackages.hasktags haskellPackages.cabal-install ghc+ (nix-shell) $ haskdogs
haskdogs.cabal view
@@ -1,5 +1,5 @@ Name: haskdogs-Version: 0.5.3+Version: 0.5.4 Synopsis: Generate tags file for Haskell project and its nearest deps Homepage: http://github.com/grwlf/haskdogs License: BSD3
src/Main.hs view
@@ -36,6 +36,7 @@ , cli_ghc_pkgs_args :: String , cli_use_stack :: Tristate , cli_deps_dir :: FilePath+ , cli_raw_mode :: Bool -- , cli_use_sandbox :: Tristate , cli_hasktags_args2 :: [String] } deriving(Show)@@ -63,7 +64,7 @@ long "hasktags-args" <> metavar "OPTS" <> value "" <>- help ("Arguments to pass to hasktags. " ++ unwords def_hasktags_args ++ " is the default"))+ help ("Arguments to pass to hasktags. " ++ unwords def_hasktags_args ++ " is the default. Not for raw mode.")) <*> strOption ( long "stack-args" <> metavar "OPTS" <>@@ -82,12 +83,15 @@ long "deps-dir" <> metavar "PATH" <> value def_deps_dir <>- help ("Specify the directory PATH to save the dependencies of the project. Default is [" <> def_deps_dir <> "]"))+ help ("Specify the directory PATH to place the dependencies of the project. Default is [" <> def_deps_dir <> "]"))+ <*> flag False True (+ long "raw" <>+ help "Don't execute hasktags, print list of files to tag on the STDOUT. The output may be piped into hasktags like this: `haskdogs --raw | hasktags -c -x STDIN'") -- <*> option auto ( -- long "include-sandbox" <> -- value AUTO <> -- help "(!UNIMPLEMENTED!) Include .cabal-sandbox package databases")- <*> many (argument str (metavar "OPTS" <> help "More hasktags options, use `--' to pass flags starting with `-'"))+ <*> many (argument str (metavar "OPTS" <> help "More hasktags options, use `--' to pass flags starting with `-'. Not for raw mode.")) exename :: String exename = "haskdogs"@@ -116,6 +120,8 @@ Opts {..} <- execParser (opts def_deps_dir) let+ cli_hasktags_args = (words cli_hasktags_args1) ++ cli_hasktags_args2+ -- Directory to unpack sources into getDataDir :: IO FilePath getDataDir = do@@ -146,9 +152,13 @@ (runp "which" [appname] [] >> return True) `catch` (\(e::SomeException) -> vprint ("GNU which falied to find " ++ appname) >> return False) + when ((not $ null cli_hasktags_args) && cli_raw_mode) $ do+ fail $ "--raw is incompatible with passing hasktags arguments"+ cwd <- getCurrentDirectory datadir <- getDataDir has_stack <- hasapp "stack"+ has_cabal <- hasapp "cabal" let @@ -169,17 +179,23 @@ | null cli_filelist_file = return Set.empty | otherwise = Set.fromList <$> readLinedFile cli_filelist_file - cli_hasktags_args = (words cli_hasktags_args1) ++ cli_hasktags_args2- runp_ghc_pkgs args = go cli_use_stack where go ON = runp "stack" (["exec", "ghc-pkg"] ++ (words cli_stack_args) ++ ["--"] ++ (words cli_ghc_pkgs_args) ++ args) [] go OFF = runp "ghc-pkg" (words cli_ghc_pkgs_args ++ args) []- go AUTO = if has_stack then go ON else go OFF+ go AUTO =+ case (has_stack,has_cabal) of+ (True,_) -> go ON+ (False,True) -> go OFF+ (False,False) -> fail "Either `stack` or `cabal` should be installed" cabal_or_stack = go cli_use_stack where go ON = "stack" go OFF = "cabal"- go AUTO = if has_stack then go ON else go OFF+ go AUTO =+ case (has_stack,has_cabal) of+ (True,_) -> go ON+ (False,True) -> go OFF+ (False,False) -> fail "Either `stack` or `cabal` should be installed" -- Finds *hs in dirs, but filter-out Setup.hs findSources :: [FilePath] -> IO (Set FilePath)@@ -238,10 +254,15 @@ fail $ "Haskdogs were not able to find any sources in " <> (intercalate ", " dirs) ss_l1deps <- findModules ss_local >>= inames2modules >>= unpackModules >>= findSources return $ ss_local `mappend` ss_l1deps- sfiles <- pure $ unlines $ Set.toList files- vprint sfiles- runp "hasktags" ((if null cli_hasktags_args then def_hasktags_args else cli_hasktags_args) ++ ["STDIN"]) sfiles- putStrLn "\nSuccess"+ case cli_raw_mode of+ True -> do+ forM_ (Set.toList files) $ \f-> do+ putStrLn f+ False -> do+ sfiles <- pure $ unlines $ Set.toList files+ vprint sfiles+ runp "hasktags" ((if null cli_hasktags_args then def_hasktags_args else cli_hasktags_args) ++ ["STDIN"]) sfiles+ putStrLn "\nSuccess" {- _real_main_ -} gentags