skywind3000 / asyncrun.vim

:rocket: Run Async Shell Commands in Vim 8.0 / NeoVim and Output to the Quickfix Window !!
https://www.vim.org/scripts/script.php?script_id=5431
MIT License
1.84k stars 109 forks source link

AsyncStop does not work when program does not exit normally #204

Open lucypero opened 3 years ago

lucypero commented 3 years ago

Also, Asyncrun believes the program is still running at some instances, for example when the program panics because of an error. AsyncStop() never works in these instances. It doesn't do anything. So I can't run the program again. I have to restart vim every time this happens.

I use it on Neovim on Windows

Example: https://github.com/skywind3000/asyncrun.vim/issues/204#issuecomment-705730506

skywind3000 commented 3 years ago

reproduce steps ??

lucypero commented 3 years ago

Take this Odin program:

package main

main :: proc()
{
  panic("");
}

then run it with AsyncRun

:AsyncRun odin run main.odin

Even though the program just exits normally when you run it on cmd.exe, AsyncRun gets stuck and you cannot quit the program with AsyncStop and so you can't run the program again. I have to restart vim every time.

skywind3000 commented 3 years ago

I failed to setup an odin environment. could you provide another example in C or C++ or Python ??

My guess:

Suggest:

lucypero commented 3 years ago

@skywind3000

Simply running this program breaks AsyncRun.

int main(){
  return -1;
}

cl main.c /nologo

Then on vim:

:AsyncRun main

gets it stuck forever. Only fix is to restart vim. Running the same program on the console is fine.

Is there a way so that AsyncStop actually works?

skywind3000 commented 3 years ago

can't reproduce your error:

图片

lucypero commented 3 years ago

Ok, I tested it with vim and it works. Then I tested it with Neovim with the same config and it doesn't. Maybe Neovim is the problem.

skywind3000 commented 3 years ago

sorry, I forgot you are using neovim and I just tested it in vim. Now, It can be reproduced after I switched to neovim:

图片

After some inspection, I found it is neovim's issue on windows, if a process returns a code below zero, neovim's job system will hang there, no further events can be received from job system's callback.

The workaround is very simple, just return something >= 0:

图片

See, successfully exited.

skywind3000 commented 3 years ago

So keep your return code above or equal to zero. OR use a script launch.cmd to start your job:

@echo off
call %*
exit 0

This launch.cmd will override your program's return code. use it to start your program:

图片

:AsyncRun launch.cmd main

the process exited as expected. a new command modifier may help here:

let g:asyncrun_program = get(g:, 'asyncrun_program', {})
let g:asyncrun_program.fix = { opts -> 'd:\launch.cmd  ' . opts.cmd }

Then:

:AsyncRun -program=fix  main

When -program=fix is provided, the command will be modified to a new string:

图片

thePHTest commented 2 years ago

Unfortunately this bug still exists with the latest release from https://github.com/neovim/neovim . Has anyone opened an issue there or attempted to make a PR for it?

skywind3000 commented 2 years ago

Can this be closed ? after the new commit: https://github.com/skywind3000/asyncrun.vim/commit/a7a83c1ecdcd54636247454694ddd5d9086e3b68

Sharlock93 commented 1 year ago

I tested it on the latest version of Async and returning negative numbers no longer hangs the program.