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

Running tasks sequentially

Open Shatur opened this issue 5 years ago • 16 comments

Is it possible to run tasks sequentially? For example, in most IDEs, when a project starts, compilation occurs first. It would be convenient to assign build + run to a single key.

P.S. Sorry for a lot of issues :)

Shatur avatar Mar 17 '20 17:03 Shatur

It is not a simply task, which would significantly increase the complexity. Many corner cases need to be handled.

No problem for issues, they let me know how to polish this plugin.

skywind3000 avatar Mar 17 '20 17:03 skywind3000

It is not a simply task, which would significantly increase the complexity. Many corner cases need to be handled.

Understand. Will you try to implement it in future? It would be great to be able to pass multiple tasks to :AsyncTask for sequential execution.

Shatur avatar Mar 17 '20 18:03 Shatur

It is difficult to chain tasks with different output and pos together.

skywind3000 avatar Mar 17 '20 19:03 skywind3000

Maybe you don't need to chain output of such tasks? :AsyncTask first second could works as :AsyncTask first, wait for finish, :AsyncTask second.

Shatur avatar Mar 17 '20 19:03 Shatur

Some kinds of tasks (including user defined runners) have no exit callback to notify AsyncTask to proceed next one.

Some tasks will open a new split/tab, if people are editing in insert mode, opening a new split/tab is really unexpected.

skywind3000 avatar Mar 17 '20 19:03 skywind3000

Some tasks will open a new split/tab, if people are editing in insert mode, opening a new split/tab is really unexpected.

But if the user created a task that does this, this is the user's problem, I think.

Some kinds of tasks (including user defined runners) have no exit callback to notify AsyncTask to proceed next one.

Bad to hear :( So, it's not possible?

Shatur avatar Mar 17 '20 20:03 Shatur

Sad to say it is impossible.

And a work around is to concatenate two commands with $$ in one task.

skywind3000 avatar Mar 18 '20 12:03 skywind3000

s/$$/&&/g

skywind3000 avatar Mar 18 '20 12:03 skywind3000

Maybe it would be possible to get parameters from other tasks? It could solve the problem. Something like this can allow to execute build + run and only build:

[project-build]
command=cd ../build-$(VIM_PRONAME)-$(VIM_PROFILE) && cmake --build .
cwd=<root>

[project-run]
command=$(project-build:command) && ./my-executable
cwd=<root>

Shatur avatar Mar 18 '20 13:03 Shatur

A big refactor is required for this.

skywind3000 avatar Mar 18 '20 14:03 skywind3000

Do you like the idea in general? If yes, I think that is possible to think about simpler syntax.

Shatur avatar Mar 18 '20 14:03 Shatur

It is a good idea.

skywind3000 avatar Mar 18 '20 15:03 skywind3000

Okay :) Getting parameters from other tasks is very flexible and generic solution. Maybe would be simpler to add the ability to specify commands that will be concatenated? For example:

[project-build]
command=cd ../build-$(VIM_PRONAME)-$(VIM_PROFILE) && cmake --build .
cwd=<root>

[project-run]
depends=project-build
command=cd ../build-$(VIM_PRONAME)-$(VIM_PROFILE) && ./my-executable
cwd=<root>

It less flexible, but maybe it would be simpler to implement?

Shatur avatar Mar 18 '20 19:03 Shatur

That's even more complex, because asynctasks.vim needs to parse dependency

skywind3000 avatar Mar 19 '20 00:03 skywind3000

Hm... What if use :AsyncTask first-task second-task with concatenation under the hood and disallow user to specify different output and pos in running tasks? This will have some limitations for user tasks, but maybe it will be easier?

Shatur avatar Mar 19 '20 09:03 Shatur

I use the following workaround to build and run a file:

let s:asynctask_build_filetypes = ['c', 'cpp', 'rust']
function! s:asynctask_call_after_build_file()
    augroup asyntask_file_build_finished
        autocmd!
    augroup END
    AsyncTask file-run
endfunction
function! s:asynctask_build_and_run_file()
    if index(s:asynctask_build_filetypes, &filetype) >= 0
        augroup asyntask_file_build_finished
            autocmd!
            autocmd User AsyncRunStop call s:asynctask_call_after_build_file()
        augroup END
        AsyncTask file-build
    else
        call s:asynctask_call_after_build_file()
    endif
endfunction
command! AsyncTaskBuildAndRunFile call <SID>asynctask_build_and_run_file()

nnoremap <S-F7> :AsyncTaskBuildAndRunFile<CR>

Pressing <Shift-F7> builds an executable and runs it, after the build was completed. It uses the AsyncRunStop autocommand which is triggered after a task has been completed.

IngoMeyer441 avatar Jan 19 '23 15:01 IngoMeyer441