2016-01-03 13:55:27 -05:00
|
|
|
# Copyright (C) 2016 YouCompleteMe Contributors
|
|
|
|
#
|
|
|
|
# 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-02-27 19:12:24 -05:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import absolute_import
|
2017-03-09 09:57:27 -05:00
|
|
|
# Not installing aliases from python-future; it's unreliable and slow.
|
2016-02-27 19:12:24 -05:00
|
|
|
from builtins import * # noqa
|
|
|
|
|
2016-10-14 05:00:57 -04:00
|
|
|
from ycm.tests.test_utils import ExtendedMock, MockVimModule
|
2016-01-03 13:55:27 -05:00
|
|
|
MockVimModule()
|
|
|
|
|
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
|
2016-01-03 13:55:27 -05:00
|
|
|
from mock import patch, call
|
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
|
|
|
from nose.tools import ok_
|
2016-01-03 13:55:27 -05:00
|
|
|
from ycm.client.command_request import CommandRequest
|
|
|
|
|
|
|
|
|
2016-02-27 19:12:24 -05:00
|
|
|
class GoToResponse_QuickFix_test( object ):
|
2016-01-03 13:55:27 -05:00
|
|
|
"""This class tests the generation of QuickFix lists for GoTo responses which
|
|
|
|
return multiple locations, such as the Python completer and JavaScript
|
|
|
|
completer. It mostly proves that we use 1-based indexing for the column
|
|
|
|
number."""
|
|
|
|
|
|
|
|
def setUp( self ):
|
|
|
|
self._request = CommandRequest( [ 'GoToTest' ] )
|
|
|
|
|
|
|
|
|
|
|
|
def tearDown( self ):
|
|
|
|
self._request = None
|
|
|
|
|
|
|
|
|
|
|
|
def GoTo_EmptyList_test( self ):
|
|
|
|
self._CheckGoToList( [], [] )
|
|
|
|
|
|
|
|
|
|
|
|
def GoTo_SingleItem_List_test( self ):
|
|
|
|
self._CheckGoToList( [ {
|
|
|
|
'filepath': 'dummy_file',
|
|
|
|
'line_num': 10,
|
|
|
|
'column_num': 1,
|
|
|
|
'description': 'this is some text',
|
|
|
|
} ], [ {
|
|
|
|
'filename': 'dummy_file',
|
|
|
|
'text': 'this is some text',
|
|
|
|
'lnum': 10,
|
|
|
|
'col': 1
|
|
|
|
} ] )
|
|
|
|
|
|
|
|
|
|
|
|
def GoTo_MultiItem_List_test( self ):
|
|
|
|
self._CheckGoToList( [ {
|
|
|
|
'filepath': 'dummy_file',
|
|
|
|
'line_num': 10,
|
|
|
|
'column_num': 1,
|
|
|
|
'description': 'this is some other text',
|
|
|
|
}, {
|
|
|
|
'filepath': 'dummy_file2',
|
|
|
|
'line_num': 1,
|
|
|
|
'column_num': 21,
|
|
|
|
'description': 'this is some text',
|
|
|
|
} ], [ {
|
|
|
|
'filename': 'dummy_file',
|
|
|
|
'text': 'this is some other text',
|
|
|
|
'lnum': 10,
|
|
|
|
'col': 1
|
|
|
|
}, {
|
|
|
|
'filename': 'dummy_file2',
|
|
|
|
'text': 'this is some text',
|
|
|
|
'lnum': 1,
|
|
|
|
'col': 21
|
|
|
|
} ] )
|
|
|
|
|
|
|
|
|
2016-05-31 04:40:25 -04:00
|
|
|
@patch( 'ycm.vimsupport.VariableExists', return_value = True )
|
|
|
|
@patch( 'ycm.vimsupport.SetFittingHeightForCurrentWindow' )
|
|
|
|
@patch( 'vim.command', new_callable = ExtendedMock )
|
|
|
|
@patch( 'vim.eval', new_callable = ExtendedMock )
|
|
|
|
def _CheckGoToList( self,
|
|
|
|
completer_response,
|
|
|
|
expected_qf_list,
|
|
|
|
vim_eval,
|
|
|
|
vim_command,
|
|
|
|
set_fitting_height,
|
|
|
|
variable_exists ):
|
2016-01-03 13:55:27 -05:00
|
|
|
self._request._response = completer_response
|
|
|
|
|
2018-07-24 11:12:50 -04:00
|
|
|
self._request.RunPostCommandActionsIfNeeded( 'aboveleft' )
|
2016-01-03 13:55:27 -05:00
|
|
|
|
2016-05-31 04:40:25 -04:00
|
|
|
vim_eval.assert_has_exact_calls( [
|
|
|
|
call( 'setqflist( {0} )'.format( json.dumps( expected_qf_list ) ) )
|
2016-01-03 13:55:27 -05:00
|
|
|
] )
|
2016-05-31 04:40:25 -04:00
|
|
|
vim_command.assert_has_exact_calls( [
|
|
|
|
call( 'botright copen' ),
|
2019-03-02 07:06:46 -05:00
|
|
|
call( 'augroup ycmquickfix' ),
|
|
|
|
call( 'autocmd! * <buffer>' ),
|
|
|
|
call( 'autocmd WinLeave <buffer> '
|
|
|
|
'if bufnr( "%" ) == expand( "<abuf>" ) | q | endif' ),
|
|
|
|
call( 'augroup END' ),
|
2016-05-31 04:40:25 -04:00
|
|
|
call( 'doautocmd User YcmQuickFixOpened' )
|
|
|
|
] )
|
|
|
|
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
|
|
|
|
|
|
|
|
2016-02-27 19:12:24 -05:00
|
|
|
class Response_Detection_test( object ):
|
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 BasicResponse_test( self ):
|
|
|
|
def _BasicResponseTest( command, response ):
|
|
|
|
with patch( 'vim.command' ) as vim_command:
|
|
|
|
request = CommandRequest( [ command ] )
|
|
|
|
request._response = response
|
2018-07-24 11:12:50 -04:00
|
|
|
request.RunPostCommandActionsIfNeeded( 'belowright' )
|
2016-08-28 02:34:09 -04:00
|
|
|
vim_command.assert_called_with( "echo '{0}'".format( response ) )
|
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
|
|
|
|
|
|
|
tests = [
|
|
|
|
[ 'AnythingYouLike', True ],
|
|
|
|
[ 'GoToEvenWorks', 10 ],
|
|
|
|
[ 'FixItWorks', 'String!' ],
|
|
|
|
[ 'and8434fd andy garbag!', 10.3 ],
|
|
|
|
]
|
|
|
|
|
|
|
|
for test in tests:
|
|
|
|
yield _BasicResponseTest, test[ 0 ], test[ 1 ]
|
|
|
|
|
|
|
|
|
|
|
|
def FixIt_Response_Empty_test( self ):
|
|
|
|
# Ensures we recognise and handle fixit responses which indicate that there
|
|
|
|
# are no fixits available
|
|
|
|
def EmptyFixItTest( command ):
|
|
|
|
with patch( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks:
|
2016-08-28 02:34:09 -04:00
|
|
|
with patch( 'ycm.vimsupport.PostVimMessage' ) as 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
|
|
|
request = CommandRequest( [ command ] )
|
|
|
|
request._response = {
|
|
|
|
'fixits': []
|
|
|
|
}
|
2018-07-24 11:12:50 -04:00
|
|
|
request.RunPostCommandActionsIfNeeded( 'botright' )
|
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
|
|
|
post_vim_message.assert_called_with(
|
|
|
|
'No fixits found for current line', 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
|
|
|
replace_chunks.assert_not_called()
|
|
|
|
|
|
|
|
for test in [ 'FixIt', 'Refactor', 'GoToHell', 'any_old_garbade!!!21' ]:
|
|
|
|
yield EmptyFixItTest, test
|
|
|
|
|
|
|
|
|
|
|
|
def FixIt_Response_test( self ):
|
|
|
|
# Ensures we recognise and handle fixit responses with some dummy chunk data
|
2018-02-07 13:57:45 -05:00
|
|
|
def FixItTest( command, response, chunks, selection, silent ):
|
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( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks:
|
2016-08-28 02:34:09 -04:00
|
|
|
with patch( 'ycm.vimsupport.PostVimMessage' ) as post_vim_message:
|
2016-06-19 15:38:07 -04:00
|
|
|
with patch( 'ycm.vimsupport.SelectFromList',
|
|
|
|
return_value = selection ):
|
|
|
|
request = CommandRequest( [ command ] )
|
|
|
|
request._response = response
|
2018-07-24 11:12:50 -04:00
|
|
|
request.RunPostCommandActionsIfNeeded( 'leftabove' )
|
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
|
|
|
|
2018-02-07 13:57:45 -05:00
|
|
|
replace_chunks.assert_called_with( chunks, silent = silent )
|
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
|
|
|
|
|
|
|
basic_fixit = {
|
|
|
|
'fixits': [ {
|
|
|
|
'chunks': [ {
|
|
|
|
'dummy chunk contents': True
|
|
|
|
} ]
|
|
|
|
} ]
|
|
|
|
}
|
|
|
|
basic_fixit_chunks = basic_fixit[ 'fixits' ][ 0 ][ 'chunks' ]
|
|
|
|
|
|
|
|
multi_fixit = {
|
|
|
|
'fixits': [ {
|
2016-06-19 15:38:07 -04:00
|
|
|
'text': 'first',
|
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': [ {
|
|
|
|
'dummy chunk contents': True
|
|
|
|
} ]
|
|
|
|
}, {
|
2016-06-19 15:38:07 -04:00
|
|
|
'text': 'second',
|
|
|
|
'chunks': [ {
|
|
|
|
'dummy chunk contents': False
|
2018-02-07 13:57:45 -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
|
|
|
} ]
|
|
|
|
}
|
|
|
|
multi_fixit_first_chunks = multi_fixit[ 'fixits' ][ 0 ][ 'chunks' ]
|
2016-06-19 15:38:07 -04:00
|
|
|
multi_fixit_second_chunks = multi_fixit[ 'fixits' ][ 1 ][ 'chunks' ]
|
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
|
|
|
|
|
|
|
tests = [
|
2018-02-07 13:57:45 -05:00
|
|
|
[ 'AnythingYouLike',
|
|
|
|
basic_fixit, basic_fixit_chunks, 0, False ],
|
|
|
|
[ 'GoToEvenWorks',
|
|
|
|
basic_fixit, basic_fixit_chunks, 0, False ],
|
|
|
|
[ 'FixItWorks',
|
|
|
|
basic_fixit, basic_fixit_chunks, 0, False ],
|
|
|
|
[ 'and8434fd andy garbag!',
|
|
|
|
basic_fixit, basic_fixit_chunks, 0, False ],
|
|
|
|
[ 'Format',
|
2018-05-29 19:00:49 -04:00
|
|
|
basic_fixit, basic_fixit_chunks, 0, True ],
|
2018-02-07 13:57:45 -05:00
|
|
|
[ 'select from multiple 1',
|
|
|
|
multi_fixit, multi_fixit_first_chunks, 0, False ],
|
|
|
|
[ 'select from multiple 2',
|
|
|
|
multi_fixit, multi_fixit_second_chunks, 1, 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
|
|
|
]
|
|
|
|
|
|
|
|
for test in tests:
|
2018-02-07 13:57:45 -05:00
|
|
|
yield FixItTest, test[ 0 ], test[ 1 ], test[ 2 ], test[ 3 ], test[ 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
|
|
|
|
|
|
|
|
|
|
|
def Message_Response_test( self ):
|
|
|
|
# Ensures we correctly recognise and handle responses with a message to show
|
|
|
|
# to the user
|
|
|
|
|
|
|
|
def MessageTest( command, message ):
|
2016-08-28 02:34:09 -04:00
|
|
|
with patch( 'ycm.vimsupport.PostVimMessage' ) as 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
|
|
|
request = CommandRequest( [ command ] )
|
|
|
|
request._response = { 'message': message }
|
2018-07-24 11:12:50 -04:00
|
|
|
request.RunPostCommandActionsIfNeeded( 'rightbelow' )
|
2016-08-28 02:34:09 -04:00
|
|
|
post_vim_message.assert_called_with( message, 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
|
|
|
|
|
|
|
tests = [
|
|
|
|
[ '___________', 'This is a message' ],
|
|
|
|
[ '', 'this is also a message' ],
|
|
|
|
[ 'GetType', 'std::string' ],
|
|
|
|
]
|
|
|
|
|
|
|
|
for test in tests:
|
|
|
|
yield MessageTest, test[ 0 ], test[ 1 ]
|
|
|
|
|
|
|
|
|
|
|
|
def Detailed_Info_test( self ):
|
|
|
|
# Ensures we correctly detect and handle detailed_info responses which are
|
|
|
|
# used to display information in the preview window
|
|
|
|
|
|
|
|
def DetailedInfoTest( command, info ):
|
|
|
|
with patch( 'ycm.vimsupport.WriteToPreviewWindow' ) as write_to_preview:
|
|
|
|
request = CommandRequest( [ command ] )
|
|
|
|
request._response = { 'detailed_info': info }
|
2018-07-24 11:12:50 -04:00
|
|
|
request.RunPostCommandActionsIfNeeded( 'topleft' )
|
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
|
|
|
write_to_preview.assert_called_with( info )
|
|
|
|
|
|
|
|
tests = [
|
|
|
|
[ '___________', 'This is a message' ],
|
|
|
|
[ '', 'this is also a message' ],
|
|
|
|
[ 'GetDoc', 'std::string\netc\netc' ],
|
|
|
|
]
|
|
|
|
|
|
|
|
for test in tests:
|
|
|
|
yield DetailedInfoTest, test[ 0 ], test[ 1 ]
|
|
|
|
|
|
|
|
|
|
|
|
def GoTo_Single_test( self ):
|
|
|
|
# Ensures we handle any unknown type of response as a GoTo response
|
|
|
|
|
|
|
|
def GoToTest( command, response ):
|
|
|
|
with patch( 'ycm.vimsupport.JumpToLocation' ) as jump_to_location:
|
|
|
|
request = CommandRequest( [ command ] )
|
|
|
|
request._response = response
|
2018-07-24 11:12:50 -04:00
|
|
|
request.RunPostCommandActionsIfNeeded( 'rightbelow' )
|
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
|
|
|
jump_to_location.assert_called_with(
|
|
|
|
response[ 'filepath' ],
|
|
|
|
response[ 'line_num' ],
|
2018-07-24 11:12:50 -04:00
|
|
|
response[ 'column_num' ],
|
2018-11-25 10:11:00 -05:00
|
|
|
'rightbelow',
|
|
|
|
'same-buffer' )
|
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 GoToListTest( command, response ):
|
|
|
|
# Note: the detail of these called are tested by
|
|
|
|
# GoToResponse_QuickFix_test, so here we just check that the right call is
|
|
|
|
# made
|
|
|
|
with patch( 'ycm.vimsupport.SetQuickFixList' ) as set_qf_list:
|
2017-02-19 18:52:21 -05:00
|
|
|
with patch( 'ycm.vimsupport.OpenQuickFixList' ) as open_qf_list:
|
|
|
|
request = CommandRequest( [ command ] )
|
|
|
|
request._response = response
|
2018-07-24 11:12:50 -04:00
|
|
|
request.RunPostCommandActionsIfNeeded( 'tab' )
|
2017-02-19 18:52:21 -05:00
|
|
|
ok_( set_qf_list.called )
|
|
|
|
ok_( open_qf_list.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
|
|
|
|
|
|
|
basic_goto = {
|
|
|
|
'filepath': 'test',
|
|
|
|
'line_num': 10,
|
|
|
|
'column_num': 100,
|
|
|
|
}
|
|
|
|
|
|
|
|
tests = [
|
|
|
|
[ GoToTest, 'AnythingYouLike', basic_goto ],
|
|
|
|
[ GoToTest, 'GoTo', basic_goto ],
|
|
|
|
[ GoToTest, 'FindAThing', basic_goto ],
|
|
|
|
[ GoToTest, 'FixItGoto', basic_goto ],
|
|
|
|
[ GoToListTest, 'AnythingYouLike', [ basic_goto ] ],
|
2018-05-29 19:00:49 -04:00
|
|
|
[ GoToListTest, 'GoTo', [] ],
|
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
|
|
|
[ GoToListTest, 'FixItGoto', [ basic_goto, basic_goto ] ],
|
|
|
|
]
|
|
|
|
|
|
|
|
for test in tests:
|
|
|
|
yield test[ 0 ], test[ 1 ], test[ 2 ]
|