Skip to content

Commit f994844

Browse files
authored
Merge branch 'master' into dont-clear-screen-syntax
2 parents f8af00f + 95a5d54 commit f994844

File tree

6 files changed

+93
-12
lines changed

6 files changed

+93
-12
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,11 @@ See the [file type feature summary](#quick-feature-summary) for an overview of
19311931
the features available for each file type. See the _YcmCompleter subcommands_
19321932
section for more information on the available subcommands and their usage.
19331933

1934+
Some commands, like `Format` accept a range, like `:%YcmCompleter Format`.
1935+
1936+
Some commands like `GetDoc` and the various `GoTo` commands respect modifiers,
1937+
like `:rightbelow YcmCompleter GetDoc`, `:vertical YcmCompleter GoTo`.
1938+
19341939
YcmCompleter Subcommands
19351940
------------------------
19361941

@@ -2147,6 +2152,27 @@ under the cursor. Depending on the file type, this includes things like:
21472152
* Python docstrings,
21482153
* etc.
21492154

2155+
The documentation is opened in the preview window, and options like
2156+
`previewheight` are respected. If you would like to customise the height and
2157+
position of this window, we suggest a custom command that:
2158+
2159+
* Sets `previewheight` temporarily
2160+
* Runs the `GetDoc` command with supplied modifiers
2161+
* Restores `previewheight`.
2162+
2163+
For example:
2164+
2165+
```viml
2166+
command -count ShowDocWithSize
2167+
\ let g:ph=&previewheight
2168+
\ <bar> set previewheight=<count>
2169+
\ <bar> <mods> YcmCompleter GetDoc
2170+
\ <bar> let &previewheight=g:ph
2171+
```
2172+
2173+
You can then use something like `:botright vertical 80ShowDocWithSize`. Here's an
2174+
example of that: https://asciinema.org/a/hE6Pi1gU6omBShwFna8iwGEe9
2175+
21502176
Supported in filetypes: `c, cpp, objc, objcpp, cuda, cs, go, java, javascript,
21512177
python, typescript, rust`
21522178

doc/youcompleteme.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,11 @@ See the file type feature summary for an overview of the features available for
21822182
each file type. See the _YcmCompleter subcommands_ section for more information
21832183
on the available subcommands and their usage.
21842184

2185+
Some commands, like |Format| accept a range, like ':%YcmCompleter Format'.
2186+
2187+
Some commands like |GetDoc| and the various |GoTo| commands respect modifiers,
2188+
like ':rightbelow YcmCompleter GetDoc', ':vertical YcmCompleter GoTo'.
2189+
21852190
-------------------------------------------------------------------------------
21862191
*youcompleteme-ycmcompleter-subcommands*
21872192
YcmCompleter Subcommands ~
@@ -2418,6 +2423,25 @@ under the cursor. Depending on the file type, this includes things like:
24182423
- Python docstrings,
24192424
- etc.
24202425

2426+
The documentation is opened in the preview window, and options like
2427+
'previewheight' are respected. If you would like to customise the height and
2428+
position of this window, we suggest a custom command that:
2429+
2430+
- Sets 'previewheight' temporarily
2431+
- Runs the |GetDoc| command with supplied modifiers
2432+
- Restores 'previewheight'.
2433+
2434+
For example:
2435+
>
2436+
command -count ShowDocWithSize
2437+
\ let g:ph=&previewheight
2438+
\ <bar> set previewheight=<count>
2439+
\ <bar> <mods> YcmCompleter GetDoc
2440+
\ <bar> let &previewheight=g:ph
2441+
<
2442+
You can then use something like ':botright vertical 80ShowDocWithSize'. Here's
2443+
an example of that: https://asciinema.org/a/hE6Pi1gU6omBShwFna8iwGEe9
2444+
24212445
Supported in filetypes: 'c, cpp, objc, objcpp, cuda, cs, go, java, javascript,
24222446
python, typescript, rust'
24232447

python/ycm/client/command_request.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def RunPostCommandActionsIfNeeded( self,
9393
return self._HandleMessageResponse()
9494

9595
if 'detailed_info' in self._response:
96-
return self._HandleDetailedInfoResponse()
96+
return self._HandleDetailedInfoResponse( modifiers )
9797

9898
# The only other type of response we understand is GoTo, and that is the
9999
# only one that we can't detect just by inspecting the response (it should
@@ -201,8 +201,9 @@ def _HandleMessageResponse( self ):
201201
vimsupport.PostVimMessage( self._response[ 'message' ], warning = False )
202202

203203

204-
def _HandleDetailedInfoResponse( self ):
205-
vimsupport.WriteToPreviewWindow( self._response[ 'detailed_info' ] )
204+
def _HandleDetailedInfoResponse( self, modifiers ):
205+
vimsupport.WriteToPreviewWindow( self._response[ 'detailed_info' ],
206+
modifiers )
206207

207208

208209
def SendCommandRequestAsync( arguments, extra_data = None, silent = True ):

python/ycm/tests/client/command_request_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def DetailedInfoTest( command, info ):
283283
request = CommandRequest( [ command ] )
284284
request._response = { 'detailed_info': info }
285285
request.RunPostCommandActionsIfNeeded( 'topleft' )
286-
write_to_preview.assert_called_with( info )
286+
write_to_preview.assert_called_with( info, 'topleft' )
287287

288288
for command, info in [
289289
[ '___________', 'This is a message' ],

python/ycm/tests/vimsupport_test.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ def test_ReplaceChunks_MultiFile_Open( self,
13751375
def test_WriteToPreviewWindow( self, vim_current, vim_command ):
13761376
vim_current.window.options.__getitem__ = MagicMock( return_value = True )
13771377

1378-
vimsupport.WriteToPreviewWindow( "test" )
1378+
vimsupport.WriteToPreviewWindow( "test", '' )
13791379

13801380
vim_command.assert_has_exact_calls( [
13811381
call( 'silent! pclose!' ),
@@ -1398,11 +1398,39 @@ def test_WriteToPreviewWindow( self, vim_current, vim_command ):
13981398
call( 'readonly', True ),
13991399
], any_order = True )
14001400

1401+
@patch( 'vim.command', new_callable=ExtendedMock )
1402+
@patch( 'vim.current', new_callable=ExtendedMock )
1403+
def test_WriteToPreviewWindow_Mods( self, vim_current, vim_command ):
1404+
vim_current.window.options.__getitem__ = MagicMock( return_value = True )
1405+
1406+
vimsupport.WriteToPreviewWindow( "test", 'tab leftabove' )
1407+
1408+
vim_command.assert_has_exact_calls( [
1409+
call( 'silent! pclose!' ),
1410+
call( 'silent! tab leftabove pedit! _TEMP_FILE_' ),
1411+
call( 'silent! wincmd P' ),
1412+
call( 'silent! wincmd p' ) ] )
1413+
1414+
vim_current.buffer.__setitem__.assert_called_with(
1415+
slice( None, None, None ), [ 'test' ] )
1416+
1417+
vim_current.buffer.options.__setitem__.assert_has_exact_calls( [
1418+
call( 'modifiable', True ),
1419+
call( 'readonly', False ),
1420+
call( 'buftype', 'nofile' ),
1421+
call( 'bufhidden', 'wipe' ),
1422+
call( 'buflisted', False ),
1423+
call( 'swapfile', False ),
1424+
call( 'modifiable', False ),
1425+
call( 'modified', False ),
1426+
call( 'readonly', True ),
1427+
], any_order = True )
1428+
14011429

14021430
@patch( 'vim.current' )
14031431
def test_WriteToPreviewWindow_MultiLine( self, vim_current ):
14041432
vim_current.window.options.__getitem__ = MagicMock( return_value = True )
1405-
vimsupport.WriteToPreviewWindow( "test\ntest2" )
1433+
vimsupport.WriteToPreviewWindow( "test\ntest2", '' )
14061434

14071435
vim_current.buffer.__setitem__.assert_called_with(
14081436
slice( None, None, None ), [ 'test', 'test2' ] )
@@ -1413,7 +1441,7 @@ def test_WriteToPreviewWindow_MultiLine( self, vim_current ):
14131441
def test_WriteToPreviewWindow_JumpFail( self, vim_current, vim_command ):
14141442
vim_current.window.options.__getitem__ = MagicMock( return_value = False )
14151443

1416-
vimsupport.WriteToPreviewWindow( "test" )
1444+
vimsupport.WriteToPreviewWindow( "test", '' )
14171445

14181446
vim_command.assert_has_exact_calls( [
14191447
call( 'silent! pclose!' ),
@@ -1434,7 +1462,7 @@ def test_WriteToPreviewWindow_JumpFail_MultiLine(
14341462

14351463
vim_current.window.options.__getitem__ = MagicMock( return_value = False )
14361464

1437-
vimsupport.WriteToPreviewWindow( "test\ntest2" )
1465+
vimsupport.WriteToPreviewWindow( "test\ntest2", '' )
14381466

14391467
vim_command.assert_has_exact_calls( [
14401468
call( 'silent! pclose!' ),

python/ycm/vimsupport.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,12 +1231,14 @@ def JumpToTab( tab_number ):
12311231
vim.command( f'silent! tabn { tab_number }' )
12321232

12331233

1234-
def OpenFileInPreviewWindow( filename ):
1234+
def OpenFileInPreviewWindow( filename, modifiers ):
12351235
""" Open the supplied filename in the preview window """
1236-
vim.command( 'silent! pedit! ' + filename )
1236+
if modifiers:
1237+
modifiers = ' ' + modifiers
1238+
vim.command( f'silent!{modifiers} pedit! { filename }' )
12371239

12381240

1239-
def WriteToPreviewWindow( message ):
1241+
def WriteToPreviewWindow( message, modifiers ):
12401242
""" Display the supplied message in the preview window """
12411243

12421244
# This isn't something that comes naturally to Vim. Vim only wants to show
@@ -1248,7 +1250,7 @@ def WriteToPreviewWindow( message ):
12481250

12491251
ClosePreviewWindow()
12501252

1251-
OpenFileInPreviewWindow( vim.eval( 'tempname()' ) )
1253+
OpenFileInPreviewWindow( vim.eval( 'tempname()' ), modifiers )
12521254

12531255
if JumpToPreviewWindow():
12541256
# We actually got to the preview window. By default the preview window can't

0 commit comments

Comments
 (0)