Skip to content

Commit

Permalink
Merge pull request #4137 from eliasdaler/master
Browse files Browse the repository at this point in the history
Add the ability to pass popup_params when creating a custom ycm_hover
  • Loading branch information
mergify[bot] committed Mar 20, 2023
2 parents aaebb55 + a4a869c commit d0657bb
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 12 deletions.
20 changes: 20 additions & 0 deletions README.md
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
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
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
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

0 comments on commit d0657bb

Please sign in to comment.