Fix HiddenEnabled function

The 'hidden' option is a global option, not a buffer one. If this option is
false, we should check if the 'bufhidden' option, which is local to the buffer,
is set to 'hide'. If so, the buffer can be hidden despite the 'hidden' option
being false.
This commit is contained in:
micbou 2017-07-05 15:10:56 +02:00
parent e573457563
commit 81546b901e
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
3 changed files with 63 additions and 18 deletions

View File

@ -91,8 +91,8 @@ def _MockGetBufferVariable( buffer_number, option ):
return vim_buffer.filetype return vim_buffer.filetype
if option == 'changedtick': if option == 'changedtick':
return vim_buffer.changedtick return vim_buffer.changedtick
if option == '&hid': if option == '&bh':
return vim_buffer.hidden return vim_buffer.bufhidden
return '' return ''
return '' return ''
@ -136,6 +136,9 @@ def _MockVimOptionsEval( value ):
if value == '&showcmd': if value == '&showcmd':
return 1 return 1
if value == '&hidden':
return 0
return None return None
@ -211,21 +214,21 @@ def MockVimCommand( command ):
class VimBuffer( object ): class VimBuffer( object ):
"""An object that looks like a vim.buffer object: """An object that looks like a vim.buffer object:
- |name| : full path of the buffer with symbolic links resolved; - |name| : full path of the buffer with symbolic links resolved;
- |number| : buffer number; - |number| : buffer number;
- |contents|: list of lines representing the buffer contents; - |contents| : list of lines representing the buffer contents;
- |filetype|: buffer filetype. Empty string if no filetype is set; - |filetype| : buffer filetype. Empty string if no filetype is set;
- |modified|: True if the buffer has unsaved changes, False otherwise; - |modified| : True if the buffer has unsaved changes, False otherwise;
- |hidden| : True if the buffer is hidden, False otherwise; - |bufhidden|: value of the 'bufhidden' option (see :h bufhidden);
- |window| : number of the buffer window. None if the buffer is hidden; - |window| : number of the buffer window. None if the buffer is hidden;
- |omnifunc|: omni completion function used by the buffer.""" - |omnifunc| : omni completion function used by the buffer."""
def __init__( self, name, def __init__( self, name,
number = 1, number = 1,
contents = [], contents = [],
filetype = '', filetype = '',
modified = True, modified = False,
hidden = False, bufhidden = '',
window = None, window = None,
omnifunc = '' ): omnifunc = '' ):
self.name = os.path.realpath( name ) if name else '' self.name = os.path.realpath( name ) if name else ''
@ -233,8 +236,8 @@ class VimBuffer( object ):
self.contents = contents self.contents = contents
self.filetype = filetype self.filetype = filetype
self.modified = modified self.modified = modified
self.hidden = hidden self.bufhidden = bufhidden
self.window = window if not hidden else None self.window = window
self.omnifunc = omnifunc self.omnifunc = omnifunc
self.changedtick = 1 self.changedtick = 1

View File

