gen_tags.vim icon indicating copy to clipboard operation
gen_tags.vim copied to clipboard

Support let g:gen_tags#find_tool options

Open d4em0n opened this issue 7 years ago • 20 comments

g:gen_tags#find_tool is a command that displays list filenames. When g:gen_tags#find_tool is set. gen_tags will use it for generating tags for list of filenames.

For example,

let g:gen_tags#find_tool = 'rg --files'

gen_tags will execute command rg --files | ctags -f /home/ramdhan/.cache/tags_dir/homeramdhanctftoolsgef/prj_tags -L- . rg --files command (ripgrep) can be used too for exclude filename/folder in .gitignore. #44

  • Support ctags only, i'am not use gtags.

d4em0n avatar Jun 30 '18 01:06 d4em0n

Thanks for the contribution, but I can't merge it right now. This PR is still too rough.

  1. It breaks on neovim.
  2. It only support ctags, I wish it can support gtags in the same time.
  3. It introduce the external dependence.
  4. It should works on different platform, like windows, linux and macOS.

Sorry, I don't have enough time to review and refine this PR, right now. Please keep it open and I'll look into it when I have some spare time.

Thanks again.

jsfaint avatar Jul 02 '18 02:07 jsfaint

Oh, this PR is releated to #44, BTW

jsfaint avatar Jul 02 '18 02:07 jsfaint

Why breaks neovim?, I'm using neovim, and it's works fine. We can using find with exclude options or git ls-files instead of ripgrep. ripgrep works on windows too. Thanks for your reply

d4em0n avatar Jul 02 '18 04:07 d4em0n

You should use gen_tags#opt_converter() to convert the option (list and string are both supported)

jsfaint avatar Jul 02 '18 06:07 jsfaint

The gtags can use the file list as below

rg --files | gtags -f -

jsfaint avatar Jul 02 '18 06:07 jsfaint

Check/Test the latest commit, i don't know if let l:cmd = ['cmd', '/c', join(a:cmd)] worked or not

d4em0n avatar Jul 03 '18 01:07 d4em0n

There is no need to add 'cmd' or 'sh' The command can work directly, for example

call jobstart(['rg', '--files', '|', 'gtags', '-f', '-'])

jsfaint avatar Jul 03 '18 01:07 jsfaint

In vim that's doesn't work, i tried this. For example :call job_start('echo hello > /tmp/b') this command doesn't work. But this command work for me :call job_start(["/bin/sh", "-c", "echo hello > /tmp/b"]). That's why im using sh

d4em0n avatar Jul 03 '18 01:07 d4em0n

:call job_start(["echo", "hello", ">", "/tmp/c"]) this command doesn't work too in vim.

d4em0n avatar Jul 03 '18 01:07 d4em0n

you can't redirect the stdout in job_start, because the stdout of job_start only appear in callback function.

jsfaint avatar Jul 03 '18 01:07 jsfaint

Don't know if job_start works using pipe |. This command doesn't work for me :call job_start(["echo", "hello", "|", "nc", "localhost" , "8080"]). It's work using :call job_start(["/bin/sh", "-c", "echo hello | nc localhost 8080"]). CMIIW

d4em0n avatar Jul 03 '18 01:07 d4em0n

I tried this code snippet, it works on windows and linux with vim8.1/neovim

function! s:job_stdout(job_id, data, ...) abort
  if type(a:data) == 1 "string
    echomsg a:data
  elseif type(a:data) == 3 "list
    for l:item in a:data
      echomsg l:item
    endfor
  endif
endfunction

function! s:job_start(cmd, ...) abort
  if has('nvim')
    let l:job = {
          \ 'on_stdout': function('s:job_stdout'),
          \ }

    let l:job_id = jobstart(a:cmd, l:job)
  elseif has('job')
    let l:job = {
          \ 'out_cb': function('s:job_stdout'),
          \ }

    let l:job_id = job_start(a:cmd, l:job)
  endif

  return l:job_id
endfunction

let s:list = ['ag', '-g', '""', '|', 'gtags', '-f', '-', '-v']

echomsg system(join(s:list))

call s:job_start(s:list)

jsfaint avatar Jul 03 '18 02:07 jsfaint

image oh... I got this error..

jsfaint avatar Jul 03 '18 03:07 jsfaint

yea, it's works in vim using system command. Above snippet doesn't work for me if i remove system line. It's should works in vim using job_start (without system command). Can you call job_start using s:list as argument directly in vim in your machine ?. sorry if im wrong

d4em0n avatar Jul 03 '18 03:07 d4em0n

How do you got that error ?

d4em0n avatar Jul 03 '18 03:07 d4em0n

I add a stderr callback to print the error message. I tried your code, it works with git ls-files, I don't have rg installed so I don't test with rg. I tested with ag, but it fail to work.

It's a little hard that the user set the find tool by themself correctly. Maybe we should remove g:gen_tags#find_tool option, and make it built-in?

gen_tags.vim detects the existing commands and use them directly. Support some commands like git ls-files, rg, ag, fd?

jsfaint avatar Jul 03 '18 03:07 jsfaint

I don't want remove g:gen_tags#find_tool. But if user not setting gen_tags#find_tool then gen_tags will detect existing command (like ag, rg) and set g:gen_tags#find_tool automatically. What do you think?

d4em0n avatar Jul 05 '18 02:07 d4em0n

The current code only works for rg and git ls-files

Some user may not use the rg like me. And both rg and git ls-files only works for the git repo.

If I merge this PR now, it will become my own dog food. I need to maintain it in future.

It's easy to introduce a new option, but it's hard to remove it or change the behavior later. Sorry, I can't merge it until I find a better way to handle it.

jsfaint avatar Jul 05 '18 06:07 jsfaint

It's ok if you can't merge it. I don't want my code breaks this repo. Do you want to close this PR or keep it open until this PR better?. Feel free to ask me if you need help.

d4em0n avatar Jul 05 '18 07:07 d4em0n

Please keep it open, thanks anyway

jsfaint avatar Jul 05 '18 07:07 jsfaint