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

Add the ability to pass popup_params when creating a custom ycm_hover #4137

Merged
merged 5 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3019,6 +3019,7 @@ buffer-local variable can be set to a dictionary with the following keys:
* `command`: The YCM completer subcommand which should be run on hover
* `syntax`: The syntax to use (as in `set syntax=`) in the popup window for
highlighting.
* `popup_params`: The params passed to a popup window which gets opened.

For example, to use C/C++ syntax highlighting in the popup for C-family
languages, add something like this to your vimrc:
Expand All @@ -3033,6 +3034,25 @@ augroup MyYCMCustom
augroup END
```

You can also modify the opened popup with `popup_params` key.
For example, you can limit the popup's maximum width and add a border to it:

```viml
augroup MyYCMCustom
autocmd!
autocmd FileType c,cpp let b:ycm_hover = {
\ 'command': 'GetDoc',
\ 'syntax': &filetype
\ 'popup_params': {
\ 'maxwidth': 80,
\ 'border': [],
\ 'borderchars': ['─', '│', '─', '│', '┌', '┐', '┘', '└'],
\ },
\ }
augroup END
```
See `:help popup_create-arguments` for the list of available popup window options.

Default: `'CursorHold'`

### The `g:ycm_filter_diagnostics` option
Expand Down
28 changes: 16 additions & 12 deletions autoload/youcompleteme.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1650,18 +1650,22 @@ if exists( '*popup_atcursor' )
let wrap = 1
endif

let s:cursorhold_popup = popup_atcursor(
\ lines,
\ {
\ 'col': col,
\ 'wrap': wrap,
\ 'padding': [ 0, 1, 0, 1 ],
\ 'moved': 'word',
\ 'maxwidth': &columns,
\ 'close': 'click',
\ 'fixed': 0,
\ }
\ )
let popup_params = {
\ 'col': col,
\ 'wrap': wrap,
\ 'padding': [ 0, 1, 0, 1 ],
\ 'moved': 'word',
\ 'maxwidth': &columns,
\ 'close': 'click',
\ 'fixed': 0,
\ }

if has_key( b:ycm_hover, 'popup_params' )
let popup_params = extend( copy( popup_params ),
\ b:ycm_hover.popup_params )
endif

let s:cursorhold_popup = popup_atcursor( lines, popup_params )
call setbufvar( winbufnr( s:cursorhold_popup ),
\ '&syntax',
\ b:ycm_hover.syntax )
Expand Down
22 changes: 22 additions & 0 deletions doc/youcompleteme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3277,6 +3277,7 @@ This buffer-local variable can be set to a dictionary with the following keys:
- 'command': The YCM completer subcommand which should be run on hover
- 'syntax': The syntax to use (as in 'set syntax=') in the popup window for
highlighting.
- 'popup_params': The params passed to a popup window which gets opened.

For example, to use C/C++ syntax highlighting in the popup for C-family
languages, add something like this to your vimrc:
Expand All @@ -3289,6 +3290,27 @@ languages, add something like this to your vimrc:
\ }
augroup END
<
You can also modify the opened popup with 'popup_params' key. For example, you
can limit the popup's maximum width and add a border to it:


>
augroup MyYCMCustom
autocmd!
autocmd FileType c,cpp let b:ycm_hover = {
\ 'command': 'GetDoc',
\ 'syntax': &filetype
\ 'popup_params': {
\ 'maxwidth': 80,
\ 'border': [],
\ 'borderchars': ['─', '│', '─', '│', '┌', '┐', '┘', '└'],
\ },
\ }
augroup END
<
See ':help popup_create-arguments' for the list of available popup window
options.

Default: "'CursorHold'"

-------------------------------------------------------------------------------
Expand Down
47 changes: 47 additions & 0 deletions test/hover.test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,53 @@ function! TearDown_Test_Hover_Custom_Command()
silent! au! MyYCMCustom
endfunction

function! SetUp_Test_Hover_Custom_Popup()
augroup MyYCMCustom
autocmd!
autocmd FileType cpp let b:ycm_hover = {
\ 'command': 'GetDoc',
\ 'syntax': 'cpp',
\ 'popup_params': {
\ 'maxwidth': 10,
\ }
\ }
augroup END
endfunction

function! Test_Hover_Custom_Popup()
call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/completion.cc',
\ {} )
call assert_equal( 'cpp', &filetype )
call assert_equal( {
\ 'command': 'GetDoc',
\ 'syntax': 'cpp',
\ 'popup_params': { 'maxwidth': 10 }
\ }, b:ycm_hover )

call setpos( '.', [ 0, 6, 8 ] )
doautocmd CursorHold
call assert_equal( {
\ 'command': 'GetDoc',
\ 'syntax': 'cpp',
\ 'popup_params': { 'maxwidth': 10 }
\ }, b:ycm_hover )

call s:CheckPopupVisibleScreenPos( { 'row': 7, 'col': 9 },
\ s:cpp_lifetime.GetDoc,
\ 'cpp' )
" Check that popup's width is limited by maxwidth being passed
call s:CheckPopupNotVisibleScreenPos( { 'row': 7, 'col': 20 }, v:false )

normal \D
call s:CheckPopupNotVisibleScreenPos( { 'row': 7, 'col': 9 }, v:false )

call popup_clear()
endfunction

function! TearDown_Test_Hover_Custom_Popup()
silent! au! MyYCMCustom
endfunction

function! Test_Long_Single_Line()
call youcompleteme#test#setup#OpenFile( '/test/testdata/python/doc.py', {} )
call cursor( [ 37, 3 ] )
Expand Down