diff --git a/python/ycm/tests/test_utils.py b/python/ycm/tests/test_utils.py index 049874df..72f62962 100644 --- a/python/ycm/tests/test_utils.py +++ b/python/ycm/tests/test_utils.py @@ -91,8 +91,8 @@ def _MockGetBufferVariable( buffer_number, option ): return vim_buffer.filetype if option == 'changedtick': return vim_buffer.changedtick - if option == '&hid': - return vim_buffer.hidden + if option == '&bh': + return vim_buffer.bufhidden return '' return '' @@ -136,6 +136,9 @@ def _MockVimOptionsEval( value ): if value == '&showcmd': return 1 + if value == '&hidden': + return 0 + return None @@ -211,21 +214,21 @@ def MockVimCommand( command ): class VimBuffer( object ): """An object that looks like a vim.buffer object: - - |name| : full path of the buffer with symbolic links resolved; - - |number| : buffer number; - - |contents|: list of lines representing the buffer contents; - - |filetype|: buffer filetype. Empty string if no filetype is set; - - |modified|: True if the buffer has unsaved changes, False otherwise; - - |hidden| : True if the buffer is hidden, False otherwise; - - |window| : number of the buffer window. None if the buffer is hidden; - - |omnifunc|: omni completion function used by the buffer.""" + - |name| : full path of the buffer with symbolic links resolved; + - |number| : buffer number; + - |contents| : list of lines representing the buffer contents; + - |filetype| : buffer filetype. Empty string if no filetype is set; + - |modified| : True if the buffer has unsaved changes, False otherwise; + - |bufhidden|: value of the 'bufhidden' option (see :h bufhidden); + - |window| : number of the buffer window. None if the buffer is hidden; + - |omnifunc| : omni completion function used by the buffer.""" def __init__( self, name, number = 1, contents = [], filetype = '', - modified = True, - hidden = False, + modified = False, + bufhidden = '', window = None, omnifunc = '' ): self.name = os.path.realpath( name ) if name else '' @@ -233,8 +236,8 @@ class VimBuffer( object ): self.contents = contents self.filetype = filetype self.modified = modified - self.hidden = hidden - self.window = window if not hidden else None + self.bufhidden = bufhidden + self.window = window self.omnifunc = omnifunc self.changedtick = 1 diff --git a/python/ycm/tests/vimsupport_test.py b/python/ycm/tests/vimsupport_test.py index 9de6f6ee..6a4c1133 100644 --- a/python/ycm/tests/vimsupport_test.py +++ b/python/ycm/tests/vimsupport_test.py @@ -1624,13 +1624,33 @@ def JumpToLocation_SameFile_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_NoSwapFile_test( vim_command ): +def JumpToLocation_DifferentFile_SameBuffer_Unmodified_test( vim_command ): current_buffer = VimBuffer( 'uni¢𐍈d€' ) 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', + { '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 ) ) ) vim_command.assert_has_exact_calls( [ 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', { 'goto_buffer_command': 'same-buffer' } ) @patch( 'vim.error', VimError ) @@ -1671,7 +1711,7 @@ def JumpToLocation_DifferentFile_SameBuffer_SwapFile_Quit_test( vim_command ): vim_command.assert_has_exact_calls( [ 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( [ call( 'normal! m\'' ), - call( u'keepjumps split {0}'.format( target_name ) ) + call( u'keepjumps edit {0}'.format( target_name ) ) ] ) diff --git a/python/ycm/vimsupport.py b/python/ycm/vimsupport.py index dffaf627..ac67fd1c 100644 --- a/python/ycm/vimsupport.py +++ b/python/ycm/vimsupport.py @@ -355,7 +355,9 @@ def VimExpressionToPythonType( vim_expression ): 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 ):