@ -1624,13 +1624,33 @@ def JumpToLocation_SameFile_SameBuffer_NoSwapFile_test( vim_command ):
@patch( 'ycmd.user_options_store._USER_OPTIONS', @patch( 'ycmd.user_options_store._USER_OPTIONS',
{ 'goto_buffer_command': 'same-buffer' } ) { 'goto_buffer_command': 'same-buffer' } )
@patch( 'vim.command', new_callable = ExtendedMock ) @patch( 'vim.command', new_callable = ExtendedMock )
def JumpToLocation_DifferentFile_SameBuffer_NoSwapFile_test( vim_command ): def JumpToLocation_DifferentFile_SameBuffer_Unmodified_test( vim_command ):
current_buffer = VimBuffer( 'uni¢𐍈d€' ) current_buffer = VimBuffer( 'uni¢𐍈d€' )
with MockVimBuffers( [ current_buffer ], current_buffer ) as vim: with MockVimBuffers( [ current_buffer ], current_buffer ) as vim:
target_name = os.path.realpath( u'different_uni¢𐍈d€' ) target_name = os.path.realpath( u'different_uni¢𐍈d€' )
vimsupport.JumpToLocation( target_name, 2, 5 ) vimsupport.JumpToLocation( target_name, 2, 5 )
assert_that( vim.current.window.cursor, equal_to( ( 2, 4 ) ) )
vim_command.assert_has_exact_calls( [
call( 'normal! m\'' ),
call( u'keepjumps edit {0}'.format( target_name ) ),
call( 'normal! zz' )
] )
@patch( 'ycmd.user_options_store._USER_OPTIONS',
{ 'goto_buffer_command': 'same-buffer' } )
@patch( 'vim.command', new_callable = ExtendedMock )
def JumpToLocation_DifferentFile_SameBuffer_Modified_CannotHide_test(
vim_command ):
current_buffer = VimBuffer( 'uni¢𐍈d€', modified = True )
with MockVimBuffers( [ current_buffer ], current_buffer ) as vim:
target_name = os.path.realpath( u'different_uni¢𐍈d€' )
vimsupport.JumpToLocation( target_name, 2, 5 )
assert_that( vim.current.window.cursor, equal_to( ( 2, 4 ) ) ) assert_that( vim.current.window.cursor, equal_to( ( 2, 4 ) ) )
vim_command.assert_has_exact_calls( [ vim_command.assert_has_exact_calls( [
call( 'normal! m\'' ), call( 'normal! m\'' ),
@ -1639,6 +1659,26 @@ def JumpToLocation_DifferentFile_SameBuffer_NoSwapFile_test( vim_command ):
] ) ] )
@patch( 'ycmd.user_options_store._USER_OPTIONS',
{ 'goto_buffer_command': 'same-buffer' } )
@patch( 'vim.command', new_callable = ExtendedMock )
def JumpToLocation_DifferentFile_SameBuffer_Modified_CanHide_test(
vim_command ):
current_buffer = VimBuffer( 'uni¢𐍈d€', modified = True, bufhidden = "hide" )
with MockVimBuffers( [ current_buffer ], current_buffer ) as vim:
target_name = os.path.realpath( u'different_uni¢𐍈d€' )
vimsupport.JumpToLocation( target_name, 2, 5 )
assert_that( vim.current.window.cursor, equal_to( ( 2, 4 ) ) )
vim_command.assert_has_exact_calls( [
call( 'normal! m\'' ),
call( u'keepjumps edit {0}'.format( target_name ) ),
call( 'normal! zz' )
] )
@patch( 'ycmd.user_options_store._USER_OPTIONS', @patch( 'ycmd.user_options_store._USER_OPTIONS',
{ 'goto_buffer_command': 'same-buffer' } ) { 'goto_buffer_command': 'same-buffer' } )
@patch( 'vim.error', VimError ) @patch( 'vim.error', VimError )
@ -1671,7 +1711,7 @@ def JumpToLocation_DifferentFile_SameBuffer_SwapFile_Quit_test( vim_command ):
vim_command.assert_has_exact_calls( [ vim_command.assert_has_exact_calls( [
call( 'normal! m\'' ), call( 'normal! m\'' ),
call( u'keepjumps split {0}'.format( target_name ) ) call( u'keepjumps edit {0}'.format( target_name ) )
] ) ] )
@ -1690,7 +1730,7 @@ def JumpToLocation_DifferentFile_SameBuffer_SwapFile_Abort_test( vim_command ):
vim_command.assert_has_exact_calls( [ vim_command.assert_has_exact_calls( [
call( 'normal! m\'' ), call( 'normal! m\'' ),
call( u'keepjumps split {0}'.format( target_name ) ) call( u'keepjumps edit {0}'.format( target_name ) )
] ) ] )

View File

@ -355,7 +355,9 @@ def VimExpressionToPythonType( vim_expression ):
def HiddenEnabled( buffer_object ): def HiddenEnabled( buffer_object ):
return bool( int( GetBufferOption( buffer_object, 'hid' ) ) ) if GetBufferOption( buffer_object, 'bh' ) == "hide":
return True
return GetBoolValue( '&hidden' )
def BufferIsUsable( buffer_object ): def BufferIsUsable( buffer_object ):