Skip to content

[VIM Plugin] Option to control navigation window #485

Closed

Description

@weirdan

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.

Activity

  1. dantleech commented on May 24, 2018

    @dantleech
    Collaborator

    Problem is this could get quickly out of control when making several jumps?

  2. weirdan commented on May 24, 2018

    @weirdan
    ContributorAuthor

    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:

    1. It doesn't work when current window contains changed buffer (not with my default settings anyway)
    2. 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.

  3. weirdan commented on May 24, 2018

    @weirdan
    ContributorAuthor

    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.

  4. dantleech commented on May 24, 2018

    @dantleech
    Collaborator

    It doesn't work when current window contains changed buffer (not with my default settings anyway)

    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 🤔

  5. weirdan commented on May 24, 2018

    @weirdan
    ContributorAuthor

    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.

  6. weirdan commented on May 24, 2018

    @weirdan
    ContributorAuthor

    If you haven't seen that, you might be running with 'hidden' option set.

  7. dantleech commented on May 24, 2018

    @dantleech
    Collaborator

    Indeed I am

  8. dantleech commented on Sep 11, 2018

    @dantleech
    Collaborator

    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.

  9. changed the title [-]Option to control navigation window[/-] [+][VIM Plugin] Option to control navigation window[/+] on Sep 11, 2018
  10. jesseleite commented on Feb 20, 2019

    @jesseleite

    Messing with this mapping for going to definition in new vertical split...

    nmap <Leader>vg :vsplit<CR>:call phpactor#GotoDefinition()<CR>

    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:

    phpactor#GotoDefinitionSplit()
    phpactor#GotoDefinitionVSplit()
    phpactor#GotoDefinitionTab()

    Or maybe via a parameter into phpactor#GotoDefinition()? Thoughts?

  11. dantleech commented on Feb 20, 2019

    @dantleech
    Collaborator

    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)

  12. dantleech commented on Feb 20, 2019

    @dantleech
    Collaborator

    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.

  13. jesseleite commented on Feb 20, 2019

    @jesseleite

    Wicked, would the vimscript parameter just accept split, vsplit, or tab string values? You also lost me at RPC 😓

  14. dantleech commented on Feb 20, 2019

    @dantleech
    Collaborator

    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.

  15. jesseleite commented on Feb 21, 2019

    @jesseleite

    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?

  16. Taluu commented on Feb 21, 2019

    @Taluu
    Contributor

    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...

  17. daraul commented on May 15, 2019

    @daraul

    I like @jesseleite's solution

    nmap vg :vsplit:call phpactor#GotoDefinition()

    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.

  18. jesseleite commented on May 15, 2019

    @jesseleite

    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 👍

  19. dantleech commented on May 15, 2019

    @dantleech
    Collaborator

    I think due to the way that GotoDefinition is invoked:

    function! phpactor#GotoDefinition()
        call phpactor#rpc("goto_definition", { "offset": phpactor#_offset(), "source": phpactor#_source(), "path": expand('%:p'), 'language': &ft})
    endfunction
    

    and the response:

            return OpenFileResponse::fromPathAndOffset(
    

    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.

  20. dantleech commented on May 15, 2019

    @dantleech
    Collaborator
  21. jesseleite commented on May 16, 2019

    @jesseleite

    Oh fantastic, thanks for working on this @dantleech ❤️

  22. dantleech commented on May 18, 2019

    @dantleech
    Collaborator

    Merged into develop :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions