Skip to content

Commit 69e9803

Browse files
authored
Merge branch 'master' into changedtick-empty
2 parents 52ff5a3 + d0657bb commit 69e9803

File tree

4 files changed

+105
-12
lines changed

4 files changed

+105
-12
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,6 +3019,7 @@ buffer-local variable can be set to a dictionary with the following keys:
30193019
* `command`: The YCM completer subcommand which should be run on hover
30203020
* `syntax`: The syntax to use (as in `set syntax=`) in the popup window for
30213021
highlighting.
3022+
* `popup_params`: The params passed to a popup window which gets opened.
30223023

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

3037+
You can also modify the opened popup with `popup_params` key.
3038+
For example, you can limit the popup's maximum width and add a border to it:
3039+
3040+
```viml
3041+
augroup MyYCMCustom
3042+
autocmd!
3043+
autocmd FileType c,cpp let b:ycm_hover = {
3044+
\ 'command': 'GetDoc',
3045+
\ 'syntax': &filetype
3046+
\ 'popup_params': {
3047+
\ 'maxwidth': 80,
3048+
\ 'border': [],
3049+
\ 'borderchars': ['─', '│', '─', '│', '┌', '┐', '┘', '└'],
3050+
\ },
3051+
\ }
3052+
augroup END
3053+
```
3054+
See `:help popup_create-arguments` for the list of available popup window options.
3055+
30363056
Default: `'CursorHold'`
30373057

30383058
### The `g:ycm_filter_diagnostics` option

autoload/youcompleteme.vim

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,18 +1650,22 @@ if exists( '*popup_atcursor' )
16501650
let wrap = 1
16511651
endif
16521652

1653-
let s:cursorhold_popup = popup_atcursor(
1654-
\ lines,
1655-
\ {
1656-
\ 'col': col,
1657-
\ 'wrap': wrap,
1658-
\ 'padding': [ 0, 1, 0, 1 ],
1659-
\ 'moved': 'word',
1660-
\ 'maxwidth': &columns,
1661-
\ 'close': 'click',
1662-
\ 'fixed': 0,
1663-
\ }
1664-
\ )
1653+
let popup_params = {
1654+
\ 'col': col,
1655+
\ 'wrap': wrap,
1656+
\ 'padding': [ 0, 1, 0, 1 ],
1657+
\ 'moved': 'word',
1658+
\ 'maxwidth': &columns,
1659+
\ 'close': 'click',
1660+
\ 'fixed': 0,
1661+
\ }
1662+
1663+
if has_key( b:ycm_hover, 'popup_params' )
1664+
let popup_params = extend( copy( popup_params ),
1665+
\ b:ycm_hover.popup_params )
1666+
endif
1667+
1668+
let s:cursorhold_popup = popup_atcursor( lines, popup_params )
16651669
call setbufvar( winbufnr( s:cursorhold_popup ),
16661670
\ '&syntax',
16671671
\ b:ycm_hover.syntax )

doc/youcompleteme.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3277,6 +3277,7 @@ This buffer-local variable can be set to a dictionary with the following keys:
32773277
- 'command': The YCM completer subcommand which should be run on hover
32783278
- 'syntax': The syntax to use (as in 'set syntax=') in the popup window for
32793279
highlighting.
3280+
- 'popup_params': The params passed to a popup window which gets opened.
32803281

32813282
For example, to use C/C++ syntax highlighting in the popup for C-family
32823283
languages, add something like this to your vimrc:
@@ -3289,6 +3290,27 @@ languages, add something like this to your vimrc:
32893290
\ }
32903291
augroup END
32913292
<
3293+
You can also modify the opened popup with 'popup_params' key. For example, you
3294+
can limit the popup's maximum width and add a border to it:
3295+
3296+
3297+
>
3298+
augroup MyYCMCustom
3299+
autocmd!
3300+
autocmd FileType c,cpp let b:ycm_hover = {
3301+
\ 'command': 'GetDoc',
3302+
\ 'syntax': &filetype
3303+
\ 'popup_params': {
3304+
\ 'maxwidth': 80,
3305+
\ 'border': [],
3306+
\ 'borderchars': ['─', '│', '─', '│', '┌', '┐', '┘', '└'],
3307+
\ },
3308+
\ }
3309+
augroup END
3310+
<
3311+
See ':help popup_create-arguments' for the list of available popup window
3312+
options.
3313+
32923314
Default: "'CursorHold'"
32933315

32943316
-------------------------------------------------------------------------------

test/hover.test.vim

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,53 @@ function! TearDown_Test_Hover_Custom_Command()
387387
silent! au! MyYCMCustom
388388
endfunction
389389

390+
function! SetUp_Test_Hover_Custom_Popup()
391+
augroup MyYCMCustom
392+
autocmd!
393+
autocmd FileType cpp let b:ycm_hover = {
394+
\ 'command': 'GetDoc',
395+
\ 'syntax': 'cpp',
396+
\ 'popup_params': {
397+
\ 'maxwidth': 10,
398+
\ }
399+
\ }
400+
augroup END
401+
endfunction
402+
403+
function! Test_Hover_Custom_Popup()
404+
call youcompleteme#test#setup#OpenFile( '/test/testdata/cpp/completion.cc',
405+
\ {} )
406+
call assert_equal( 'cpp', &filetype )
407+
call assert_equal( {
408+
\ 'command': 'GetDoc',
409+
\ 'syntax': 'cpp',
410+
\ 'popup_params': { 'maxwidth': 10 }
411+
\ }, b:ycm_hover )
412+
413+
call setpos( '.', [ 0, 6, 8 ] )
414+
doautocmd CursorHold
415+
call assert_equal( {
416+
\ 'command': 'GetDoc',
417+
\ 'syntax': 'cpp',
418+
\ 'popup_params': { 'maxwidth': 10 }
419+
\ }, b:ycm_hover )
420+
421+
call s:CheckPopupVisibleScreenPos( { 'row': 7, 'col': 9 },
422+
\ s:cpp_lifetime.GetDoc,
423+
\ 'cpp' )
424+
" Check that popup's width is limited by maxwidth being passed
425+
call s:CheckPopupNotVisibleScreenPos( { 'row': 7, 'col': 20 }, v:false )
426+
427+
normal \D
428+
call s:CheckPopupNotVisibleScreenPos( { 'row': 7, 'col': 9 }, v:false )
429+
430+
call popup_clear()
431+
endfunction
432+
433+
function! TearDown_Test_Hover_Custom_Popup()
434+
silent! au! MyYCMCustom
435+
endfunction
436+
390437
function! Test_Long_Single_Line()
391438
call youcompleteme#test#setup#OpenFile( '/test/testdata/python/doc.py', {} )
392439
call cursor( [ 37, 3 ] )

0 commit comments

Comments
 (0)