Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify async job handling #1864

Merged
merged 12 commits into from
Jul 18, 2018
Merged

unify async job handling #1864

merged 12 commits into from
Jul 18, 2018

Conversation

bhcleek
Copy link
Collaborator

@bhcleek bhcleek commented Jun 20, 2018

Unify how jobs are handled in autoload/go/job.vim and autoload/go/jobcontrol.vim so that there's a single abstraction for async jobs instead of separate abstractions for Vim and Neovim. Unifying the abstractions allows us to provide the same behavior around updating status, writing progress, and handling errors in Vim and Neovim.

As part of this work, I was able to refactoring async go test jobs to use the abstraction in autoload/go/job.vim and also enable the tests in autoload/go/test_test.vim for Neovim.

Among other things, this work paves the way to:

  1. Move even more jobs that currently explicitly use job_start or jobstart into the abstraction so that there are fewer one offs.
  2. Move jobs that currently use job_start in Vim, but use a synchronous call in Neovim, to use the abstraction instead.
  3. Extend the vim-go term support to include Vim as well as Neovinm.
  4. Extend the vim-go term support to more async jobs than is currently supported.

Though this PR is relatively large, the commits that make up this change tell a coherent story using small and focused changes; reviewing this PR will be made easier by reviewing each commit individually.

bhcleek added 3 commits June 17, 2018 11:08
Remove go#jobcontrol#RemoveHandler, because it is unused.
Remove the desc argument from go#jobcontrol#Spawn, because it is unused.
Set the working directory for Neovim jobs instead of manually changing
the directory before starting the job.
@@ -1,7 +1,18 @@
" Spawn returns callbacks to be used with job_start. It is abstracted to be
let s:cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, this doesn't do what you want. The haslocaldir() checks if the current window has a local path set already with :lcd. So evaluating it once here isn't really that useful. You need to evaluate it when using.

We could add a wrapper function in util.vim though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

bhcleek added 9 commits June 20, 2018 07:53
Rename go#job#Spawn to go#job#Options.

Add a new key, cwd, to the return value of go#job#Options so that the
working directory for the job can be passed in the job options.

Add a new function, go#job#Start, to wrap vim8's job_start function.
Eventually, this new function will be used to start Neovim jobs, too, so
that vim-go can have an abstraction to start jobs that hides the details
of dealing with Neovim and Vim8 job API differences.
* Update the status in vim8 so it can be shown on the statusline.
Add go#job#Spawn, a convenience wrapper around go#job#Options and
go#job#Start that brings the vim8 and neovim job abstraction closer
together.
@bhcleek
Copy link
Collaborator Author

bhcleek commented Jun 20, 2018

PTAL

@bhcleek
Copy link
Collaborator Author

bhcleek commented Jul 18, 2018

@fatih approved the PR in a personal DM.

@bhcleek bhcleek merged commit 8c17fc4 into fatih:master Jul 18, 2018
@bhcleek bhcleek deleted the unified-job-api branch July 18, 2018 21:23
bhcleek added a commit that referenced this pull request Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants