Repository navigation
[vim-plugin] Adding support for async calls #890
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| let s:lock = v:null | ||
|
|
||
| func! phpactor#nvim#asyncCall(action, arguments) | ||
| " TODO: Include either the original "action" in the response or a request | ||
| " ID (probably better to include both) | ||
| if s:lock != v:null | ||
| echo "An asynchronous RPC '" . s:lock . "' action is already running" | ||
| return | ||
| endif | ||
|
|
||
| let s:lock = a:action | ||
| let callbacks = { | ||
| \ 'on_stdout': function('phpactor#nvim#asyncHandle'), | ||
| \ 'on_stderr': function('phpactor#nvim#asyncHandle'), | ||
| \ 'on_exit': function('phpactor#nvim#asyncHandle') | ||
| \ } | ||
| let job = jobstart([ g:phpactorPhpBin, g:phpactorbinpath, 'rpc', '--working-dir=' . g:phpactorInitialCwd ], callbacks) | ||
|
|
||
| let request = { "action": a:action, "parameters": a:arguments } | ||
|
|
||
| call chansend(job, json_encode(request)) | ||
| call chanclose(job, 'stdin') | ||
|
|
||
| return job | ||
| endfunc | ||
|
|
||
| let s:stdout = [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also still have no idea how to catch the response without using non-local scope (like the above). What do you think about creating a RPC server between vim and one-time phpactor commands? PHPCD mentioned already somewhere had a such solution. I did not tested behaviour of vim-specific
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One idea of this PR was to allow messages to be sent from Phpactor during a command's execution (i.e. to send progress notifications from the Indexer). I'm not sure there are benefits to having an 2-way RPC connection. I can imagine a use-case would be to cancel an operation - and in that case sending a
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But in anycase it's worth concentrating on the language server solution for now - we can support most of Phpactor's operations (even refactoring) over LSP and it if it works well, it could replace the Phpactor VIM client one day. Although it's still worth refactoring to use the |
||
| let s:stderr = [] | ||
|
|
||
| func! phpactor#nvim#asyncHandle(jobId, data, event) | ||
| if a:event == 'stdout' | ||
| call extend(s:stdout, a:data) | ||
| return | ||
| elseif a:event == 'stderr' | ||
| call extend(s:stderr, a:data) | ||
| return | ||
| endif | ||
|
|
||
| if a:data != 0 | ||
| echo "Phpactor returned an error: " . join(s:stderr) | ||
| return | ||
| endif | ||
|
|
||
| let s:lock = v:null | ||
| call phpactor#rpc#handleRawResponse(join(s:stdout)) | ||
|
|
||
| let s:stdout = [] | ||
| let s:stderr = [] | ||
| endfunc | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| func! phpactor#rpc#handleRawResponse(response) | ||
| if "" == a:response | ||
| return v:null | ||
| endif | ||
|
|
||
| try | ||
| let response = json_decode(a:response) | ||
| catch | ||
| throw "Could not parse response from Phpactor: " . v:exception | ||
| endtry | ||
|
|
||
| let actionName = response['action'] | ||
| let parameters = response['parameters'] | ||
|
|
||
| return phpactor#_rpc_dispatch(actionName, parameters) | ||
| endfunc |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,3 +120,8 @@ command! -nargs=0 PhpactorChangeVisibility call phpactor#ChangeVisibility() | |
| "" | ||
| " Generate accessors for the current class | ||
| command! -nargs=0 PhpactorGenerateAccessors call phpactor#GenerateAccessors() | ||
|
|
||
| "" | ||
| " Generate accessors for the current class | ||
| command! -nargs=0 PhpactorIndexStart call phpactor#IndexStart() | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove spurious doc |
||
| command! -nargs=0 PhpactorIndexStop call phpactor#IndexStop() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abstract the VIM/Neovim job control