2016-03-02 21:12:38 -05:00
|
|
|
# coding: utf-8
|
2016-02-28 17:42:18 -05:00
|
|
|
#
|
2016-10-14 05:00:57 -04:00
|
|
|
# Copyright (C) 2015-2016 YouCompleteMe contributors
|
2015-08-05 17:09:07 -04:00
|
|
|
#
|
|
|
|
# This file is part of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
# Intentionally not importing unicode_literals!
|
2016-02-27 19:12:24 -05:00
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from future import standard_library
|
|
|
|
standard_library.install_aliases()
|
|
|
|
from builtins import * # noqa
|
|
|
|
|
2016-10-11 18:05:24 -04:00
|
|
|
from ycm.tests import PathToTestFile
|
|
|
|
from ycm.tests.test_utils import ( CurrentWorkingDirectory, ExtendedMock,
|
2017-02-19 18:52:21 -05:00
|
|
|
MockVimBuffers, MockVimCommand,
|
|
|
|
MockVimModule, VimBuffer )
|
2015-09-06 15:07:42 -04:00
|
|
|
MockVimModule()
|
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
from ycm import vimsupport
|
|
|
|
from nose.tools import eq_
|
2016-05-06 01:52:04 -04:00
|
|
|
from hamcrest import assert_that, calling, equal_to, has_entry, raises
|
2015-09-06 15:07:42 -04:00
|
|
|
from mock import MagicMock, call, patch
|
2016-10-08 04:53:17 -04:00
|
|
|
from ycmd.utils import ToBytes
|
2015-11-07 20:16:13 -05:00
|
|
|
import os
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
import json
|
2015-08-05 17:09:07 -04:00
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2017-02-19 18:52:21 -05:00
|
|
|
@patch( 'vim.eval', new_callable = ExtendedMock )
|
|
|
|
def SetLocationList_test( vim_eval ):
|
|
|
|
diagnostics = [ {
|
|
|
|
'bufnr': 3,
|
|
|
|
'filename': 'some_filename',
|
|
|
|
'lnum': 5,
|
|
|
|
'col': 22,
|
|
|
|
'type': 'E',
|
|
|
|
'valid': 1
|
|
|
|
} ]
|
|
|
|
vimsupport.SetLocationList( diagnostics )
|
|
|
|
vim_eval.assert_called_once_with(
|
|
|
|
'setloclist( 0, {0} )'.format( json.dumps( diagnostics ) ) )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.VariableExists', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.SetFittingHeightForCurrentWindow' )
|
|
|
|
@patch( 'vim.command', new_callable = ExtendedMock )
|
|
|
|
def OpenLocationList_test( vim_command, fitting_height, variable_exists ):
|
|
|
|
vimsupport.OpenLocationList( focus = False, autoclose = True )
|
|
|
|
vim_command.assert_has_exact_calls( [
|
|
|
|
call( 'botright lopen' ),
|
|
|
|
call( 'au WinLeave <buffer> q' ),
|
|
|
|
call( 'doautocmd User YcmLocationOpened' ),
|
|
|
|
call( 'silent! wincmd p' )
|
|
|
|
] )
|
|
|
|
fitting_height.assert_called_once_with()
|
|
|
|
variable_exists.assert_called_once_with( '#User#YcmLocationOpened' )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetIntValue', return_value = 120 )
|
|
|
|
@patch( 'vim.command' )
|
|
|
|
def SetFittingHeightForCurrentWindow_test( vim_command, *args ):
|
|
|
|
# Create a buffer with one line that is longer than the window width.
|
|
|
|
current_buffer = VimBuffer( 'buffer',
|
|
|
|
contents = [ 'a' * 140 ] )
|
|
|
|
with MockVimBuffers( [ current_buffer ], current_buffer ):
|
|
|
|
vimsupport.SetFittingHeightForCurrentWindow()
|
|
|
|
vim_command.assert_called_once_with( '2wincmd _' )
|
|
|
|
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
def AssertBuffersAreEqualAsBytes( result_buffer, expected_buffer ):
|
|
|
|
eq_( len( result_buffer ), len( expected_buffer ) )
|
|
|
|
for result_line, expected_line in zip( result_buffer, expected_buffer ):
|
|
|
|
eq_( ToBytes( result_line ), ToBytes( expected_line ) )
|
|
|
|
|
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Repl_1_test():
|
|
|
|
# Replace with longer range
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This is a string' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 1, 1, 5 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'How long',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'How long is a string' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 4 )
|
|
|
|
|
|
|
|
# and replace again, using delta
|
|
|
|
start, end = _BuildLocations( 1, 10, 1, 11 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
|
2015-08-05 17:09:07 -04:00
|
|
|
start,
|
|
|
|
end,
|
|
|
|
' piece of ',
|
|
|
|
line_offset,
|
|
|
|
char_offset,
|
|
|
|
result_buffer )
|
|
|
|
|
|
|
|
line_offset += new_line_offset
|
|
|
|
char_offset += new_char_offset
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'How long is a piece of string' ],
|
|
|
|
result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( new_line_offset, 0 )
|
|
|
|
eq_( new_char_offset, 9 )
|
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 13 )
|
|
|
|
|
|
|
|
# and once more, for luck
|
|
|
|
start, end = _BuildLocations( 1, 11, 1, 17 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
|
2015-08-05 17:09:07 -04:00
|
|
|
start,
|
|
|
|
end,
|
|
|
|
'pie',
|
|
|
|
line_offset,
|
|
|
|
char_offset,
|
|
|
|
result_buffer )
|
|
|
|
|
|
|
|
line_offset += new_line_offset
|
|
|
|
char_offset += new_char_offset
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'How long is a piece of pie' ],
|
|
|
|
result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( new_line_offset, 0 )
|
|
|
|
eq_( new_char_offset, -3 )
|
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 10 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Repl_2_test():
|
|
|
|
# Replace with shorter range
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This is a string' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 11, 1, 17 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'test',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This is a test' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, -2 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Repl_3_test():
|
|
|
|
# Replace with equal range
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This is a string' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 6, 1, 8 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'be',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This be a string' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 0 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Add_1_test():
|
|
|
|
# Insert at start
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'is a string' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 1, 1, 1 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'This ',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This is a string' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 5 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Add_2_test():
|
|
|
|
# Insert at end
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This is a ' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 11, 1, 11 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'string',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This is a string' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 6 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Add_3_test():
|
|
|
|
# Insert in the middle
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This is a string' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 8, 1, 8 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
' not',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This is not a string' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 4 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Del_1_test():
|
|
|
|
# Delete from start
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This is a string' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 1, 1, 6 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'is a string' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, -5 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Del_2_test():
|
|
|
|
# Delete from end
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This is a string' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 10, 1, 18 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This is a' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, -8 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleLine_Del_3_test():
|
|
|
|
# Delete from middle
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This is not a string' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 9, 1, 13 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This is a string' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, -4 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2016-03-25 23:40:17 -04:00
|
|
|
def ReplaceChunk_SingleLine_Unicode_ReplaceUnicodeChars_test():
|
|
|
|
# Replace Unicode characters.
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This Uniçø∂‰ string is in the middle' ]
|
2016-03-25 23:40:17 -04:00
|
|
|
start, end = _BuildLocations( 1, 6, 1, 20 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'Unicode ',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This Unicode string is in the middle' ],
|
|
|
|
result_buffer )
|
2016-03-25 23:40:17 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, -6 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_SingleLine_Unicode_ReplaceAfterUnicode_test():
|
|
|
|
# Replace ASCII characters after Unicode characters in the line.
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'This Uniçø∂‰ string is in the middle' ]
|
2016-03-25 23:40:17 -04:00
|
|
|
start, end = _BuildLocations( 1, 30, 1, 43 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'fåke',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'This Uniçø∂‰ string is fåke' ],
|
|
|
|
result_buffer )
|
2016-03-25 23:40:17 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, -8 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_SingleLine_Unicode_Grown_test():
|
|
|
|
# Replace ASCII characters after Unicode characters in the line.
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'a' ]
|
2016-03-25 23:40:17 -04:00
|
|
|
start, end = _BuildLocations( 1, 1, 1, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
|
|
|
'å',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
result_buffer )
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'å' ], result_buffer )
|
2016-03-25 23:40:17 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 1 ) # Note: byte difference (a = 1 byte, å = 2 bytes)
|
|
|
|
|
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_RemoveSingleLine_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 1, 3, 1 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, '',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
# First line is not affected.
|
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, -1 )
|
|
|
|
eq_( char_offset, 0 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_SingleToMultipleLines_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 2, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Eb\nbF',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'aEb',
|
|
|
|
'bFBa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 1 )
|
|
|
|
eq_( char_offset, 1 )
|
|
|
|
|
|
|
|
# now make another change to the "2nd" line
|
|
|
|
start, end = _BuildLocations( 2, 3, 2, 4 )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
|
|
|
|
start,
|
|
|
|
end,
|
2015-08-05 17:09:07 -04:00
|
|
|
'cccc',
|
|
|
|
line_offset,
|
|
|
|
char_offset,
|
|
|
|
result_buffer )
|
|
|
|
|
|
|
|
line_offset += new_line_offset
|
|
|
|
char_offset += new_char_offset
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'aAa',
|
|
|
|
'aEb',
|
|
|
|
'bFBcccc',
|
|
|
|
'aCa' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 1 )
|
|
|
|
eq_( char_offset, 4 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_SingleToMultipleLines2_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa', 'aBa', 'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 2, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
2015-09-12 10:34:47 -04:00
|
|
|
end,
|
2015-08-05 17:09:07 -04:00
|
|
|
'Eb\nbFb\nG',
|
2015-09-12 10:34:47 -04:00
|
|
|
0,
|
|
|
|
0,
|
2015-08-05 17:09:07 -04:00
|
|
|
result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'aEb',
|
|
|
|
'bFb',
|
|
|
|
'GBa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 2 )
|
|
|
|
eq_( char_offset, 0 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_SingleToMultipleLines3_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa', 'aBa', 'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 2, 2 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
2015-08-05 17:09:07 -04:00
|
|
|
'Eb\nbFb\nbGb',
|
2015-09-12 10:34:47 -04:00
|
|
|
0,
|
|
|
|
0,
|
2015-08-05 17:09:07 -04:00
|
|
|
result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'aEb',
|
|
|
|
'bFb',
|
|
|
|
'bGbBa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 2 )
|
|
|
|
eq_( char_offset, 2 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleToMultipleLinesReplace_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa', 'aBa', 'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 2, 1, 4 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
2015-08-05 17:09:07 -04:00
|
|
|
'Eb\nbFb\nbGb',
|
2015-09-12 10:34:47 -04:00
|
|
|
0,
|
|
|
|
0,
|
2015-08-05 17:09:07 -04:00
|
|
|
result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aEb',
|
|
|
|
'bFb',
|
|
|
|
'bGb',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 2 )
|
|
|
|
eq_( char_offset, 0 )
|
|
|
|
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2015-08-05 17:09:07 -04:00
|
|
|
def ReplaceChunk_SingleToMultipleLinesReplace_2_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 2, 1, 4 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
2015-08-05 17:09:07 -04:00
|
|
|
'Eb\nbFb\nbGb',
|
2015-09-12 10:34:47 -04:00
|
|
|
0,
|
|
|
|
0,
|
2015-08-05 17:09:07 -04:00
|
|
|
result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aEb',
|
|
|
|
'bFb',
|
|
|
|
'bGb',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 2 )
|
|
|
|
eq_( char_offset, 0 )
|
|
|
|
|
|
|
|
# now do a subsequent change (insert at end of line "1")
|
|
|
|
start, end = _BuildLocations( 1, 4, 1, 4 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
|
2015-08-05 17:09:07 -04:00
|
|
|
start,
|
|
|
|
end,
|
|
|
|
'cccc',
|
|
|
|
line_offset,
|
|
|
|
char_offset,
|
|
|
|
result_buffer )
|
|
|
|
|
|
|
|
line_offset += new_line_offset
|
|
|
|
char_offset += new_char_offset
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'aEb',
|
|
|
|
'bFb',
|
|
|
|
'bGbcccc',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
|
|
|
|
eq_( line_offset, 2 )
|
|
|
|
eq_( char_offset, 4 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_MultipleLinesToSingleLine_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa', 'aBa', 'aCaaaa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 3, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'E',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa', 'aECaaaa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, -1 )
|
|
|
|
eq_( char_offset, 1 )
|
|
|
|
|
|
|
|
# make another modification applying offsets
|
|
|
|
start, end = _BuildLocations( 3, 3, 3, 4 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
|
2015-08-05 17:09:07 -04:00
|
|
|
start,
|
|
|
|
end,
|
|
|
|
'cccc',
|
|
|
|
line_offset,
|
|
|
|
char_offset,
|
|
|
|
result_buffer )
|
|
|
|
|
|
|
|
line_offset += new_line_offset
|
|
|
|
char_offset += new_char_offset
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'aAa',
|
|
|
|
'aECccccaaa' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, -1 )
|
|
|
|
eq_( char_offset, 4 )
|
|
|
|
|
|
|
|
# and another, for luck
|
|
|
|
start, end = _BuildLocations( 3, 4, 3, 5 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( new_line_offset, new_char_offset ) = vimsupport.ReplaceChunk(
|
2015-08-05 17:09:07 -04:00
|
|
|
start,
|
|
|
|
end,
|
|
|
|
'dd\ndd',
|
|
|
|
line_offset,
|
|
|
|
char_offset,
|
|
|
|
result_buffer )
|
|
|
|
|
|
|
|
line_offset += new_line_offset
|
|
|
|
char_offset += new_char_offset
|
2015-09-12 10:34:47 -04:00
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( [ 'aAa',
|
|
|
|
'aECccccdd',
|
|
|
|
'ddaa' ], result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, -2 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_MultipleLinesToSameMultipleLines_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa',
|
|
|
|
'aDe' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 3, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Eb\nbF',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'aEb',
|
|
|
|
'bFCa',
|
|
|
|
'aDe' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 1 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_MultipleLinesToMoreMultipleLines_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa',
|
|
|
|
'aDe' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 3, 2 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
2015-08-05 17:09:07 -04:00
|
|
|
'Eb\nbFb\nbG',
|
2015-09-12 10:34:47 -04:00
|
|
|
0,
|
|
|
|
0,
|
2015-08-05 17:09:07 -04:00
|
|
|
result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'aEb',
|
|
|
|
'bFb',
|
|
|
|
'bGCa',
|
|
|
|
'aDe' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 1 )
|
|
|
|
eq_( char_offset, 1 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_MultipleLinesToLessMultipleLines_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa',
|
|
|
|
'aDe' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 2, 3, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Eb\nbF',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aEb', 'bFCa', 'aDe' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, -1 )
|
|
|
|
eq_( char_offset, 1 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_MultipleLinesToEvenLessMultipleLines_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa',
|
|
|
|
'aDe' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 2, 4, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Eb\nbF',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aEb', 'bFDe' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, -2 )
|
|
|
|
eq_( char_offset, 1 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_SpanBufferEdge_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 1, 1, 3 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'bDba',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 1 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_DeleteTextInLine_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 2, 3 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, '',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'aa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, -1 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_AddTextInLine_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 2, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'abDbBa',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 3 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_ReplaceTextInLine_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 2, 2, 2, 3 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
|
|
|
|
0, 0, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'abDba',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 2 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_SingleLineOffsetWorks_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 1, 1, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
|
|
|
|
1, 1, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'abDba',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 0 )
|
|
|
|
eq_( char_offset, 2 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_SingleLineToMultipleLinesOffsetWorks_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 1, 1, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'Db\nE',
|
|
|
|
1, 1, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'aDb',
|
|
|
|
'Ea',
|
|
|
|
'aCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 1 )
|
|
|
|
eq_( char_offset, -1 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_MultipleLinesToSingleLineOffsetWorks_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 1, 1, 2, 2 )
|
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start, end, 'bDb',
|
|
|
|
1, 1, result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'abDbCa' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, -1 )
|
|
|
|
eq_( char_offset, 3 )
|
|
|
|
|
|
|
|
|
|
|
|
def ReplaceChunk_MultipleLineOffsetWorks_test():
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'aAa',
|
|
|
|
'aBa',
|
|
|
|
'aCa' ]
|
2015-08-05 17:09:07 -04:00
|
|
|
start, end = _BuildLocations( 3, 1, 4, 3 )
|
2015-09-12 10:34:47 -04:00
|
|
|
( line_offset, char_offset ) = vimsupport.ReplaceChunk( start,
|
|
|
|
end,
|
2015-08-05 17:09:07 -04:00
|
|
|
'bDb\nbEb\nbFb',
|
2015-09-12 10:34:47 -04:00
|
|
|
-1,
|
|
|
|
1,
|
2015-08-05 17:09:07 -04:00
|
|
|
result_buffer )
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'aAa',
|
|
|
|
'abDb',
|
|
|
|
'bEb',
|
|
|
|
'bFba' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-08-05 17:09:07 -04:00
|
|
|
eq_( line_offset, 1 )
|
|
|
|
eq_( char_offset, 1 )
|
|
|
|
|
|
|
|
|
|
|
|
def _BuildLocations( start_line, start_column, end_line, end_column ):
|
2015-09-12 10:34:47 -04:00
|
|
|
return {
|
|
|
|
'line_num' : start_line,
|
2015-08-05 17:09:07 -04:00
|
|
|
'column_num': start_column,
|
|
|
|
}, {
|
2015-09-12 10:34:47 -04:00
|
|
|
'line_num' : end_line,
|
2015-08-05 17:09:07 -04:00
|
|
|
'column_num': end_column,
|
|
|
|
}
|
2015-09-12 11:06:17 -04:00
|
|
|
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
def ReplaceChunksInBuffer_SortedChunks_test():
|
2015-09-12 11:06:17 -04:00
|
|
|
chunks = [
|
2016-08-16 10:08:11 -04:00
|
|
|
_BuildChunk( 1, 4, 1, 4, '(' ),
|
2015-09-12 11:06:17 -04:00
|
|
|
_BuildChunk( 1, 11, 1, 11, ')' )
|
|
|
|
]
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'CT<10 >> 2> ct' ]
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vimsupport.ReplaceChunksInBuffer( chunks, result_buffer, None )
|
2015-09-12 11:06:17 -04:00
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'CT<(10 >> 2)> ct' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-09-12 11:06:17 -04:00
|
|
|
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
def ReplaceChunksInBuffer_UnsortedChunks_test():
|
2015-09-12 11:06:17 -04:00
|
|
|
chunks = [
|
2016-08-16 10:08:11 -04:00
|
|
|
_BuildChunk( 1, 11, 1, 11, ')' ),
|
2015-09-12 11:06:17 -04:00
|
|
|
_BuildChunk( 1, 4, 1, 4, '(' )
|
|
|
|
]
|
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
result_buffer = [ 'CT<10 >> 2> ct' ]
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vimsupport.ReplaceChunksInBuffer( chunks, result_buffer, None )
|
2015-09-12 11:06:17 -04:00
|
|
|
|
2016-07-13 17:19:41 -04:00
|
|
|
expected_buffer = [ 'CT<(10 >> 2)> ct' ]
|
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, result_buffer )
|
2015-09-12 11:06:17 -04:00
|
|
|
|
|
|
|
|
2016-05-31 04:40:25 -04:00
|
|
|
@patch( 'ycm.vimsupport.VariableExists', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.SetFittingHeightForCurrentWindow' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.GetBufferNumberForFilename',
|
2016-08-28 02:34:09 -04:00
|
|
|
return_value = 1,
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.BufferIsVisible',
|
2016-08-28 02:34:09 -04:00
|
|
|
return_value = True,
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.OpenFilename' )
|
2016-08-28 02:34:09 -04:00
|
|
|
@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
|
|
|
|
@patch( 'vim.eval', new_callable = ExtendedMock )
|
|
|
|
@patch( 'vim.command', new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
def ReplaceChunks_SingleFile_Open_test( vim_command,
|
|
|
|
vim_eval,
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message,
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
open_filename,
|
|
|
|
buffer_is_visible,
|
2016-05-31 04:40:25 -04:00
|
|
|
get_buffer_number_for_filename,
|
|
|
|
set_fitting_height,
|
|
|
|
variable_exists ):
|
2016-05-06 01:52:04 -04:00
|
|
|
single_buffer_name = os.path.realpath( 'single_file' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
chunks = [
|
2016-05-06 01:52:04 -04:00
|
|
|
_BuildChunk( 1, 1, 2, 1, 'replacement', single_buffer_name )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
]
|
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
result_buffer = VimBuffer(
|
2016-05-06 01:52:04 -04:00
|
|
|
single_buffer_name,
|
2016-10-08 04:53:17 -04:00
|
|
|
contents = [
|
|
|
|
'line1',
|
|
|
|
'line2',
|
|
|
|
'line3'
|
|
|
|
]
|
|
|
|
)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
with patch( 'vim.buffers', [ None, result_buffer, None ] ):
|
|
|
|
vimsupport.ReplaceChunks( chunks )
|
|
|
|
|
|
|
|
# Ensure that we applied the replacement correctly
|
2016-03-25 23:40:17 -04:00
|
|
|
eq_( result_buffer.GetLines(), [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'replacementline2',
|
|
|
|
'line3',
|
|
|
|
] )
|
|
|
|
|
|
|
|
# GetBufferNumberForFilename is called twice:
|
|
|
|
# - once to the check if we would require opening the file (so that we can
|
|
|
|
# raise a warning)
|
|
|
|
# - once whilst applying the changes
|
|
|
|
get_buffer_number_for_filename.assert_has_exact_calls( [
|
2016-05-06 01:52:04 -04:00
|
|
|
call( single_buffer_name, False ),
|
|
|
|
call( single_buffer_name, False ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
|
|
|
|
|
|
|
# BufferIsVisible is called twice for the same reasons as above
|
|
|
|
buffer_is_visible.assert_has_exact_calls( [
|
2016-05-06 01:52:04 -04:00
|
|
|
call( 1 ),
|
|
|
|
call( 1 ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
|
|
|
|
|
|
|
# we don't attempt to open any files
|
|
|
|
open_filename.assert_not_called()
|
|
|
|
|
|
|
|
# But we do set the quickfix list
|
|
|
|
vim_eval.assert_has_exact_calls( [
|
2016-05-06 01:52:04 -04:00
|
|
|
call( 'setqflist( {0} )'.format( json.dumps( [ {
|
|
|
|
'bufnr': 1,
|
|
|
|
'filename': single_buffer_name,
|
|
|
|
'lnum': 1,
|
|
|
|
'col': 1,
|
|
|
|
'text': 'replacement',
|
|
|
|
'type': 'F'
|
|
|
|
} ] ) ) ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
2016-05-31 04:40:25 -04:00
|
|
|
vim_command.assert_has_exact_calls( [
|
2016-05-06 01:52:04 -04:00
|
|
|
call( 'botright copen' ),
|
|
|
|
call( 'silent! wincmd p' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
2016-05-31 04:40:25 -04:00
|
|
|
set_fitting_height.assert_called_once_with()
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
# And it is ReplaceChunks that prints the message showing the number of
|
|
|
|
# changes
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message.assert_has_exact_calls( [
|
2016-05-06 01:52:04 -04:00
|
|
|
call( 'Applied 1 changes', warning = False ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
|
|
|
|
|
|
|
|
2016-05-31 04:40:25 -04:00
|
|
|
@patch( 'ycm.vimsupport.VariableExists', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.SetFittingHeightForCurrentWindow' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.GetBufferNumberForFilename',
|
2016-08-28 02:34:09 -04:00
|
|
|
side_effect = [ -1, -1, 1 ],
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.BufferIsVisible',
|
2016-08-28 02:34:09 -04:00
|
|
|
side_effect = [ False, False, True ],
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.OpenFilename',
|
2016-08-28 02:34:09 -04:00
|
|
|
new_callable = ExtendedMock )
|
|
|
|
@patch( 'ycm.vimsupport.PostVimMessage', new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.Confirm',
|
2016-08-28 02:34:09 -04:00
|
|
|
return_value = True,
|
|
|
|
new_callable = ExtendedMock )
|
|
|
|
@patch( 'vim.eval', return_value = 10, new_callable = ExtendedMock )
|
|
|
|
@patch( 'vim.command', new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
def ReplaceChunks_SingleFile_NotOpen_test( vim_command,
|
|
|
|
vim_eval,
|
|
|
|
confirm,
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message,
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
open_filename,
|
|
|
|
buffer_is_visible,
|
2016-05-31 04:40:25 -04:00
|
|
|
get_buffer_number_for_filename,
|
|
|
|
set_fitting_height,
|
|
|
|
variable_exists ):
|
2016-05-06 01:52:04 -04:00
|
|
|
single_buffer_name = os.path.realpath( 'single_file' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
chunks = [
|
2016-05-06 01:52:04 -04:00
|
|
|
_BuildChunk( 1, 1, 2, 1, 'replacement', single_buffer_name )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
]
|
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
result_buffer = VimBuffer(
|
2016-05-06 01:52:04 -04:00
|
|
|
single_buffer_name,
|
2016-10-08 04:53:17 -04:00
|
|
|
contents = [
|
|
|
|
'line1',
|
|
|
|
'line2',
|
|
|
|
'line3'
|
|
|
|
]
|
|
|
|
)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
with patch( 'vim.buffers', [ None, result_buffer, None ] ):
|
|
|
|
vimsupport.ReplaceChunks( chunks )
|
|
|
|
|
|
|
|
# We checked if it was OK to open the file
|
|
|
|
confirm.assert_has_exact_calls( [
|
|
|
|
call( vimsupport.FIXIT_OPENING_BUFFERS_MESSAGE_FORMAT.format( 1 ) )
|
|
|
|
] )
|
|
|
|
|
|
|
|
# Ensure that we applied the replacement correctly
|
2016-03-25 23:40:17 -04:00
|
|
|
eq_( result_buffer.GetLines(), [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'replacementline2',
|
|
|
|
'line3',
|
|
|
|
] )
|
|
|
|
|
|
|
|
# GetBufferNumberForFilename is called 3 times. The return values are set in
|
|
|
|
# the @patch call above:
|
|
|
|
# - once to the check if we would require opening the file (so that we can
|
|
|
|
# raise a warning) (-1 return)
|
|
|
|
# - once whilst applying the changes (-1 return)
|
|
|
|
# - finally after calling OpenFilename (1 return)
|
|
|
|
get_buffer_number_for_filename.assert_has_exact_calls( [
|
2016-05-06 01:52:04 -04:00
|
|
|
call( single_buffer_name, False ),
|
|
|
|
call( single_buffer_name, False ),
|
|
|
|
call( single_buffer_name, False ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
|
|
|
|
|
|
|
# BufferIsVisible is called 3 times for the same reasons as above, with the
|
|
|
|
# return of each one
|
|
|
|
buffer_is_visible.assert_has_exact_calls( [
|
|
|
|
call( -1 ),
|
|
|
|
call( -1 ),
|
|
|
|
call( 1 ),
|
|
|
|
] )
|
|
|
|
|
|
|
|
# We open 'single_file' as expected.
|
2016-05-06 01:52:04 -04:00
|
|
|
open_filename.assert_called_with( single_buffer_name, {
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'focus': True,
|
|
|
|
'fix': True,
|
|
|
|
'size': 10
|
|
|
|
} )
|
|
|
|
|
2016-05-31 04:40:25 -04:00
|
|
|
# And close it again, then show the quickfix window.
|
|
|
|
vim_command.assert_has_exact_calls( [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
call( 'lclose' ),
|
|
|
|
call( 'hide' ),
|
2016-05-31 04:40:25 -04:00
|
|
|
call( 'botright copen' ),
|
|
|
|
call( 'silent! wincmd p' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
2016-05-31 04:40:25 -04:00
|
|
|
set_fitting_height.assert_called_once_with()
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
# And update the quickfix list
|
|
|
|
vim_eval.assert_has_exact_calls( [
|
|
|
|
call( '&previewheight' ),
|
|
|
|
call( 'setqflist( {0} )'.format( json.dumps( [ {
|
|
|
|
'bufnr': 1,
|
2016-05-06 01:52:04 -04:00
|
|
|
'filename': single_buffer_name,
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'lnum': 1,
|
|
|
|
'col': 1,
|
|
|
|
'text': 'replacement',
|
|
|
|
'type': 'F'
|
|
|
|
} ] ) ) ),
|
|
|
|
] )
|
|
|
|
|
|
|
|
# And it is ReplaceChunks that prints the message showing the number of
|
|
|
|
# changes
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message.assert_has_exact_calls( [
|
|
|
|
call( 'Applied 1 changes', warning = False ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetBufferNumberForFilename',
|
2016-08-28 02:34:09 -04:00
|
|
|
side_effect = [ -1, -1, 1 ],
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.BufferIsVisible',
|
2016-08-28 02:34:09 -04:00
|
|
|
side_effect = [ False, False, True ],
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.OpenFilename',
|
2016-08-28 02:34:09 -04:00
|
|
|
new_callable = ExtendedMock )
|
|
|
|
@patch( 'ycm.vimsupport.PostVimMessage',
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.Confirm',
|
2016-08-28 02:34:09 -04:00
|
|
|
return_value = False,
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'vim.eval',
|
2016-08-28 02:34:09 -04:00
|
|
|
return_value = 10,
|
|
|
|
new_callable = ExtendedMock )
|
|
|
|
@patch( 'vim.command', new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
def ReplaceChunks_User_Declines_To_Open_File_test(
|
|
|
|
vim_command,
|
|
|
|
vim_eval,
|
|
|
|
confirm,
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message,
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
open_filename,
|
|
|
|
buffer_is_visible,
|
|
|
|
get_buffer_number_for_filename ):
|
|
|
|
|
|
|
|
# Same as above, except the user selects Cancel when asked if they should
|
|
|
|
# allow us to open lots of (ahem, 1) file.
|
2016-05-06 01:52:04 -04:00
|
|
|
single_buffer_name = os.path.realpath( 'single_file' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
chunks = [
|
2016-05-06 01:52:04 -04:00
|
|
|
_BuildChunk( 1, 1, 2, 1, 'replacement', single_buffer_name )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
]
|
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
result_buffer = VimBuffer(
|
2016-05-06 01:52:04 -04:00
|
|
|
single_buffer_name,
|
2016-10-08 04:53:17 -04:00
|
|
|
contents = [
|
|
|
|
'line1',
|
|
|
|
'line2',
|
|
|
|
'line3'
|
|
|
|
]
|
|
|
|
)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
with patch( 'vim.buffers', [ None, result_buffer, None ] ):
|
|
|
|
vimsupport.ReplaceChunks( chunks )
|
|
|
|
|
|
|
|
# We checked if it was OK to open the file
|
|
|
|
confirm.assert_has_exact_calls( [
|
|
|
|
call( vimsupport.FIXIT_OPENING_BUFFERS_MESSAGE_FORMAT.format( 1 ) )
|
|
|
|
] )
|
|
|
|
|
|
|
|
# Ensure that buffer is not changed
|
2016-03-25 23:40:17 -04:00
|
|
|
eq_( result_buffer.GetLines(), [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'line1',
|
|
|
|
'line2',
|
|
|
|
'line3',
|
|
|
|
] )
|
|
|
|
|
|
|
|
# GetBufferNumberForFilename is called once. The return values are set in
|
|
|
|
# the @patch call above:
|
|
|
|
# - once to the check if we would require opening the file (so that we can
|
|
|
|
# raise a warning) (-1 return)
|
|
|
|
get_buffer_number_for_filename.assert_has_exact_calls( [
|
2016-05-06 01:52:04 -04:00
|
|
|
call( single_buffer_name, False ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
|
|
|
|
|
|
|
# BufferIsVisible is called once for the above file, which wasn't visible.
|
|
|
|
buffer_is_visible.assert_has_exact_calls( [
|
|
|
|
call( -1 ),
|
|
|
|
] )
|
|
|
|
|
|
|
|
# We don't attempt to open any files or update any quickfix list or anything
|
|
|
|
# like that
|
|
|
|
open_filename.assert_not_called()
|
|
|
|
vim_eval.assert_not_called()
|
|
|
|
vim_command.assert_not_called()
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message.assert_not_called()
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.GetBufferNumberForFilename',
|
2016-08-28 02:34:09 -04:00
|
|
|
side_effect = [ -1, -1, 1 ],
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
# Key difference is here: In the final check, BufferIsVisible returns False
|
|
|
|
@patch( 'ycm.vimsupport.BufferIsVisible',
|
2016-08-28 02:34:09 -04:00
|
|
|
side_effect = [ False, False, False ],
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.OpenFilename',
|
2016-08-28 02:34:09 -04:00
|
|
|
new_callable = ExtendedMock )
|
|
|
|
@patch( 'ycm.vimsupport.PostVimMessage',
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.Confirm',
|
2016-08-28 02:34:09 -04:00
|
|
|
return_value = True,
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'vim.eval',
|
2016-08-28 02:34:09 -04:00
|
|
|
return_value = 10,
|
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'vim.command',
|
2016-08-28 02:34:09 -04:00
|
|
|
new_callable = ExtendedMock )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
def ReplaceChunks_User_Aborts_Opening_File_test(
|
|
|
|
vim_command,
|
|
|
|
vim_eval,
|
|
|
|
confirm,
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message,
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
open_filename,
|
|
|
|
buffer_is_visible,
|
|
|
|
get_buffer_number_for_filename ):
|
|
|
|
|
|
|
|
# Same as above, except the user selects Abort or Quick during the
|
|
|
|
# "swap-file-found" dialog
|
2016-05-06 01:52:04 -04:00
|
|
|
single_buffer_name = os.path.realpath( 'single_file' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
chunks = [
|
2016-05-06 01:52:04 -04:00
|
|
|
_BuildChunk( 1, 1, 2, 1, 'replacement', single_buffer_name )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
]
|
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
result_buffer = VimBuffer(
|
2016-05-06 01:52:04 -04:00
|
|
|
single_buffer_name,
|
2016-10-08 04:53:17 -04:00
|
|
|
contents = [
|
|
|
|
'line1',
|
|
|
|
'line2',
|
|
|
|
'line3'
|
|
|
|
]
|
|
|
|
)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
with patch( 'vim.buffers', [ None, result_buffer, None ] ):
|
|
|
|
assert_that( calling( vimsupport.ReplaceChunks ).with_args( chunks ),
|
|
|
|
raises( RuntimeError,
|
2016-05-06 01:52:04 -04:00
|
|
|
'Unable to open file: .+single_file\n'
|
|
|
|
'FixIt/Refactor operation aborted prior to completion. '
|
|
|
|
'Your files have not been fully updated. '
|
|
|
|
'Please use undo commands to revert the applied changes.' ) )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
# We checked if it was OK to open the file
|
|
|
|
confirm.assert_has_exact_calls( [
|
|
|
|
call( vimsupport.FIXIT_OPENING_BUFFERS_MESSAGE_FORMAT.format( 1 ) )
|
|
|
|
] )
|
|
|
|
|
|
|
|
# Ensure that buffer is not changed
|
2016-03-25 23:40:17 -04:00
|
|
|
eq_( result_buffer.GetLines(), [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'line1',
|
|
|
|
'line2',
|
|
|
|
'line3',
|
|
|
|
] )
|
|
|
|
|
|
|
|
# We tried to open this file
|
2016-05-06 01:52:04 -04:00
|
|
|
open_filename.assert_called_with( single_buffer_name, {
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'focus': True,
|
|
|
|
'fix': True,
|
|
|
|
'size': 10
|
|
|
|
} )
|
|
|
|
vim_eval.assert_called_with( "&previewheight" )
|
|
|
|
|
|
|
|
# But raised an exception before issuing the message at the end
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message.assert_not_called()
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
|
2016-05-31 04:40:25 -04:00
|
|
|
@patch( 'ycm.vimsupport.VariableExists', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.SetFittingHeightForCurrentWindow' )
|
2016-08-28 02:34:09 -04:00
|
|
|
@patch( 'ycm.vimsupport.GetBufferNumberForFilename', side_effect = [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
22, # first_file (check)
|
2016-05-06 01:52:04 -04:00
|
|
|
-1, # second_file (check)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
22, # first_file (apply)
|
2016-05-06 01:52:04 -04:00
|
|
|
-1, # second_file (apply)
|
|
|
|
19, # second_file (check after open)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
],
|
2016-08-28 02:34:09 -04:00
|
|
|
new_callable = ExtendedMock )
|
|
|
|
@patch( 'ycm.vimsupport.BufferIsVisible', side_effect = [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
True, # first_file (check)
|
|
|
|
False, # second_file (check)
|
|
|
|
True, # first_file (apply)
|
|
|
|
False, # second_file (apply)
|
|
|
|
True, # side_effect (check after open)
|
|
|
|
],
|
2016-08-28 02:34:09 -04:00
|
|
|
new_callable = ExtendedMock)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'ycm.vimsupport.OpenFilename',
|
2016-08-28 02:34:09 -04:00
|
|
|
new_callable = ExtendedMock)
|
|
|
|
@patch( 'ycm.vimsupport.PostVimMessage',
|
|
|
|
new_callable = ExtendedMock)
|
|
|
|
@patch( 'ycm.vimsupport.Confirm', return_value = True,
|
|
|
|
new_callable = ExtendedMock)
|
|
|
|
@patch( 'vim.eval', return_value = 10,
|
|
|
|
new_callable = ExtendedMock)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'vim.command',
|
2016-08-28 02:34:09 -04:00
|
|
|
new_callable = ExtendedMock)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
def ReplaceChunks_MultiFile_Open_test( vim_command,
|
|
|
|
vim_eval,
|
|
|
|
confirm,
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message,
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
open_filename,
|
|
|
|
buffer_is_visible,
|
2016-05-31 04:40:25 -04:00
|
|
|
get_buffer_number_for_filename,
|
|
|
|
set_fitting_height,
|
|
|
|
variable_exists ):
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
# Chunks are split across 2 files, one is already open, one isn't
|
2016-05-06 01:52:04 -04:00
|
|
|
first_buffer_name = os.path.realpath( '1_first_file' )
|
|
|
|
second_buffer_name = os.path.realpath( '2_second_file' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
chunks = [
|
2016-05-06 01:52:04 -04:00
|
|
|
_BuildChunk( 1, 1, 2, 1, 'first_file_replacement ', first_buffer_name ),
|
|
|
|
_BuildChunk( 2, 1, 2, 1, 'second_file_replacement ', second_buffer_name ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
]
|
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
first_file = VimBuffer(
|
2016-05-06 01:52:04 -04:00
|
|
|
first_buffer_name,
|
2016-10-08 04:53:17 -04:00
|
|
|
number = 22,
|
|
|
|
contents = [
|
|
|
|
'line1',
|
|
|
|
'line2',
|
|
|
|
'line3',
|
|
|
|
]
|
|
|
|
)
|
2016-05-06 01:52:04 -04:00
|
|
|
second_file = VimBuffer(
|
|
|
|
second_buffer_name,
|
2016-10-08 04:53:17 -04:00
|
|
|
number = 19,
|
|
|
|
contents = [
|
|
|
|
'another line1',
|
|
|
|
'ACME line2',
|
|
|
|
]
|
|
|
|
)
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
vim_buffers = [ None ] * 23
|
|
|
|
vim_buffers[ 22 ] = first_file
|
2016-05-06 01:52:04 -04:00
|
|
|
vim_buffers[ 19 ] = second_file
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
with patch( 'vim.buffers', vim_buffers ):
|
|
|
|
vimsupport.ReplaceChunks( chunks )
|
|
|
|
|
|
|
|
# We checked for the right file names
|
|
|
|
get_buffer_number_for_filename.assert_has_exact_calls( [
|
2016-05-06 01:52:04 -04:00
|
|
|
call( first_buffer_name, False ),
|
|
|
|
call( second_buffer_name, False ),
|
|
|
|
call( first_buffer_name, False ),
|
|
|
|
call( second_buffer_name, False ),
|
|
|
|
call( second_buffer_name, False ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
|
|
|
|
|
|
|
# We checked if it was OK to open the file
|
|
|
|
confirm.assert_has_exact_calls( [
|
|
|
|
call( vimsupport.FIXIT_OPENING_BUFFERS_MESSAGE_FORMAT.format( 1 ) )
|
|
|
|
] )
|
|
|
|
|
|
|
|
# Ensure that buffers are updated
|
2016-05-06 01:52:04 -04:00
|
|
|
eq_( second_file.GetLines(), [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'another line1',
|
|
|
|
'second_file_replacement ACME line2',
|
|
|
|
] )
|
2016-03-25 23:40:17 -04:00
|
|
|
eq_( first_file.GetLines(), [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'first_file_replacement line2',
|
|
|
|
'line3',
|
|
|
|
] )
|
|
|
|
|
2016-05-06 01:52:04 -04:00
|
|
|
# We open '2_second_file' as expected.
|
|
|
|
open_filename.assert_called_with( second_buffer_name, {
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'focus': True,
|
|
|
|
'fix': True,
|
|
|
|
'size': 10
|
|
|
|
} )
|
|
|
|
|
2016-05-31 04:40:25 -04:00
|
|
|
# And close it again, then show the quickfix window.
|
|
|
|
vim_command.assert_has_exact_calls( [
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
call( 'lclose' ),
|
|
|
|
call( 'hide' ),
|
2016-05-31 04:40:25 -04:00
|
|
|
call( 'botright copen' ),
|
|
|
|
call( 'silent! wincmd p' )
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
2016-05-31 04:40:25 -04:00
|
|
|
set_fitting_height.assert_called_once_with()
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
|
|
|
|
# And update the quickfix list with each entry
|
|
|
|
vim_eval.assert_has_exact_calls( [
|
|
|
|
call( '&previewheight' ),
|
|
|
|
call( 'setqflist( {0} )'.format( json.dumps( [ {
|
|
|
|
'bufnr': 22,
|
2016-05-06 01:52:04 -04:00
|
|
|
'filename': first_buffer_name,
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'lnum': 1,
|
|
|
|
'col': 1,
|
|
|
|
'text': 'first_file_replacement ',
|
|
|
|
'type': 'F'
|
|
|
|
}, {
|
|
|
|
'bufnr': 19,
|
2016-05-06 01:52:04 -04:00
|
|
|
'filename': second_buffer_name,
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'lnum': 2,
|
|
|
|
'col': 1,
|
|
|
|
'text': 'second_file_replacement ',
|
|
|
|
'type': 'F'
|
|
|
|
} ] ) ) ),
|
|
|
|
] )
|
|
|
|
|
|
|
|
# And it is ReplaceChunks that prints the message showing the number of
|
|
|
|
# changes
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message.assert_has_exact_calls( [
|
|
|
|
call( 'Applied 2 changes', warning = False ),
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
] )
|
|
|
|
|
|
|
|
|
|
|
|
def _BuildChunk( start_line,
|
|
|
|
start_column,
|
|
|
|
end_line,
|
|
|
|
end_column,
|
|
|
|
replacement_text, filepath='test_file_name' ):
|
2015-09-12 11:06:17 -04:00
|
|
|
return {
|
|
|
|
'range': {
|
|
|
|
'start': {
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'filepath': filepath,
|
2015-09-12 11:06:17 -04:00
|
|
|
'line_num': start_line,
|
|
|
|
'column_num': start_column,
|
|
|
|
},
|
|
|
|
'end': {
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
'filepath': filepath,
|
2015-09-12 11:06:17 -04:00
|
|
|
'line_num': end_line,
|
|
|
|
'column_num': end_column,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'replacement_text': replacement_text
|
|
|
|
}
|
2015-09-06 15:07:42 -04:00
|
|
|
|
|
|
|
|
2016-08-16 10:08:11 -04:00
|
|
|
@patch( 'vim.eval', new_callable = ExtendedMock )
|
|
|
|
def AddDiagnosticSyntaxMatch_ErrorInMiddleOfLine_test( vim_eval ):
|
2016-10-08 04:53:17 -04:00
|
|
|
current_buffer = VimBuffer(
|
|
|
|
'some_file',
|
|
|
|
contents = [ 'Highlight this error please' ]
|
|
|
|
)
|
2016-08-16 10:08:11 -04:00
|
|
|
|
|
|
|
with patch( 'vim.current.buffer', current_buffer ):
|
|
|
|
vimsupport.AddDiagnosticSyntaxMatch( 1, 16, 1, 21 )
|
|
|
|
|
|
|
|
vim_eval.assert_called_once_with(
|
|
|
|
r"matchadd('YcmErrorSection', '\%1l\%16c\_.\{-}\%1l\%21c')" )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', new_callable = ExtendedMock )
|
|
|
|
def AddDiagnosticSyntaxMatch_WarningAtEndOfLine_test( vim_eval ):
|
2016-10-08 04:53:17 -04:00
|
|
|
current_buffer = VimBuffer(
|
|
|
|
'some_file',
|
|
|
|
contents = [ 'Highlight this warning' ]
|
|
|
|
)
|
2016-08-16 10:08:11 -04:00
|
|
|
|
|
|
|
with patch( 'vim.current.buffer', current_buffer ):
|
|
|
|
vimsupport.AddDiagnosticSyntaxMatch( 1, 16, 1, 23, is_error = False )
|
|
|
|
|
|
|
|
vim_eval.assert_called_once_with(
|
|
|
|
r"matchadd('YcmWarningSection', '\%1l\%16c\_.\{-}\%1l\%23c')" )
|
|
|
|
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'vim.command', new_callable=ExtendedMock )
|
|
|
|
@patch( 'vim.current', new_callable=ExtendedMock)
|
2015-11-07 20:16:13 -05:00
|
|
|
def WriteToPreviewWindow_test( vim_current, vim_command ):
|
2015-09-06 15:07:42 -04:00
|
|
|
vim_current.window.options.__getitem__ = MagicMock( return_value = True )
|
|
|
|
|
|
|
|
vimsupport.WriteToPreviewWindow( "test" )
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vim_command.assert_has_exact_calls( [
|
2015-09-06 15:07:42 -04:00
|
|
|
call( 'silent! pclose!' ),
|
|
|
|
call( 'silent! pedit! _TEMP_FILE_' ),
|
|
|
|
call( 'silent! wincmd P' ),
|
|
|
|
call( 'silent! wincmd p' ) ] )
|
|
|
|
|
|
|
|
vim_current.buffer.__setitem__.assert_called_with(
|
|
|
|
slice( None, None, None ), [ 'test' ] )
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vim_current.buffer.options.__setitem__.assert_has_exact_calls( [
|
|
|
|
call( 'modifiable', True ),
|
|
|
|
call( 'readonly', False ),
|
2015-09-06 15:07:42 -04:00
|
|
|
call( 'buftype', 'nofile' ),
|
2016-11-11 13:15:22 -05:00
|
|
|
call( 'bufhidden', 'wipe' ),
|
|
|
|
call( 'buflisted', False ),
|
2015-09-06 15:07:42 -04:00
|
|
|
call( 'swapfile', False ),
|
|
|
|
call( 'modifiable', False ),
|
|
|
|
call( 'modified', False ),
|
|
|
|
call( 'readonly', True ),
|
|
|
|
], any_order = True )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.current' )
|
2015-11-07 20:16:13 -05:00
|
|
|
def WriteToPreviewWindow_MultiLine_test( vim_current ):
|
2015-09-06 15:07:42 -04:00
|
|
|
vim_current.window.options.__getitem__ = MagicMock( return_value = True )
|
|
|
|
vimsupport.WriteToPreviewWindow( "test\ntest2" )
|
|
|
|
|
|
|
|
vim_current.buffer.__setitem__.assert_called_with(
|
|
|
|
slice( None, None, None ), [ 'test', 'test2' ] )
|
|
|
|
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'vim.command', new_callable=ExtendedMock )
|
|
|
|
@patch( 'vim.current', new_callable=ExtendedMock )
|
2015-11-07 20:16:13 -05:00
|
|
|
def WriteToPreviewWindow_JumpFail_test( vim_current, vim_command ):
|
2015-09-06 15:07:42 -04:00
|
|
|
vim_current.window.options.__getitem__ = MagicMock( return_value = False )
|
|
|
|
|
|
|
|
vimsupport.WriteToPreviewWindow( "test" )
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vim_command.assert_has_exact_calls( [
|
2015-09-06 15:07:42 -04:00
|
|
|
call( 'silent! pclose!' ),
|
|
|
|
call( 'silent! pedit! _TEMP_FILE_' ),
|
|
|
|
call( 'silent! wincmd P' ),
|
2016-08-28 02:34:09 -04:00
|
|
|
call( 'redraw' ),
|
|
|
|
call( "echo 'test'" ),
|
2015-09-06 15:07:42 -04:00
|
|
|
] )
|
|
|
|
|
|
|
|
vim_current.buffer.__setitem__.assert_not_called()
|
|
|
|
vim_current.buffer.options.__setitem__.assert_not_called()
|
|
|
|
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'vim.command', new_callable=ExtendedMock )
|
|
|
|
@patch( 'vim.current', new_callable=ExtendedMock )
|
2015-11-07 20:16:13 -05:00
|
|
|
def WriteToPreviewWindow_JumpFail_MultiLine_test( vim_current, vim_command ):
|
2015-09-06 15:07:42 -04:00
|
|
|
|
|
|
|
vim_current.window.options.__getitem__ = MagicMock( return_value = False )
|
|
|
|
|
|
|
|
vimsupport.WriteToPreviewWindow( "test\ntest2" )
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vim_command.assert_has_exact_calls( [
|
2015-09-06 15:07:42 -04:00
|
|
|
call( 'silent! pclose!' ),
|
|
|
|
call( 'silent! pedit! _TEMP_FILE_' ),
|
|
|
|
call( 'silent! wincmd P' ),
|
2016-08-28 02:34:09 -04:00
|
|
|
call( 'redraw' ),
|
|
|
|
call( "echo 'test'" ),
|
|
|
|
call( "echo 'test2'" ),
|
2015-09-06 15:07:42 -04:00
|
|
|
] )
|
|
|
|
|
|
|
|
vim_current.buffer.__setitem__.assert_not_called()
|
|
|
|
vim_current.buffer.options.__setitem__.assert_not_called()
|
2015-11-07 20:16:13 -05:00
|
|
|
|
|
|
|
|
2015-11-11 08:18:26 -05:00
|
|
|
def BufferIsVisibleForFilename_test():
|
2016-10-08 04:53:17 -04:00
|
|
|
vim_buffers = [
|
2016-05-06 01:52:04 -04:00
|
|
|
VimBuffer( 'visible_filename', number = 1, window = 1 ),
|
|
|
|
VimBuffer( 'hidden_filename', number = 2, window = None )
|
2015-11-11 08:18:26 -05:00
|
|
|
]
|
2015-11-07 20:16:13 -05:00
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
with patch( 'vim.buffers', vim_buffers ):
|
2015-11-11 08:18:26 -05:00
|
|
|
eq_( vimsupport.BufferIsVisibleForFilename( 'visible_filename' ), True )
|
|
|
|
eq_( vimsupport.BufferIsVisibleForFilename( 'hidden_filename' ), False )
|
|
|
|
eq_( vimsupport.BufferIsVisibleForFilename( 'another_filename' ), False )
|
2015-11-07 20:16:13 -05:00
|
|
|
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
@patch( 'vim.command',
|
|
|
|
side_effect = MockVimCommand,
|
2016-02-27 19:12:24 -05:00
|
|
|
new_callable = ExtendedMock )
|
|
|
|
def CloseBuffersForFilename_test( vim_command, *args ):
|
2016-10-08 04:53:17 -04:00
|
|
|
vim_buffers = [
|
2016-05-06 01:52:04 -04:00
|
|
|
VimBuffer( 'some_filename', number = 2 ),
|
|
|
|
VimBuffer( 'some_filename', number = 5 )
|
2016-10-08 04:53:17 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
with patch( 'vim.buffers', vim_buffers ):
|
|
|
|
vimsupport.CloseBuffersForFilename( 'some_filename' )
|
2015-11-07 20:16:13 -05:00
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vim_command.assert_has_exact_calls( [
|
2015-11-07 20:16:13 -05:00
|
|
|
call( 'silent! bwipeout! 2' ),
|
|
|
|
call( 'silent! bwipeout! 5' )
|
|
|
|
], any_order = True )
|
|
|
|
|
|
|
|
|
2016-02-27 19:12:24 -05:00
|
|
|
@patch( 'vim.command', new_callable = ExtendedMock )
|
|
|
|
@patch( 'vim.current', new_callable = ExtendedMock )
|
2015-11-07 20:16:13 -05:00
|
|
|
def OpenFilename_test( vim_current, vim_command ):
|
2016-05-06 01:52:04 -04:00
|
|
|
# Options used to open a logfile.
|
2015-11-07 20:16:13 -05:00
|
|
|
options = {
|
|
|
|
'size': vimsupport.GetIntValue( '&previewheight' ),
|
|
|
|
'fix': True,
|
2016-05-06 01:52:04 -04:00
|
|
|
'focus': False,
|
2015-11-07 20:16:13 -05:00
|
|
|
'watch': True,
|
|
|
|
'position': 'end'
|
|
|
|
}
|
|
|
|
|
|
|
|
vimsupport.OpenFilename( __file__, options )
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vim_command.assert_has_exact_calls( [
|
|
|
|
call( '12split {0}'.format( __file__ ) ),
|
2015-11-07 20:16:13 -05:00
|
|
|
call( "exec "
|
|
|
|
"'au BufEnter <buffer> :silent! checktime {0}'".format( __file__ ) ),
|
2017-01-31 15:35:34 -05:00
|
|
|
call( 'silent! normal! Gzz' ),
|
2015-11-07 20:16:13 -05:00
|
|
|
call( 'silent! wincmd p' )
|
|
|
|
] )
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vim_current.buffer.options.__setitem__.assert_has_exact_calls( [
|
2015-11-07 20:16:13 -05:00
|
|
|
call( 'autoread', True ),
|
|
|
|
] )
|
|
|
|
|
Support FixIt commands across buffers
We simply apply the changes to each file in turn. The existing replacement
logic is unchanged, except that it now no longer implicitly assumes we are
talking about the current buffer.
If a buffer is not visible for the requested file name, we open it in
a horizontal split, make the edits, then hide the window. Because this
can cause UI flickering, and leave hidden, modified buffers around, we
issue a warning to the user stating the number of files for which we are
going to do this. We pop up the quickfix list at the end of applying
the edits to allow the user to see what we changed.
If the user opts to abort due to, say, the file being open in another
window, we simply raise an error and give up, as undoing the changes
is too complex to do programatically, but trivial to do manually in such
a rare case.
2016-01-11 17:19:33 -05:00
|
|
|
vim_current.window.options.__setitem__.assert_has_exact_calls( [
|
2015-11-07 20:16:13 -05:00
|
|
|
call( 'winfixheight', True )
|
|
|
|
] )
|
2016-02-28 17:42:18 -05:00
|
|
|
|
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
def GetUnsavedAndSpecifiedBufferData_EncodedUnicodeCharsInBuffers_test():
|
2016-09-05 11:33:30 -04:00
|
|
|
filepath = os.path.realpath( 'filename' )
|
2016-10-08 04:53:17 -04:00
|
|
|
contents = [ ToBytes( u'abc' ), ToBytes( u'fДa' ) ]
|
|
|
|
vim_buffer = VimBuffer( filepath, contents = contents )
|
2016-09-05 11:33:30 -04:00
|
|
|
|
2016-10-08 04:53:17 -04:00
|
|
|
with patch( 'vim.buffers', [ vim_buffer ] ):
|
2016-09-05 11:33:30 -04:00
|
|
|
assert_that( vimsupport.GetUnsavedAndSpecifiedBufferData( filepath ),
|
|
|
|
has_entry( filepath,
|
2016-02-28 17:42:18 -05:00
|
|
|
has_entry( u'contents', u'abc\nfДa\n' ) ) )
|
|
|
|
|
|
|
|
|
2016-10-11 18:05:24 -04:00
|
|
|
def GetBufferFilepath_NoBufferName_UnicodeWorkingDirectory_test():
|
|
|
|
vim_buffer = VimBuffer( '', number = 42 )
|
|
|
|
unicode_dir = PathToTestFile( u'uni¢𐍈d€' )
|
|
|
|
with CurrentWorkingDirectory( unicode_dir ):
|
|
|
|
assert_that( vimsupport.GetBufferFilepath( vim_buffer ),
|
|
|
|
equal_to( os.path.join( unicode_dir, '42' ) ) )
|
|
|
|
|
|
|
|
|
2016-02-28 17:42:18 -05:00
|
|
|
# NOTE: Vim returns byte offsets for columns, not actual character columns. This
|
|
|
|
# makes 'ДД' have 4 columns: column 0, column 2 and column 4.
|
|
|
|
@patch( 'vim.current.line', ToBytes( 'ДДaa' ) )
|
|
|
|
@patch( 'ycm.vimsupport.CurrentColumn', side_effect = [ 4 ] )
|
|
|
|
def TextBeforeCursor_EncodedUnicode_test( *args ):
|
|
|
|
eq_( vimsupport.TextBeforeCursor(), u'ДД' )
|
|
|
|
|
|
|
|
|
|
|
|
# NOTE: Vim returns byte offsets for columns, not actual character columns. This
|
|
|
|
# makes 'ДД' have 4 columns: column 0, column 2 and column 4.
|
|
|
|
@patch( 'vim.current.line', ToBytes( 'aaДД' ) )
|
|
|
|
@patch( 'ycm.vimsupport.CurrentColumn', side_effect = [ 2 ] )
|
|
|
|
def TextAfterCursor_EncodedUnicode_test( *args ):
|
|
|
|
eq_( vimsupport.TextAfterCursor(), u'ДД' )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.current.line', ToBytes( 'fДa' ) )
|
|
|
|
def CurrentLineContents_EncodedUnicode_test( *args ):
|
|
|
|
eq_( vimsupport.CurrentLineContents(), u'fДa' )
|
2016-03-05 13:16:08 -05:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = lambda x: x )
|
|
|
|
def VimExpressionToPythonType_IntAsUnicode_test( *args ):
|
|
|
|
eq_( vimsupport.VimExpressionToPythonType( '123' ), 123 )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = lambda x: x )
|
|
|
|
def VimExpressionToPythonType_IntAsBytes_test( *args ):
|
|
|
|
eq_( vimsupport.VimExpressionToPythonType( ToBytes( '123' ) ), 123 )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = lambda x: x )
|
|
|
|
def VimExpressionToPythonType_StringAsUnicode_test( *args ):
|
|
|
|
eq_( vimsupport.VimExpressionToPythonType( 'foo' ), 'foo' )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = lambda x: x )
|
|
|
|
def VimExpressionToPythonType_StringAsBytes_test( *args ):
|
|
|
|
eq_( vimsupport.VimExpressionToPythonType( ToBytes( 'foo' ) ), 'foo' )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = lambda x: x )
|
|
|
|
def VimExpressionToPythonType_ListPassthrough_test( *args ):
|
|
|
|
eq_( vimsupport.VimExpressionToPythonType( [ 1, 2 ] ), [ 1, 2 ] )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = lambda x: x )
|
|
|
|
def VimExpressionToPythonType_ObjectPassthrough_test( *args ):
|
|
|
|
eq_( vimsupport.VimExpressionToPythonType( { 1: 2 } ), { 1: 2 } )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = lambda x: x )
|
|
|
|
def VimExpressionToPythonType_GeneratorPassthrough_test( *args ):
|
|
|
|
gen = ( x**2 for x in [ 1, 2, 3 ] )
|
|
|
|
eq_( vimsupport.VimExpressionToPythonType( gen ), gen )
|
2016-06-19 15:38:07 -04:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval',
|
|
|
|
new_callable = ExtendedMock,
|
|
|
|
side_effect = [ None, 2, None ] )
|
|
|
|
def SelectFromList_LastItem_test( vim_eval ):
|
|
|
|
eq_( vimsupport.SelectFromList( 'test', [ 'a', 'b' ] ),
|
|
|
|
1 )
|
|
|
|
|
|
|
|
vim_eval.assert_has_exact_calls( [
|
|
|
|
call( 'inputsave()' ),
|
|
|
|
call( 'inputlist( ["test", "1: a", "2: b"] )' ),
|
|
|
|
call( 'inputrestore()' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval',
|
|
|
|
new_callable = ExtendedMock,
|
|
|
|
side_effect = [ None, 1, None ] )
|
|
|
|
def SelectFromList_FirstItem_test( vim_eval ):
|
|
|
|
eq_( vimsupport.SelectFromList( 'test', [ 'a', 'b' ] ),
|
|
|
|
0 )
|
|
|
|
|
|
|
|
vim_eval.assert_has_exact_calls( [
|
|
|
|
call( 'inputsave()' ),
|
|
|
|
call( 'inputlist( ["test", "1: a", "2: b"] )' ),
|
|
|
|
call( 'inputrestore()' )
|
|
|
|
] )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = [ None, 3, None ] )
|
|
|
|
def SelectFromList_OutOfRange_test( vim_eval ):
|
|
|
|
assert_that( calling( vimsupport.SelectFromList).with_args( 'test',
|
|
|
|
[ 'a', 'b' ] ),
|
|
|
|
raises( RuntimeError, vimsupport.NO_SELECTION_MADE_MSG ) )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = [ None, 0, None ] )
|
|
|
|
def SelectFromList_SelectPrompt_test( vim_eval ):
|
|
|
|
assert_that( calling( vimsupport.SelectFromList ).with_args( 'test',
|
|
|
|
[ 'a', 'b' ] ),
|
|
|
|
raises( RuntimeError, vimsupport.NO_SELECTION_MADE_MSG ) )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'vim.eval', side_effect = [ None, -199, None ] )
|
|
|
|
def SelectFromList_Negative_test( vim_eval ):
|
|
|
|
assert_that( calling( vimsupport.SelectFromList ).with_args( 'test',
|
|
|
|
[ 'a', 'b' ] ),
|
|
|
|
raises( RuntimeError, vimsupport.NO_SELECTION_MADE_MSG ) )
|
2016-11-01 08:28:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.VariableExists', return_value = False )
|
|
|
|
@patch( 'ycm.vimsupport.SearchInCurrentBuffer', return_value = 0 )
|
|
|
|
@patch( 'vim.current' )
|
|
|
|
def InsertNamespace_insert_test( vim_current, *args ):
|
2016-11-02 08:08:30 -04:00
|
|
|
contents = [ '',
|
|
|
|
'namespace Taqueria {',
|
|
|
|
'',
|
|
|
|
' int taco = Math' ]
|
2016-11-01 08:28:28 -04:00
|
|
|
vim_current.buffer = VimBuffer( '', contents = contents )
|
|
|
|
|
|
|
|
vimsupport.InsertNamespace( 'System' )
|
|
|
|
|
|
|
|
expected_buffer = [ 'using System;',
|
2016-11-02 08:08:30 -04:00
|
|
|
'',
|
|
|
|
'namespace Taqueria {',
|
|
|
|
'',
|
|
|
|
' int taco = Math' ]
|
2016-11-01 08:28:28 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, vim_current.buffer )
|
|
|
|
|
|
|
|
|
|
|
|
@patch( 'ycm.vimsupport.VariableExists', return_value = False )
|
2016-11-02 08:08:30 -04:00
|
|
|
@patch( 'ycm.vimsupport.SearchInCurrentBuffer', return_value = 2 )
|
2016-11-01 08:28:28 -04:00
|
|
|
@patch( 'vim.current' )
|
|
|
|
def InsertNamespace_append_test( vim_current, *args ):
|
2016-11-02 08:08:30 -04:00
|
|
|
contents = [ 'namespace Taqueria {',
|
|
|
|
' using System;',
|
|
|
|
'',
|
|
|
|
' class Tasty {',
|
|
|
|
' int taco;',
|
2016-11-03 11:21:15 -04:00
|
|
|
' List salad = new List' ]
|
2016-11-01 08:28:28 -04:00
|
|
|
vim_current.buffer = VimBuffer( '', contents = contents )
|
|
|
|
|
|
|
|
vimsupport.InsertNamespace( 'System.Collections' )
|
|
|
|
|
2016-11-02 08:08:30 -04:00
|
|
|
expected_buffer = [ 'namespace Taqueria {',
|
|
|
|
' using System;',
|
|
|
|
' using System.Collections;',
|
2016-11-01 08:28:28 -04:00
|
|
|
'',
|
2016-11-02 08:08:30 -04:00
|
|
|
' class Tasty {',
|
|
|
|
' int taco;',
|
2016-11-03 11:21:15 -04:00
|
|
|
' List salad = new List' ]
|
2016-11-01 08:28:28 -04:00
|
|
|
AssertBuffersAreEqualAsBytes( expected_buffer, vim_current.buffer )
|