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

[feature request] let g:ycm_goto_buffer_command combine 'same-buffer' and 'split-or-existing-window' #3838

Open
roachsinai opened this issue Jan 17, 2021 · 15 comments
Labels
enhancement PR Welcome A good quality PR for this feature would be considered.

Comments

@roachsinai
Copy link

Issue Details

For current setting if I set g:ycm_goto_buffer_command to split-or-existing-window I could use :rightbelow YcmCompleter GoToDefinition to open in a horizontal window if the result not open, and use :rightbelow vert YcmCompleter GoToDefinition to open in a vertical window if the result not open, too.

What I wish is open result in current window when no prefix for YcmCompleter GoToDefinition. So the expected behavior different with 'split-or-existing-window' is new setting support open result in split or current buffer, it like a combine with same-buffer and split-or-existing-window.

New setting will check whether has a prefix for YcmCompleter or not. If has a prefix it will do the way what 'split-or-existing-window' does, if no prefix it will do like sam-buffer-or-existing-window.


I'm not a native speaker of English. Sorry for grammer errors.

Thanks in advance!

@bstaletic
Copy link
Collaborator

Hi. I'm aware that the behaviour of split-or-existing-window isn't always perfect. Is what you're asking for basically "listen to <mods> and don't be a smartass"?

@roachsinai
Copy link
Author

Don't know the meaning of wrod mods.

But for samrtass, I just thought it will be better if there is a way I can let the result of GoToDefinition to open in current window or split vertical or horizontal. And maybe it's a smartass from your point.

@bstaletic thanks for your reply.

@bstaletic
Copy link
Collaborator

mods are what you called "prefix" in your first post. See :h <mods>.

@roachsinai
Copy link
Author

Ah, sorry for misunderstood your meaning.

I'm asking for "listen to <mods> and existing-window".

@roachsinai
Copy link
Author

function YcmSplitHelper(complete_command)
  let actions = ['', 'rightbelow ', 'rightbelow vert ']
  let choice = confirm("Action?", "&Edit\n&Split\n&Vsplit", 1) - 1
  if choice == -1 | return | endif
  let g:ycm_goto_buffer_command = choice == 0 ? 'same-buffer' : 'split-or-existing-window'
  execute(actions[choice] . a:complete_command)
endfunction

nnoremap <leader>sr :call YcmSplitHelper('YcmCompleter GoToDeclaration')<CR>
nnoremap <leader>sd :call YcmSplitHelper('YcmCompleter GoToDefinition')<CR>
nnoremap <leader>sg :call YcmSplitHelper('YcmCompleter GoToDefinitionElseDeclaration')<CR>

I've define above function to make this, but seems variable ycm_goto_buffer_command only works when ycm starting, after that change its value can't change the behavior.

@puremourning
Copy link
Member

I still don't fully understand what feature this is requesting.

@puremourning
Copy link
Member

Wait is the logic:

  • If there are mods, use "always split"
  • If there are no mods, use "split or current buffer"

?

if so I think I can understand that.

@roachsinai
Copy link
Author

  • If there are mods, use "always split"
  • If there are no mods, use "split or current buffer"

In my opinion it should be:

  • If there are mods, use "always split"
  • If there are no mods, use "split(unless current buffer can not be switched) or current buffer"

@roachsinai
Copy link
Author

Hi @bstaletic @puremourning is it possiable to let YCM read g:ycm_goto_buffer_command each time before run command like GoToDefinition?

@puremourning puremourning added enhancement PR Welcome A good quality PR for this feature would be considered. labels Aug 27, 2022
@puremourning
Copy link
Member

that would be possible (and not difficult). would accept a pr with vim-layer tests that changes it to just read vim.vars rather than its own config store

@roachsinai
Copy link
Author

Hi, @puremourning will my issue be solved if I just change line

self._user_options[ 'goto_buffer_command' ],

to

vim.eval('g:ycm_goto_buffer_command'),

Am I right without talking about tests?

@puremourning
Copy link
Member

Maybe. Does it?

@roachsinai
Copy link
Author

Yes, it works well for me.

@roachsinai
Copy link
Author

Hi, @puremourning .

I'm very glad to make a pr for YCM!!!

But seems it's hard for me to write a corresponding test. I think the test should be add at

@YouCompleteMeInstance( { 'g:ycm_extra_conf_vim_data': [ 'tempname()' ] } )

after search at source code.

And I write a demo:

  @YouCompleteMeInstance( {
    'g:ycm_goto_buffer_command': 'split-or-existing-window' } )
  def test_SendCommandRequest_ReadVimVars_GoToBufferCommand( self, ycm ):
    current_buffer = VimBuffer( 'buffer' )
    with MockVimBuffers( [ current_buffer ], [ current_buffer ] ):
      with patch( 'ycm.youcompleteme.SendCommandRequest' ) as send_request:
        ycm.SendCommandRequest( [ 'GoTo' ], 'belowright', False, 1, 1 )
        assert_that(
          # Positional arguments passed to SendCommandRequest.
          send_request.call_args[ 0 ],
          contains_exactly(
            contains_exactly( 'GoTo' ),
            'belowright',
            'split-or-existing-window',
            has_entries( {
              'options': has_entries( {
                'tab_size': 2,
                'insert_spaces': True,
              } )
            } )
          )
        )

@roachsinai
Copy link
Author

roachsinai commented Dec 1, 2023

For now, I have two questions.

One: how to trigger the test as run ./test/run_vim_tests commands.test.vim doesn't work as expect?
Two: Help me write a right test funtion if anthing wrong with the posted funtion above.

By the way, is there a new contact method as gitter can't access.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement PR Welcome A good quality PR for this feature would be considered.
Projects
None yet
Development

No branches or pull requests

3 participants