You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[VIM Plugin] Option to control navigation window #485
Currently when you use Goto Reference or other functionality that implies navigation, phpactor tries to open the destination in the current window. It would be great if there was an option that would tell it to use new split / tab instead, with these possible values: split above, split below, split to the right, split to the left, new tab.
And the default would be the same behavior as it is now, so it's up to the user to enable this. It's also quite easy to get rid of all but the current split with quick Ctrl-w o.
There are problems with current approach:
It doesn't work when current window contains changed buffer (not with my default settings anyway)
I don't want to navigate away from the file I'm working on
So now to be able to navigate to, say, method definition I have to do the split manually and only then invoke phpactor.
Hmm... I could probably automate that instead though, so instead of just invoking the menu the mapping would do the split first.
nmap <Leader>mm <C-w>s :call phpactor#ContextMenu()<CR> does the trick. Except not every action from that menu needs the split, but it's good enough for now. Certainly better than doing the split manually.
Yeah, I've seen that commit in develop. I'm talking about the "source" buffer, though. If it's changed, and it's the only window containing the buffer, editing another file ("navigating away") in it fails.
I guess one simple thing to do would be to introduce a way to specify the way to "open" a file.
Currently it is always :edit if it is a different file than the current one. The following switches it to vsplit on open_file:
diff --git a/plugin/phpactor.vim b/plugin/phpactor.vim
index 5e489f3..f565e9a 100644
--- a/plugin/phpactor.vim+++ b/plugin/phpactor.vim@@ -271,7 +271,7 @@ endfunction
"""""""""""""""""""""""
" Utility functions
"""""""""""""""""""""""
-function! phpactor#_switchToBufferOrEdit(filePath)+function! phpactor#_switchToBufferOrEdit(filePath, target)
if expand('%:p') == a:filePath
" filePath is currently open
return
@@ -279,6 +279,11 @@ function! phpactor#_switchToBufferOrEdit(filePath)
let bufferNumber = bufnr(a:filePath . '$')
+ if (a:target == v:true)+ exec ":vsplit " . a:filePath+ return+ endif+
if (bufferNumber == -1)
exec ":edit " . a:filePath
return
@@ -511,7 +516,7 @@ function! phpactor#_rpc_dispatch(actionName, parameters)
" >> open_file
if a:actionName == "open_file"
- call phpactor#_switchToBufferOrEdit(a:parameters['path'])+ call phpactor#_switchToBufferOrEdit(a:parameters['path'], v:true)
if a:parameters['force_reload'] == v:true
exec ":e!"
This obviously isn't a flexible solution, but we could easily offer a way to specify a global opening strategy (e.g. vsplit, split, tabnew, edit, etc.
Even better would be a way to dynamically choose the opening strategy, but this might be best done with a keyboard shortcut, eg. <leader>got for GOto definition new Tab. And providing an easy way to specify the strategy - although as it goes through RPC, this would involve some kind of state hack.
It works, but if it can't find/goto definition, I'm left having to manually close the split. Do you know if I can check for definition existence first before opening split? Or what do you think of adding an alias functions like:
I think this would be great. We can add it as a parameter for sure I think, then it's a question of if we add proxy methods, but if you wanted to make a PR for the parameter way, that could go in I think (we can also update the example config with a mapping for opening in a split)
Saying that, it also +may_ make sense to support this on the RPC level with the OpenFileResponse, in which case we can pass the preference to Phpactor and it will return the OpenFileResponse with the appropriate strategy, which can then be interpreted by the VIM plugin.
I guess it's possible to imagine other situations where it's desirable for Phpactor to instruct the editor to open a new split or a new tab.
haha. It's the remote-procedure-call that you can see happening in the GotoDefinition function in the vimscript. It sends the command to Phpactor, and Phpactor returns a command to open the file, it might make sense for Phpactor to additionally be responsible for saying if the file should be opened in a split etc. In which case we would pass our preference to the RPC call.
Not complicated change, but I guess involved. If you can find a non-disruptive way to do it in the plugin only, that would be fine. I guess a string value would also be fine assuming there are no Enums in vimscript.
Well the plugin is vim-specific right? The PHP side of phpactor is vim-agnostic, isn't it? If so, wouldn't it make sense to keep :split, :vsplit, :tab, etc. related terminology in the plugin?
I think I already mentionned it somewhere, but how about using the same mecanism as the help window (I think it's the preview pane) ? So that on the first call you would indeed jump into the preview pane, but then on calls after that one you stay in that pane...
I just wish there was a way for phpactor to just not do anything if it can't find the definition I want to open, and instruct the editor to not open the split at all.
I just wish there was a way for phpactor to just not do anything if it can't find the definition I want to open, and instruct the editor to not open the split at all.
Sorry, haven't had time to look further into a PR for this, but definitely still want the feature! 100% agree though, if phpactor can't find the definition, it shouldn't open a split at all 👍
It seems necessary for the "server" to provide a hint as to how the file should be opened (at which point I'm doubting the "static constructor" approach here), but basically maybe there should be a target returned which could be new, horizontal|vertical split, or tab ... I think most options could be mapped to other IDEs.
We could then just either add GotoDefinitionSplit or add an argument to GotoDefinition with the target.
Activity
dantleech commentedon May 24, 2018
Problem is this could get quickly out of control when making several jumps?
weirdan commentedon May 24, 2018
And the default would be the same behavior as it is now, so it's up to the user to enable this. It's also quite easy to get rid of all but the current split with quick
Ctrl-w o.There are problems with current approach:
So now to be able to navigate to, say, method definition I have to do the split manually and only then invoke phpactor.
Hmm... I could probably automate that instead though, so instead of just invoking the menu the mapping would do the split first.
weirdan commentedon May 24, 2018
nmap <Leader>mm <C-w>s :call phpactor#ContextMenu()<CR>does the trick. Except not every action from that menu needs the split, but it's good enough for now. Certainly better than doing the split manually.dantleech commentedon May 24, 2018
hmm, it didn't work if the destination file was open and changed, that's fixed in develop. But what you say works for me 🤔
weirdan commentedon May 24, 2018
Yeah, I've seen that commit in develop. I'm talking about the "source" buffer, though. If it's changed, and it's the only window containing the buffer, editing another file ("navigating away") in it fails.
weirdan commentedon May 24, 2018
If you haven't seen that, you might be running with 'hidden' option set.
dantleech commentedon May 24, 2018
Indeed I am
dantleech commentedon Sep 11, 2018
I guess one simple thing to do would be to introduce a way to specify the way to "open" a file.
Currently it is always
:editif it is a different file than the current one. The following switches it tovsplitonopen_file:This obviously isn't a flexible solution, but we could easily offer a way to specify a global opening strategy (e.g.
vsplit,split,tabnew,edit, etc.Even better would be a way to dynamically choose the opening strategy, but this might be best done with a keyboard shortcut, eg.
<leader>gotfor GOto definition new Tab. And providing an easy way to specify the strategy - although as it goes through RPC, this would involve some kind of state hack.[-]Option to control navigation window[/-][+][VIM Plugin] Option to control navigation window[/+]jesseleite commentedon Feb 20, 2019
Messing with this mapping for going to definition in new vertical split...
It works, but if it can't find/goto definition, I'm left having to manually close the split. Do you know if I can check for definition existence first before opening split? Or what do you think of adding an alias functions like:
Or maybe via a parameter into
phpactor#GotoDefinition()? Thoughts?dantleech commentedon Feb 20, 2019
I think this would be great. We can add it as a parameter for sure I think, then it's a question of if we add proxy methods, but if you wanted to make a PR for the parameter way, that could go in I think (we can also update the example config with a mapping for opening in a split)
dantleech commentedon Feb 20, 2019
Saying that, it also +may_ make sense to support this on the RPC level with the
OpenFileResponse, in which case we can pass the preference to Phpactor and it will return theOpenFileResponsewith the appropriate strategy, which can then be interpreted by the VIM plugin.I guess it's possible to imagine other situations where it's desirable for Phpactor to instruct the editor to open a new split or a new tab.
jesseleite commentedon Feb 20, 2019
Wicked, would the vimscript parameter just accept
split,vsplit, ortabstring values? You also lost me at RPC 😓dantleech commentedon Feb 20, 2019
haha. It's the remote-procedure-call that you can see happening in the GotoDefinition function in the vimscript. It sends the command to Phpactor, and Phpactor returns a command to open the file, it might make sense for Phpactor to additionally be responsible for saying if the file should be opened in a split etc. In which case we would pass our preference to the RPC call.
Not complicated change, but I guess involved. If you can find a non-disruptive way to do it in the plugin only, that would be fine. I guess a string value would also be fine assuming there are no Enums in vimscript.
jesseleite commentedon Feb 21, 2019
Well the plugin is vim-specific right? The PHP side of phpactor is vim-agnostic, isn't it? If so, wouldn't it make sense to keep
:split,:vsplit,:tab, etc. related terminology in the plugin?Taluu commentedon Feb 21, 2019
I think I already mentionned it somewhere, but how about using the same mecanism as the
helpwindow (I think it's the preview pane) ? So that on the first call you would indeed jump into the preview pane, but then on calls after that one you stay in that pane...daraul commentedon May 15, 2019
I like @jesseleite's solution
I just wish there was a way for phpactor to just not do anything if it can't find the definition I want to open, and instruct the editor to not open the split at all.
jesseleite commentedon May 15, 2019
Sorry, haven't had time to look further into a PR for this, but definitely still want the feature! 100% agree though, if phpactor can't find the definition, it shouldn't open a split at all 👍
dantleech commentedon May 15, 2019
I think due to the way that GotoDefinition is invoked:
and the response:
It seems necessary for the "server" to provide a hint as to how the file should be opened (at which point I'm doubting the "static constructor" approach here), but basically maybe there should be a
targetreturned which could benew,horizontal|vertical split, ortab... I think most options could be mapped to other IDEs.We could then just either add
GotoDefinitionSplitor add an argument toGotoDefinitionwith the target.dantleech commentedon May 15, 2019
#762
jesseleite commentedon May 16, 2019
Oh fantastic, thanks for working on this @dantleech ❤️
dantleech commentedon May 18, 2019
Merged into develop :)