liuchengxu / vim-clap

:clap: Modern performant fuzzy picker, tree-sitter highlighting, and more, for both Vim and NeoVim
https://liuchengxu.github.io/vim-clap/
MIT License
2.11k stars 87 forks source link

Clap help_tags does not show search result #449

Closed markwu closed 4 years ago

markwu commented 4 years ago

Environment (please complete the following information):

Describe the bug Clap help_tags can not perform search, just show

vim-clap: Vim(let):E906: not an open channel
vim-clap: Vim(let):E906: not an open channel
...

Clap debug


            has cargo: 1
            has maple: /Users/mark/.dot_vim/bundle/vim-clap/target/release/maple
           maple info: version 0.1.17 (git v0.17), built for x86_64-apple-darwin by rustc 1.43.1.

         has +python3: 1
has py dynamic module: 0
     Current FileType: 
Third Party Providers: []
       Global Options:
    let g:clap#autoload_dir = '/Users/mark/.dot_vim/bundle/vim-clap/autoload'
    let g:clap#provider_alias = {'gfiles': 'git_files', 'hist:': 'command_history', 'hist/': 'search_history'}
    let g:clap_cache_directory = '/Users/mark/.vim/cache/clap'
    let g:clap_disable_bottom_top = 0
    let g:clap_disable_matches_indicator = v:false
    let g:clap_disable_optional_async = v:false
    let g:clap_disable_run_rooter = v:false
    let g:clap_enable_icon = 0
    let g:clap_forerunner_status_sign = {'done': '•', 'running': '!', 'using_cache': '*'}
    let g:clap_insert_mode_only = 1
    let g:clap_layout = {'col': '10%', 'row': '20%', 'width': '80%', 'relative': 'editor', 'height': '30%'}
    let g:clap_multi_selection_warning_silent = 0
    let g:clap_no_matches_msg = 'NO MATCHES FOUND'
    let g:clap_open_action = {'ctrl-v': 'vsplit', 'ctrl-x': 'split', 'ctrl-t': 'tab split'}
    let g:clap_popup_border = 'rounded'
    let g:clap_preview_size = 5
    let g:clap_project_root_markers = ['.git', '.git/', '.hg', '.svn', '.bzr', '_darcs', '_FOSSIL_', '.fslckout', '.project', '.root']
    let g:clap_prompt_format = ' %provider_id%> '
    let g:clap_providers_relaunch_code = '@@'
    let g:clap_search_box_border_style = 'nil'
    let g:clap_search_box_border_symbols = {'nil': ['', ''], 'curve': ['', ''], 'arrow': ['', '']}
  Provider Variables:
    let g:clap_provider_grep_enable_icon = 0

To Reproduce

  1. Type Clap help_tags
  2. perform search, nothing happened
  3. :messages show error vim-clap: Vim(let):E906: not an open channel
liuchengxu commented 4 years ago

Can't reproduce. No changes about help_tags and the Rust binary since v0.17. It's likely an issue of your local environment. See if /Users/mark/.dot_vim/bundle/vim-clap/target/release/maple works in the command line.

markwu commented 4 years ago

Weird, I delete vim-clap folder, and reinstall it again. It still the same ...

/Users/mark/.dot_vim/bundle/vim-clap/target/release/maple the command works ...

I also tried neovim, after I input search terms in input box, nothing happened and no error messages.

$ ./maple
maple 0.1.0

USAGE:
    maple [FLAGS] [OPTIONS] <SUBCOMMAND>

FLAGS:
    -h, --help        Prints help information
        --no-cache    Do not use the cached file for exec subcommand

OPTIONS:
    -n, --number <NUM>                   Print the top NUM of filtered items
    -i, --icon-painter <icon-painter>    Prepend an icon for item of files and grep provider, valid only when --number
                                         is used [possible values: File, Grep]
        --log <log>                      Enable the logging system
    -w, --winwidth <winwidth>            Width of clap window

SUBCOMMANDS:
    blines                Filter against current Vim buffer
    cache                 Interact with the cache info
    check-release         Retrive the latest remote release info
    exec                  Execute the shell command
    filter                Fuzzy filter the input
    grep                  Execute the grep command to avoid the escape issue
    help                  Prints this message or the help of the given subcommand(s)
    helptags              Generate vim help tags
    ripgrep-forerunner    Start the forerunner job of grep
    rpc                   Start the stdio-based service, currently there is only filer support
    tags                  Generate the project-wide tags using ctags
    version               Display the current version
liuchengxu commented 4 years ago

Well, try adding some debugging info:

diff --git a/autoload/clap/provider/help_tags.vim b/autoload/clap/provider/help_tags.vim
index ae63fc4..6ef9029 100644
--- a/autoload/clap/provider/help_tags.vim
+++ b/autoload/clap/provider/help_tags.vim
@@ -14,6 +14,8 @@ if clap#maple#is_available() && clap#filter#sync#python#has_dynamic_module()
     let tmp = tempname()
     call writefile([join(s:get_doc_tags(), ','), &runtimepath], tmp)
     let helptags_cmd = clap#maple#build_cmd('helptags', tmp)
+
+    echom 'using Rust impl, command:'.printf('"%s" %s', helptags_cmd[0], join(helptags_cmd[1:], ' '))
     " Currently the source has to be a String even we use List in job arguments.
     return printf('"%s" %s', helptags_cmd[0], join(helptags_cmd[1:], ' '))
   endfunction
@@ -44,6 +46,7 @@ else
       endif
     endif

+    echom 'using vimscript impl'
     return s:help_tags_memory_cache
   endfunction

Based on your :Clap debug info, you should be using the vimscript impl, have no idea why this issue happens. If you see the Rust command, try running it from the command line.

markwu commented 4 years ago

I found some interesting things.

  1. I try install vim-clap with minimal vimrc again, no maple. It show me: image

  2. I install maple from Clap Install-binary!, it shows me Rust nightly is required, skip building the Python dynamic module. image

  3. After maple-cli installed (without compilation errors), it show me image

I will try your above suggestions, to see any messages show up.

liuchengxu commented 4 years ago
  1. I also tried the minimal vimrc, :Clap help_tags still works for me.
set nocompatible
set runtimepath^=~/.vim/plugged/vim-clap
syntax on
filetype plugin indent on
            has cargo: 1
            has maple: v:null
         has +python3: 1
has py dynamic module: 0
     Current FileType:
Third Party Providers: []
       Global Options:
    let g:clap#autoload_dir = '/Users/xuliucheng/.vim/plugged/vim-clap/autoload'
    let g:clap#provider_alias = {'gfiles': 'git_files', 'hist:': 'command_history', 'hist/': 'search_history'}
    let g:clap_disable_bottom_top = 0
    let g:clap_disable_matches_indicator = v:false
    let g:clap_disable_optional_async = v:false
    let g:clap_disable_run_rooter = v:false
    let g:clap_enable_icon = 0
    let g:clap_forerunner_status_sign = {'done': '•', 'running': '!', 'using_cache': '*'}
    let g:clap_insert_mode_only = v:false
    let g:clap_multi_selection_warning_silent = 0
    let g:clap_no_matches_msg = 'NO MATCHES FOUND'
    let g:clap_open_action = {'ctrl-v': 'vsplit', 'ctrl-x': 'split', 'ctrl-t': 'tab split'}
    let g:clap_popup_border = 'rounded'
    let g:clap_preview_size = 5
    let g:clap_providers_relaunch_code = '@@'
    let g:clap_search_box_border_style = 'nil'
    let g:clap_search_box_border_symbols = {'nil': ['', ''], 'curve': ['', ''], 'arrow': ['', '']}
  Provider Variables:
                     []
  1. That message can just be ignored as the Python dynamic module is no longer neccessary.

  2. The error is mostly caused by the failure of the running maple inside vim.

Do the other providers work except help_tags?

markwu commented 4 years ago

I found with minimal vimrc, vim-clap still not works under vim. It just show error messages and jump to help files.

image

But, vim-clap works under neovim with minimal vimrc. image

image

It seems only vimscript command, no rust command.

No idea what's going on.

markwu commented 4 years ago

Other provider seems work.

liuchengxu commented 4 years ago

Finally reproduced it.

