1

Working Base Test

Working on a plugin, and it wasnt working on windows, so I reduced it to this test scenario:

function! myautoload#OnStdout(job_id, data, event)
    for line in a:data
        echom ">>>".string(line)
    endfor
endfun
function! myautoload#OnStderr(job_id, data, event)
    echom "My STDERR, job_id:".a:job_id." event:".a:event." data:".string(a:data)
endfun
function! myautoload#OnExit(job_id, data, event)
    echom "My EXIT, job_id:".a:job_id." event:".a:event." data:".string(a:data)
endfun
function! myautoload#TestJobStart()
    echom  "------------------------------------"
    echom "About to start job..."
    let opts_dict = {'on_exit': 'myautoload#OnExit', 'on_stdout': 'myautoload#OnStdout', 'on_stderr': 'myautoload#OnStderr'}
    let cmd = "ls -la"       " <--- Line of interest!!!
    let terminal_buf_nr = jobstart(cmd, opts_dict)
    echom "Start search for ".g:searchString." got return start up value: ".terminal_buf_nr
endfunction
call myautoload#TestJobStart()

Which works and prints the following in Windows and Ubuntu (:messages to view it):

------------------------------------
About to start job...
Start search for  got return start up value: 48
>>>'total 100'
>>>'drwxr-xr-x 13 michael michael  4096 May  1 15:05 .'
>>>'drwx------ 31 michael michael  4096 Apr 27 15:52 ..'
>>>'drwxr-xr-x  2 michael michael  4096 Apr 30 19:12 autoload'
>>>'-rw-r--r--  1 michael michael  1083 May  1 15:05 coc-settings.json'
>>>...etc
>>>''
>>>''

Introduce Ripgrep

Then I added back the command I am actually trying to run, ripgrep, so I changed the above line:

    let cmd = "ls -la"

to

    let cmd = "rg --vimgrep endfunction"

Here, endfunction is just the term I am grepping for. This works on Ubuntu, but NOT on Windows. On windows I get no STDOUT, i.e.:

------------------------------------
About to start job...
Start search for  got return start up value: 16

Strange. Further more if I change the command to:

    let cmd = "rg"

Then I receive STDERR on Windows:

------------------------------------
About to start job...
Start search for  got return start up value: 20
>>>''
My STDERR, job_id:20 event:stderr data:['error: The following required arguments were not provided:', '    <PATTERN>', '', 'USAGE:', '    ', '    rg [OPTIONS] PATTERN [PATH ...]', '    rg [OPTIONS] [-e PATTERN ...] [-f PATTERNFILE ...] [PATH ...]', '    rg [OPTIONS] --files [PATH ...]', '    rg [OPTIONS] --type-list', '    command | rg [OPTIONS] PATTERN', '', 'For more information try --help', '', '']
My STDERR, job_id:20 event:stderr data:['']
My EXIT, job_id:20 event:exit data:2

Strange that I can receive STDERR but not STDOUT when running on windows. But I received STDOUT on windows with ls -la If I run the command like this in vim

:!rg --vimgrep endfunction

It works as expected.

I tried let cmd = ['rg', '--vimgrep', 'endfunction'], didnt help. The end goal is to make it async, i.e. from reading the help I think I add to opts_dict the pair 'detach': 1. When I add that, then even the test with ls -la also gives no output, so I suspect it is something to do with threading and it not being attached. If someone could point me in the right direction, or what to read up that would be great!

Update

I have been trying every argument : pty, stdout_buffered, rpc... for some reason pty is kind of working. However then I get extra characters which mess up the output (e.g. ^[[0K^M'). I First thought it was color ouput mess it up, but even with adding --color never it produces the same output.

2

Turned out rg command for some reason behaves a certain way when called from the following:

  • Window cmd
  • bash
  • vim :!
  • Ubuntu jobstart()

Differently to when called from

  • Windows jobstart()

The solution is simply to define what to search:

let cmd = ['rg', '--vimgrep', 'endfunction', './']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.