Auto merge of #2860 - micbou:toggle-logs-prompt, r=puremourning
[READY] Prompt the user to select a logfile with the YcmToggleLogs command Instead of displaying the list of available logfiles, prompt the user to open (or close if already open) one of them when running the `:YcmToggleLogs` command with no arguments. Keep the current behavior when one or more arguments are given. ![toggle-logs-prompt](https://user-images.githubusercontent.com/10026824/34301520-39affee2-e72d-11e7-9c94-9a37beaabcce.gif) <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/youcompleteme/2860) <!-- Reviewable:end -->
This commit is contained in:
commit
757c5e5be4
12
README.md
12
README.md
@ -1283,9 +1283,15 @@ completion engine.
|
|||||||
|
|
||||||
### The `:YcmToggleLogs` command
|
### The `:YcmToggleLogs` command
|
||||||
|
|
||||||
This command opens in separate windows the logfiles given as arguments or closes
|
This command presents the list of logfiles created by YCM, the [ycmd
|
||||||
them if they are already open in the editor. When no argument is given, list the
|
server][ycmd], and the semantic engine server for the current filetype, if any.
|
||||||
available logfiles. Only for debugging purpose.
|
One of these logfiles can be opened in the editor (or closed if already open) by
|
||||||
|
entering the corresponding number or by clicking on it with the mouse.
|
||||||
|
Additionally, this command can take the logfile names as arguments. Use the
|
||||||
|
`<TAB>` key (or any other key defined by the `wildchar` option) to complete the
|
||||||
|
arguments or to cycle through them (depending on the value of the `wildmode`
|
||||||
|
option). Each logfile given as an argument is directly opened (or closed if
|
||||||
|
already open) in the editor. Only for debugging purposes.
|
||||||
|
|
||||||
### The `:YcmCompleter` command
|
### The `:YcmCompleter` command
|
||||||
|
|
||||||
|
@ -1553,9 +1553,15 @@ semantic completion engine.
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
The *:YcmToggleLogs* command
|
The *:YcmToggleLogs* command
|
||||||
|
|
||||||
This command opens in separate windows the logfiles given as arguments or
|
This command presents the list of logfiles created by YCM, the ycmd server
|
||||||
closes them if they are already open in the editor. When no argument is given,
|
[43], and the semantic engine server for the current filetype, if any. One of
|
||||||
list the available logfiles. Only for debugging purpose.
|
these logfiles can be opened in the editor (or closed if already open) by
|
||||||
|
entering the corresponding number or by clicking on it with the mouse.
|
||||||
|
Additionally, this command can take the logfile names as arguments. Use the
|
||||||
|
'<TAB>' key (or any other key defined by the 'wildchar' option) to complete the
|
||||||
|
arguments or to cycle through them (depending on the value of the 'wildmode'
|
||||||
|
option). Each logfile given as an argument is directly opened (or closed if
|
||||||
|
already open) in the editor. Only for debugging purposes.
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
The *:YcmCompleter* command
|
The *:YcmCompleter* command
|
||||||
|
@ -273,24 +273,56 @@ def YouCompleteMe_ToggleLogs_WithParameters_test( ycm,
|
|||||||
|
|
||||||
|
|
||||||
@YouCompleteMeInstance()
|
@YouCompleteMeInstance()
|
||||||
|
# Select the second item of the list which is the ycmd stderr logfile.
|
||||||
|
@patch( 'ycm.vimsupport.SelectFromList', return_value = 1 )
|
||||||
|
@patch( 'ycm.vimsupport.OpenFilename', new_callable = ExtendedMock )
|
||||||
|
def YouCompleteMe_ToggleLogs_WithoutParameters_SelectLogfileNotAlreadyOpen_test(
|
||||||
|
ycm, open_filename, *args ):
|
||||||
|
|
||||||
|
current_buffer = VimBuffer( 'current_buffer' )
|
||||||
|
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
||||||
|
ycm.ToggleLogs()
|
||||||
|
|
||||||
|
open_filename.assert_has_exact_calls( [
|
||||||
|
call( ycm._server_stderr, { 'size': 12,
|
||||||
|
'watch': True,
|
||||||
|
'fix': True,
|
||||||
|
'focus': False,
|
||||||
|
'position': 'end' } )
|
||||||
|
] )
|
||||||
|
|
||||||
|
|
||||||
|
@YouCompleteMeInstance()
|
||||||
|
# Select the third item of the list which is the ycmd stdout logfile.
|
||||||
|
@patch( 'ycm.vimsupport.SelectFromList', return_value = 2 )
|
||||||
|
@patch( 'ycm.vimsupport.CloseBuffersForFilename', new_callable = ExtendedMock )
|
||||||
|
def YouCompleteMe_ToggleLogs_WithoutParameters_SelectLogfileAlreadyOpen_test(
|
||||||
|
ycm, close_buffers_for_filename, *args ):
|
||||||
|
|
||||||
|
logfile_buffer = VimBuffer( ycm._server_stdout, window = 1 )
|
||||||
|
with MockVimBuffers( [ logfile_buffer ], logfile_buffer ):
|
||||||
|
ycm.ToggleLogs()
|
||||||
|
|
||||||
|
close_buffers_for_filename.assert_has_exact_calls( [
|
||||||
|
call( ycm._server_stdout )
|
||||||
|
] )
|
||||||
|
|
||||||
|
|
||||||
|
@YouCompleteMeInstance()
|
||||||
|
@patch( 'ycm.vimsupport.SelectFromList',
|
||||||
|
side_effect = RuntimeError( 'Error message' ) )
|
||||||
@patch( 'ycm.vimsupport.PostVimMessage' )
|
@patch( 'ycm.vimsupport.PostVimMessage' )
|
||||||
def YouCompleteMe_ToggleLogs_WithoutParameters_test( ycm, post_vim_message ):
|
def YouCompleteMe_ToggleLogs_WithoutParameters_NoSelection_test(
|
||||||
# We test on a Python buffer because the Python completer has subserver
|
ycm, post_vim_message, *args ):
|
||||||
# logfiles.
|
|
||||||
python_buffer = VimBuffer( 'buffer.py', filetype = 'python' )
|
current_buffer = VimBuffer( 'current_buffer' )
|
||||||
with MockVimBuffers( [ python_buffer ], python_buffer ):
|
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
||||||
ycm.ToggleLogs()
|
ycm.ToggleLogs()
|
||||||
|
|
||||||
assert_that(
|
assert_that(
|
||||||
# Argument passed to PostVimMessage.
|
# Argument passed to PostVimMessage.
|
||||||
post_vim_message.call_args[ 0 ][ 0 ],
|
post_vim_message.call_args[ 0 ][ 0 ],
|
||||||
matches_regexp(
|
equal_to( 'Error message' )
|
||||||
'Available logfiles are:\n'
|
|
||||||
'jedihttp_\d+_stderr_.+.log\n'
|
|
||||||
'jedihttp_\d+_stdout_.+.log\n'
|
|
||||||
'ycm_.+.log\n'
|
|
||||||
'ycmd_\d+_stderr_.+.log\n'
|
|
||||||
'ycmd_\d+_stdout_.+.log' )
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -542,8 +542,8 @@ def SelectFromList( prompt, items ):
|
|||||||
|
|
||||||
|items| should not contain leading ordinals: they are added automatically.
|
|items| should not contain leading ordinals: they are added automatically.
|
||||||
|
|
||||||
Returns the 0-based index in the list |items| that the user selected, or a
|
Returns the 0-based index in the list |items| that the user selected, or an
|
||||||
negative number if no valid item was selected.
|
exception if no valid item was selected.
|
||||||
|
|
||||||
See also :help inputlist()."""
|
See also :help inputlist()."""
|
||||||
|
|
||||||
|
@ -652,9 +652,20 @@ class YouCompleteMe( object ):
|
|||||||
def ToggleLogs( self, *filenames ):
|
def ToggleLogs( self, *filenames ):
|
||||||
logfiles = self.GetLogfiles()
|
logfiles = self.GetLogfiles()
|
||||||
if not filenames:
|
if not filenames:
|
||||||
vimsupport.PostVimMessage(
|
sorted_logfiles = sorted( list( logfiles ) )
|
||||||
'Available logfiles are:\n'
|
try:
|
||||||
'{0}'.format( '\n'.join( sorted( list( logfiles ) ) ) ) )
|
logfile_index = vimsupport.SelectFromList(
|
||||||
|
'Which logfile do you wish to open (or close if already open)?',
|
||||||
|
sorted_logfiles )
|
||||||
|
except RuntimeError as e:
|
||||||
|
vimsupport.PostVimMessage( str( e ) )
|
||||||
|
return
|
||||||
|
|
||||||
|
logfile = logfiles[ sorted_logfiles[ logfile_index ] ]
|
||||||
|
if not vimsupport.BufferIsVisibleForFilename( logfile ):
|
||||||
|
self._OpenLogfile( logfile )
|
||||||
|
else:
|
||||||
|
self._CloseLogfile( logfile )
|
||||||
return
|
return
|
||||||
|
|
||||||
for filename in set( filenames ):
|
for filename in set( filenames ):
|
||||||
|
Loading…
Reference in New Issue
Block a user