BTW, the pure vimscript impl will be deprecated once the complete client-server model(you can subscribe the progress of #448) is finished. The various performace workarounds will be all resolved by the new client-server architecture. Only the Rust binary will be required then, no more Python dynamic module, no more stopping and rerunning the maple process multiple times, no more any timer delays, pure async operation.

markwu commented 4 years ago

Weird, the fix not works for me.

my vim version is 8.2.822, and neovim version is NVIM v0.5.0-91e41c857

I'll do more tests to see what's going on.

markwu commented 4 years ago

I recompile everything, everything still the same, bug still there. No idea what's going.

liuchengxu commented 4 years ago

I can't reproduce it with the latest Vim avaliable for macOS brew. The rust binary is not being used, so recompilation doesn't help.

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jun  2 2020 17:58:30)
macOS version
Included patches: 1-884
Compiled by Homebrew

You could also see if using the Rust impl helps:

diff --git a/autoload/clap/provider/help_tags.vim b/autoload/clap/provider/help_tags.vim
index ae63fc4..f62916c 100644
--- a/autoload/clap/provider/help_tags.vim
+++ b/autoload/clap/provider/help_tags.vim
@@ -8,7 +8,8 @@ function! s:get_doc_tags() abort
   return ['/doc/tags'] + map(filter(split(&helplang, ','), 'v:val !=? "en"'), '"/doc/tags-".v:val')
 endfunction

-if clap#maple#is_available() && clap#filter#sync#python#has_dynamic_module()
+" if clap#maple#is_available() && clap#filter#sync#python#has_dynamic_module()
+if 1

   function! s:help_tags_source() abort
     let tmp = tempname()
markwu commented 4 years ago

Okay, I try to change the above statement to 1 and 0,

To 1:

It goes rust implementation, it works well.

To 0:

It goes vimscript implementation, the bugs appear.

So, for me. It seems always go to vimscript implementation, never go to rust implementation, even I have maple installed.

liuchengxu commented 4 years ago

clap#maple#is_available() && clap#filter#sync#python#has_dynamic_module()

maple is avaliable and you have built the Python dynamic module. Since you don't have the dynamic module, the vimscript impl will be used in the default strategy.

markwu commented 4 years ago

Then, I have no idea why vimscript implementation not works for me. It works before .... ha.

liuchengxu commented 4 years ago

Have tested on Ubuntu too, still works with the latest commit using minimal vimrc. If you suspect it could be caused by some update, you may revert to the old version and see if you can find some new clues.

markwu commented 4 years ago

Okay, I'll try ... and let you know the result.

markwu commented 4 years ago

Okay, I think I found something ...

Testing env:

  1. I install vim-clap without maple
  2. Try :Clap help_tags, search works
  3. install maple with :Clap install-binary!
  4. Try :Clap help_tags, search not works, error messages vim-clap: Vim(let):E906: not an open channel appears.
  5. Change help_tags.vim if statement you suggested to if 1.
  6. Try :Clap help_tags, search works
  7. Change help_tags.vim if statement you suggested to if 0.
  8. Try :Clap help_tags, search not works, error messages vim-clap: Vim(let):E906: not an open channel appears.
  9. Change help_tags.vim if statement you suggested to original clap#maple#is_available() && clap#filter#sync#python#has_dynamic_module() and delete ~/.vim/bundle/vim-clap/target/release/*.
  10. Try :Clap help_tags, search works again

It is so werid. It seems something wrong after install maple cli.

I will try other version tag to see what's going on.

markwu commented 4 years ago

Another testing ...

Testing env:

macOS: 10.14.6 vim: 8.2.822 building env: homebrew with Xcode CLT vim-clap: from tag v0.10 to v0.17 and master head

WITHOUT MAPLE

  1. from v0.10 to v0.3, :Clap help_tags, search works
  2. from v0.14 to v0.17, :Clap help_tags, search not works, and shows the followings error messages. image
  3. master head, :Clap help_tags, search works

WITH MAPLE

  1. from v0.10 to v0.3, :Clap help_tags, search works
  2. from v0.14 to master head, :Clap help_tags, search not works, and shows the followings error messages.

image

markwu commented 4 years ago

@liuchengxu Hope these information enough for you to see what's going on. It seems everything works before v0.14.

I didn't test neovim yet.

markwu commented 4 years ago

I tested neovim from vim-clap v0.13 to master head, it seems all works with or without maple.

liuchengxu commented 4 years ago

It seems something wrong after install maple cli.

This should be incorrect as the vimscript impl (if 0) does not use the maple at all. For your case, since you don't have the Python dynamic module, you should always use the vimscript impl.

This commit https://github.com/liuchengxu/vim-clap/commit/2ad4ce34a143b7734577388fba765d637f64c8d5 fixes the Vim job command argument, at least for me, I can no longer reproduce this issue . https://github.com/liuchengxu/vim-clap/pull/407 could be related, not sure about that.

markwu commented 4 years ago

For your case, since you don't have the Python dynamic module, you should always use the vimscript impl.

Yes, that's why I said "Weird" ...

Still no idea ...

liuchengxu commented 4 years ago

These could be several possible job leading to this, try to see which one is related.

diff --git a/autoload/clap/dispatcher.vim b/autoload/clap/dispatcher.vim
index 71a6e8d..91f95ff 100644
--- a/autoload/clap/dispatcher.vim
+++ b/autoload/clap/dispatcher.vim
@@ -214,6 +214,7 @@ else
   endfunction

   function! s:job_start(cmd) abort
+    echom '[dispatcher.vim]cmd:'.string(a:amd)
     let job = job_start(clap#job#wrap_cmd(a:cmd), {
           \ 'in_io': 'null',
           \ 'err_cb': function('s:err_cb'),
diff --git a/autoload/clap/job.vim b/autoload/clap/job.vim
index c49bbb2..43c2317 100644
--- a/autoload/clap/job.vim
+++ b/autoload/clap/job.vim
@@ -49,6 +49,7 @@ else
   endif

   function! clap#job#start_buffered(cmd_list, CloseCallback) abort
+    echom '[clap#job#start_buffered]cmd_list:'.string(a:amd_list)
     let job = job_start(a:cmd_list, {
           \ 'in_io': 'null',
           \ 'close_cb': a:CloseCallback,
diff --git a/autoload/clap/job/daemon.vim b/autoload/clap/job/daemon.vim
index e5ebf86..e888b71 100644
--- a/autoload/clap/job/daemon.vim
+++ b/autoload/clap/job/daemon.vim
@@ -101,6 +101,7 @@ else

   function! s:start_service_job(cmd_list) abort
     call clap#job#daemon#stop()
+    echom '[daemon#start_service_job]cmd_list:'.string(a:amd_list)
     let s:job = job_start(a:cmd_list, {
           \ 'err_cb': function('s:err_cb'),
           \ 'out_cb': function('s:out_cb'),
diff --git a/autoload/clap/job/stdio.vim b/autoload/clap/job/stdio.vim
index a94a672..3d6b7af 100644
--- a/autoload/clap/job/stdio.vim
+++ b/autoload/clap/job/stdio.vim
@@ -111,6 +111,7 @@ else
   function! s:start_service_job(cmd_list) abort
     call clap#job#stdio#stop_service()
     call clap#spinner#set_busy()
+    echom '[stdio#start_service_job]cmd_list:'.string(a:amd_list)
     let s:job = job_start(a:cmd_list, {
markwu commented 4 years ago

Okay I apply the patch and fixed some typo, cmd not amd, here comes the messages

[daemon#start_service_job]cmd_list:['/Users/markwu/Projects/vim-test/bundle/vim-clap/target/release/maple', 'rpc']
[clap#job#start_buffered]cmd_list:'[''/Users/markwu/Projects/vim-test/bundle/vim-clap/target/release/maple'', ''--number'', 52, ''--winwidth'', 127, ''filter'', ''C'', ''--sync''] --input /va
r/folders/y2/qvr3832j08340b8y6sbdv6dm0000gn/T/vLmKr5f/0'
vim-clap: Vim(let):E906: not an open channel
[clap#job#start_buffered]cmd_list:'[''/Users/markwu/Projects/vim-test/bundle/vim-clap/target/release/maple'', ''--number'', 52, ''--winwidth'', 127, ''filter'', ''Cla'', ''--sync''] --input /
var/folders/y2/qvr3832j08340b8y6sbdv6dm0000gn/T/vLmKr5f/0'
vim-clap: Vim(let):E906: not an open channel
[clap#job#start_buffered]cmd_list:'[''/Users/markwu/Projects/vim-test/bundle/vim-clap/target/release/maple'', ''--number'', 52, ''--winwidth'', 127, ''filter'', ''Clap'', ''--sync''] --input
/var/folders/y2/qvr3832j08340b8y6sbdv6dm0000gn/T/vLmKr5f/0'
vim-clap: Vim(let):E906: not an open channel
"change.txt" [唯讀] 1882L, 76749C

Vim with vim-clap master head and maple installed.

liuchengxu commented 4 years ago

Well, you may check what happens to clap#job#start_buffered(). You basically have to fix it on your own as I can't reproduce, help_tags works great for me, in every case.

diff --git a/autoload/clap/job.vim b/autoload/clap/job.vim
index c49bbb2..bf4cd41 100644
--- a/autoload/clap/job.vim
+++ b/autoload/clap/job.vim
@@ -55,6 +55,7 @@ else
           \ 'noblock': 1,
           \ 'mode': 'raw',
           \ })
+    echom 'job_info:'.string(job_info(job))
     let job_id = ch_info(job_getchannel(job))['id']
     let s:job_id_map[job_id] = job
     return job_id
markwu commented 4 years ago

Okay, I see ... I'll try.

markwu commented 4 years ago

One thing I don't get it. If my python dynamic module does not installed, it will fall back to vim script implementation.

Why it still run maple command?

[clap#job#start_buffered]cmd_list:'[''/Users/markwu/Projects/vim-test/bundle/vim-clap/target/release/maple'', ''--number'', 52, ''--winwidth'', 127, ''filter'', ''C'', ''--sync''] --input /va
r/folders/y2/qvr3832j08340b8y6sbdv6dm0000gn/T/vLmKr5f/0'
markwu commented 4 years ago

I trace down to the following script inside ./autoload/clap/maple.vim

  function! s:close_cb(channel) abort
    if clap#job#vim8_job_id_of(a:channel) == s:job_id
      try
        echom '[s:close_cb]channel:'.string(a:channel)
        let s:chunks = split(ch_readraw(a:channel), "\n")
        echom '[s:close_cb]chunks:'.string(S:chunks)
        call s:on_complete()
      catch
        call clap#helper#echo_error(v:exception)
        call clap#spinner#set_idle()
      endtry
    endif
  endfunction

I found let s:chunks = split(ch_readraw(a:channel), "\n") failed.

The channel open successed, and buffered, but when read from it, it just failed.

Here comes the debug messages:

[daemon#start_service_job]cmd_list:['/Users/markwu/.dot_vim/bundle/vim-clap/target/release/maple', 'rpc']
[clap#job#start_buffered]cmd_list:'[''/Users/markwu/.dot_vim/bundle/vim-clap/target/release/maple'', ''--number'', 52, ''--winwidth'', 152, ''filter'', ''C'', ''--sync''] --input /var/folders
/y2/qvr3832j08340b8y6sbdv6dm0000gn/T/vTd79wL/3'
[clap#job#start_buffered]job_info:{'status': 'run', 'cmd': ['[''/Users/markwu/.dot_vim/bundle/vim-clap/target/release/maple'',', '''--number'',', '52,', '''--winwidth'',', '152,', '''filter''
,', '''C'',', '''--sync'']', '--input', '/var/folders/y2/qvr3832j08340b8y6sbdv6dm0000gn/T/vTd79wL/3'], 'termsig': '', 'stoponexit': 'term', 'tty_out': '', 'exitval': 0, 'exit_cb': '', 'tty_in
': '', 'channel': 'channel 2 open', 'process': 67308}
[clap#job#start_buffered]job_channel:channel 2 open
[clap#job#start_buffered]ch_info:{'status': 'open', 'id': 2, 'in_io': 'null', 'err_mode': 'RAW', 'in_status': 'closed', 'out_io': 'pipe', 'err_io': 'pipe', 'err_status': 'open', 'out_timeout'
: 2000, 'out_status': 'open', 'out_mode': 'RAW', 'in_mode': 'RAW', 'in_timeout': 2000, 'err_timeout': 2000}
[clap#job#start_buffered]job_id_map:{'1': 'process 67307 run', '2': 'process 67308 run'}
[s:close_cb]channel:channel 2 buffered
vim-clap: Vim(let):E906: not an open channel
[clap#job#stop]job_id_map:{'1': 'process 67307 run', '2': 'process 67308 dead'}
[clap#job#stop]job_id:2
markwu commented 4 years ago

Okay, I change it to let s:chunks = split(ch_readraw(a:channel, {'part': 'err'}), "\n").

Then, I can read the error messages from the channel, the error is

[s:close_cb]channel:channel 2 buffered
[s:close_cb]chunks:['executing job failed: No such file or directory']

Does it mean vim-clap could no not found maple? Werid.

liuchengxu commented 4 years ago

Aside from the generatation of help tags using Rust, maple also serves as a fuzzy filter.

Does it mean vim-clap could no not found maple?

I think it's more likely /var/folders/y2/qvr3832j08340b8y6sbdv6dm0000gn/T/vTd79wL/3 does exist from your previous screenshot. It's a temp file containing the source list of the provider, and should only exist when the clap window is open.

markwu commented 4 years ago

Interesting, I confirmed the file is there.

markwu commented 4 years ago

Ah, there is another tempname() inside forerunner.vim and state.vim.

markwu commented 4 years ago

No idea how to solve it. I use :Clap help_tags ++ef=fzf at this moment.

markwu commented 4 years ago

I found proj_tags does not work, too.

It shows empty list.

liuchengxu commented 4 years ago

Works for me, ensure you meet the requirement of proj_tags.

markwu commented 4 years ago

Yes, I have both maple and universal-ctags installed. I also have vista.vim installed.

liuchengxu commented 4 years ago

maple and universal-ctags with JSON output support

markwu commented 4 years ago

Okay, I do have json support

$ ctags --help | grep output-format
  --output-format=u-ctags|e-ctags|etags|xref|json

That's werid.

liuchengxu commented 4 years ago

Well, I can only suggest you trying to see whether the related command works in the command line:

diff --git a/autoload/clap/provider/proj_tags.vim b/autoload/clap/provider/proj_tags.vim
index 4037a0c..60d7cc8 100644
--- a/autoload/clap/provider/proj_tags.vim
+++ b/autoload/clap/provider/proj_tags.vim
@@ -7,17 +7,19 @@ set cpoptions&vim
 let s:proj_tags = {}

 function! s:proj_tags.on_typed() abort
-  if exists('g:__clap_forerunner_tempfile')
-    call clap#filter#async#dyn#from_tempfile(g:__clap_forerunner_tempfile)
-  elseif exists('g:__clap_forerunner_result')
-    let query = g:clap.input.get()
-    if query ==# ''
-      return
-    endif
-    call clap#filter#on_typed(function('clap#filter#sync'), query, g:__clap_forerunner_result)
-  else
-    call clap#filter#async#dyn#start_directly(clap#maple#build_cmd('tags', g:clap.input.get(), clap#rooter#working_dir()))
-  endif
+  " if exists('g:__clap_forerunner_tempfile')
+    " call clap#filter#async#dyn#from_tempfile(g:__clap_forerunner_tempfile)
+  " elseif exists('g:__clap_forerunner_result')
+    " let query = g:clap.input.get()
+    " if query ==# ''
+      " return
+    " endif
+    " call clap#filter#on_typed(function('clap#filter#sync'), query, g:__clap_forerunner_result)
+  " else
+  let cmd = clap#maple#build_cmd('tags', g:clap.input.get(), clap#rooter#working_dir())
+  echom 'proj_tags cmd:'.join(cmd, ' ')
+  call clap#filter#async#dyn#start_directly(cmd)
+  " endif
 endfunction

 function! s:proj_tags.init() abort

Run that command from the command line, and see what happens.

markwu commented 4 years ago

Suddenly, it works.

markwu commented 4 years ago

After the recent update, Clap help_tags works again. But every provider it shows an error message when start

vim-clap: [client handle] 'unknown method: on_init'

And, shows the following message when I close the clap popup:

vim-clap: [client handle] 'unknown method: exit'

image

liuchengxu commented 4 years ago

I dont' see this problem. File a new issue if you can reproduce it. You might be using a mismatched Rust binary.

markwu commented 4 years ago

Okay, I will delete it and install again to see if the problem still there.

markwu commented 4 years ago

You are right, it works. No error messages.