YouCompleteMe
YouCompleteMe copied to clipboard
[feature request] let g:ycm_goto_buffer_command combine 'same-buffer' and 'split-or-existing-window'
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!
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"?
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.
mods are what you called "prefix" in your first post. See :h <mods>.
Ah, sorry for misunderstood your meaning.
I'm asking for "listen to <mods> and existing-window".
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.
I still don't fully understand what feature this is requesting.
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.
- 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"
Hi @bstaletic @puremourning is it possiable to let YCM read g:ycm_goto_buffer_command each time before run command like GoToDefinition?
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
Hi, @puremourning will my issue be solved if I just change line
https://github.com/ycm-core/YouCompleteMe/blob/9f4d1011ce90f76cb91f8cfc3db63c7557672efa/python/ycm/youcompleteme.py#L421
to
vim.eval('g:ycm_goto_buffer_command'),
Am I right without talking about tests?
Maybe. Does it?
Yes, it works well for me.
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
https://github.com/ycm-core/YouCompleteMe/blob/50379d35ddc38ee3651f568d080442d5e4cb4a3a/python/ycm/tests/command_test.py#L29
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,
} )
} )
)
)
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!