Commit 8c750fc8 authored by Onur Aslan's avatar Onur Aslan

Imported Upstream version 0+20160229+git94ec3ed

parent 6b940637
# Issue Prelude
**Please complete these steps and check these boxes (by putting an `x` inside
the brackets) _before_ filing your issue:**
- [ ] I have read and understood YCM's [CONTRIBUTING][cont] document.
- [ ] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
- [ ] I have read and understood YCM's [README][readme], **especially the
[Frequently Asked Questions][faq] section.**
- [ ] I have searched YCM's issue tracker to find issues similar to the one I'm
about to report and couldn't find an answer to my problem. ([Example Google
search.][search])
- [ ] If filing a bug report, I have included the output of `vim --version`.
- [ ] If filing a bug report, I have included the output of `:YcmDebugInfo`.
- [ ] If filing a bug report, I have included the output of
`:YcmToggleLogs stderr`.
- [ ] If filing a bug report, I have included which OS (including specific OS
version) I am using.
- [ ] If filing a bug report, I have included a minimal test case that reproduces
my issue.
- [ ] **I understand this is an open-source project staffed by volunteers and
that any help I receive is a selfless, heartfelt _gift_ of their free time. I
know I am not entitled to anything and will be polite and courteous.**
- [ ] **I understand my issue may be closed if it becomes obvious I didn't
actually perform all of these steps.**
Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.
# Issue Details
[If filing a bug report, please include **a list of steps** that describe how to
reproduce the bug you are experiencing. Also include test code if relevant.]
[cont]: https://github.com/Valloric/YouCompleteMe/blob/master/CONTRIBUTING.md
[code]: https://github.com/Valloric/YouCompleteMe/blob/master/CODE_OF_CONDUCT.md
[readme]: https://github.com/Valloric/YouCompleteMe/blob/master/README.md
[faq]: https://github.com/Valloric/YouCompleteMe/blob/master/README.md#faq
[search]: https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fgithub.com%2FValloric%2FYouCompleteMe%2Fissues%20python%20mac
# PR Prelude
Thank you for working on YCM! :)
**Please complete these steps and check these boxes (by putting an `x` inside
the brackets) _before_ filing your PR:**
- [ ] I have read and understood YCM's [CONTRIBUTING][cont] document.
- [ ] I have read and understood YCM's [CODE_OF_CONDUCT][code] document.
- [ ] I have included tests for the changes in my PR. If not, I have included a
rationale for why I haven't.
- [ ] **I understand my PR may be closed if it becomes obvious I didn't
actually perform all of these steps.**
# Why this change is necessary and useful
[Please explain **in detail** why the changes in this PR are needed.]
[cont]: https://github.com/Valloric/YouCompleteMe/blob/master/CONTRIBUTING.md
[code]: https://github.com/Valloric/YouCompleteMe/blob/master/CODE_OF_CONDUCT.md
# Contributor Code of Conduct
As contributors and maintainers of this project, and in the interest of
fostering an open and welcoming community, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating
documentation, submitting pull requests or patches, and other activities.
We are committed to making participation in this project a harassment-free
experience for everyone, regardless of level of experience, gender, gender
identity and expression, sexual orientation, disability, personal appearance,
body size, race, ethnicity, age, religion, or nationality.
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* Public or private harassment
* Publishing other's private information, such as physical or electronic
addresses, without explicit permission
* Other unethical or unprofessional conduct
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
By adopting this Code of Conduct, project maintainers commit themselves to
fairly and consistently applying these principles to every aspect of managing
this project. Project maintainers who do not follow or enforce the Code of
Conduct may be permanently removed from the project team.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting a project maintainer at val@markovic.io. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. Maintainers are
obligated to maintain confidentiality with regard to the reporter of an
incident.
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.3.0, available at
[http://contributor-covenant.org/version/1/3/0/][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/3/0/
This diff is collapsed.
......@@ -6,9 +6,9 @@ environment:
install:
- git submodule update --init --recursive
- ps: $env:python = if ($env:arch -eq 32) { 'C:\Python27' } else { 'C:\Python27-x64' }
- ps: (new-object net.webclient).DownloadFile('https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 'C:\get-pip.py')
- appveyor DownloadFile https://bootstrap.pypa.io/get-pip.py
- set PATH=%python%;%python%\Scripts;%PATH%
- python C:\get-pip.py
- python get-pip.py
- pip install -r python\test_requirements.txt
build_script:
- python run_tests.py
......
......@@ -29,14 +29,6 @@ let s:cursor_moved = 0
let s:moved_vertically_in_insert_mode = 0
let s:previous_num_chars_on_current_line = strlen( getline('.') )
let s:diagnostic_ui_filetypes = {
\ 'cpp': 1,
\ 'cs': 1,
\ 'c': 1,
\ 'objc': 1,
\ 'objcpp': 1,
\ }
function! youcompleteme#Enable()
" When vim is in diff mode, don't run
......@@ -139,37 +131,38 @@ endfunction
function! s:SetUpPython() abort
python << EOF
import os
import sys
import traceback
import vim
import os
import subprocess
# Add python sources folder to the system path.
script_folder = vim.eval( 's:script_folder_path' )
sys.path.insert( 0, os.path.join( script_folder, '../python' ) )
sys.path.insert( 0, os.path.join( script_folder, '../third_party/ycmd' ) )
from ycmd import utils
utils.AddNearestThirdPartyFoldersToSysPath( script_folder )
# We need to import ycmd's third_party folders as well since we import and
# use ycmd code in the client.
utils.AddNearestThirdPartyFoldersToSysPath( utils.__file__ )
from ycm import base
base.LoadJsonDefaultsIntoVim()
from ycmd import user_options_store
user_options_store.SetAll( base.BuildServerConf() )
from ycm import paths, vimsupport
popen_args = [ paths.PathToPythonInterpreter(),
paths.PathToCheckCoreVersion() ]
if utils.SafePopen( popen_args ).wait() == 2:
vimsupport.PostVimMessage(
'YouCompleteMe unavailable: YCM support libs too old, PLEASE RECOMPILE' )
vim.command( 'return 0' )
sys.path.insert( 0, os.path.join( script_folder, '..', 'python' ) )
from ycm.setup import SetUpSystemPaths, SetUpYCM
# We enclose this code in a try/except block to avoid backtraces in Vim.
try:
SetUpSystemPaths()
from ycm.youcompleteme import YouCompleteMe
ycm_state = YouCompleteMe( user_options_store.GetAll() )
vim.command( 'return 1' )
# Import the modules used in this file.
from ycm import base, vimsupport
ycm_state = SetUpYCM()
except Exception as error:
# We don't use PostVimMessage or EchoText from the vimsupport module because
# importing this module may fail.
vim.command( 'redraw | echohl WarningMsg' )
for line in traceback.format_exc().splitlines():
vim.command( "echom '{0}'".format( line.replace( "'", "''" ) ) )
vim.command( "echo 'YouCompleteMe unavailable: {0}'"
.format( str( error ).replace( "'", "''" ) ) )
vim.command( 'echohl None' )
vim.command( 'return 0' )
else:
vim.command( 'return 1' )
EOF
endfunction
......@@ -308,11 +301,6 @@ function! s:TurnOffSyntasticForCFamily()
endfunction
function! s:DiagnosticUiSupportedForCurrentFiletype()
return get( s:diagnostic_ui_filetypes, &filetype, 0 )
endfunction
function! s:AllowedToCompleteInCurrentFile()
if empty( &filetype ) ||
\ getbufvar( winbufnr( winnr() ), "&buftype" ) ==# 'nofile' ||
......@@ -462,11 +450,11 @@ function! s:OnFileReadyToParse()
" happen for special buffers.
call s:SetUpYcmChangedTick()
" Order is important here; we need to extract any done diagnostics before
" Order is important here; we need to extract any information before
" reparsing the file again. If we sent the new parse request first, then
" the response would always be pending when we called
" UpdateDiagnosticNotifications.
call s:UpdateDiagnosticNotifications()
" HandleFileParseRequest.
py ycm_state.HandleFileParseRequest()
let buffer_changed = b:changedtick != b:ycm_changedtick.file_ready_to_parse
if buffer_changed
......@@ -612,19 +600,6 @@ function! s:ClosePreviewWindowIfNeeded()
endfunction
function! s:UpdateDiagnosticNotifications()
let should_display_diagnostics = g:ycm_show_diagnostics_ui &&
\ s:DiagnosticUiSupportedForCurrentFiletype()
if !should_display_diagnostics
py ycm_state.ValidateParseRequest()
return
endif
py ycm_state.UpdateDiagnosticInterface()
endfunction
function! s:IdentifierFinishedOperations()
if !pyeval( 'base.CurrentIdentifierFinished()' )
return
......@@ -853,15 +828,8 @@ function! s:ForceCompile()
echom "Forcing compilation, this will block Vim until done."
py ycm_state.OnFileReadyToParse()
while 1
let diagnostics_ready = pyeval(
\ 'ycm_state.DiagnosticsForCurrentFileReady()' )
if diagnostics_ready
break
endif
py ycm_state.HandleFileParseRequest( True )
sleep 100m
endwhile
return 1
endfunction
......@@ -871,8 +839,6 @@ function! s:ForceCompileAndDiagnostics()
if !compilation_succeeded
return
endif
call s:UpdateDiagnosticNotifications()
echom "Diagnostics refreshed."
endfunction
......@@ -883,11 +849,7 @@ function! s:ShowDiagnostics()
return
endif
let diags = pyeval(
\ 'ycm_state.GetDiagnosticsFromStoredRequest( qflist_format = True )' )
if !empty( diags )
call setloclist( 0, diags )
if pyeval( 'ycm_state.PopulateLocationListWithLatestDiagnostics()' )
if g:ycm_open_loclist_on_ycm_diags
lopen
endif
......
This diff is collapsed.
......@@ -6,6 +6,11 @@ import sys
import os.path as p
import glob
major, minor = sys.version_info[ 0 : 2 ]
if major != 2 or minor < 6:
sys.exit( 'The build script requires Python version >= 2.6 and < 3.0; '
'your version of Python is ' + sys.version )
DIR_OF_THIS_SCRIPT = p.dirname( p.abspath( __file__ ) )
DIR_OF_OLD_LIBS = p.join( DIR_OF_THIS_SCRIPT, 'python' )
......
......@@ -47,14 +47,11 @@ let s:python_folder_path = s:script_folder_path . '/../python/'
let s:ycmd_folder_path = s:script_folder_path . '/../third_party/ycmd/'
function! s:YcmLibsPresentIn( path_prefix )
if filereadable(a:path_prefix . 'ycm_client_support.so') &&
\ filereadable(a:path_prefix . 'ycm_core.so')
if filereadable(a:path_prefix . 'ycm_core.so')
return 1
elseif filereadable(a:path_prefix . 'ycm_client_support.pyd') &&
\ filereadable(a:path_prefix . 'ycm_core.pyd')
elseif filereadable(a:path_prefix . 'ycm_core.pyd')
return 1
elseif filereadable(a:path_prefix . 'ycm_client_support.dll') &&
\ filereadable(a:path_prefix . 'ycm_core.dll')
elseif filereadable(a:path_prefix . 'ycm_core.dll')
return 1
endif
return 0
......@@ -75,8 +72,7 @@ let g:ycm_check_if_ycm_core_present =
if g:ycm_check_if_ycm_core_present &&
\ !s:YcmLibsPresentIn( s:ycmd_folder_path )
echohl WarningMsg |
\ echomsg "ycm_client_support.[so|pyd|dll] and " .
\ "ycm_core.[so|pyd|dll] not detected; you need to compile " .
\ echomsg "ycm_core.[so|pyd|dll] not detected; you need to compile " .
\ "YCM before using it. Read the docs!" |
\ echohl None
call s:restore_cpo()
......@@ -85,11 +81,11 @@ endif
let g:loaded_youcompleteme = 1
" NOTE: Most defaults are in default_settings.json. They are loaded into Vim
" global with the 'ycm_' prefix if such a key does not already exist; thus, the
" user can override the defaults.
" NOTE: Most defaults are in third_party/ycmd/ycmd/default_settings.json. They
" are loaded into Vim globals with the 'ycm_' prefix if such a key does not
" already exist; thus, the user can override the defaults.
" The only defaults that are here are the ones that are only relevant to the YCM
" Vim client and not the server.
" Vim client and not the ycmd server.
let g:ycm_allow_changing_updatetime =
\ get( g:, 'ycm_allow_changing_updatetime', 1 )
......
......@@ -2,3 +2,5 @@ flake8>=2.0
mock>=1.0.1
nose>=1.3.0
PyHamcrest>=1.8.0
# This needs to be kept in sync with submodule checkout in third_party/ycmd/third_party
future==0.15.2
#!/usr/bin/env python
#
# Copyright (C) 2011, 2012 Google Inc.
#
# This file is part of YouCompleteMe.
......
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
......@@ -19,13 +17,14 @@
import requests
import urlparse
import json
from base64 import b64decode, b64encode
from retries import retries
from requests_futures.sessions import FuturesSession
from ycm.unsafe_thread_pool_executor import UnsafeThreadPoolExecutor
from ycm import vimsupport
from ycmd.utils import ToUtf8Json
from ycmd.hmac_utils import CreateRequestHmac, CreateHmac, SecureStringsEqual
from ycmd.utils import ToBytes
from ycmd.hmac_utils import CreateRequestHmac, CreateHmac, SecureBytesEqual
from ycmd.responses import ServerError, UnknownExtraConf
_HEADERS = {'content-type': 'application/json'}
......@@ -91,7 +90,7 @@ class BaseRequest( object ):
def SendRequest( data, handler, method, timeout ):
request_uri = _BuildUri( handler )
if method == 'POST':
sent_data = ToUtf8Json( data )
sent_data = _ToUtf8Json( data )
return BaseRequest.session.post(
request_uri,
data = sent_data,
......@@ -109,7 +108,7 @@ class BaseRequest( object ):
def DelayedSendRequest( data, handler, method ):
request_uri = _BuildUri( handler )
if method == 'POST':
sent_data = ToUtf8Json( data )
sent_data = _ToUtf8Json( data )
return requests.post(
request_uri,
data = sent_data,
......@@ -184,13 +183,18 @@ def HandleServerException( exception ):
vimsupport.PostVimMessage( serialized_exception )
def _ToUtf8Json( data ):
return ToBytes( json.dumps( data ) if data else None )
def _ValidateResponseObject( response ):
hmac = CreateHmac( response.content, BaseRequest.hmac_secret )
if not SecureStringsEqual( hmac,
b64decode( response.headers[ _HMAC_HEADER ] ) ):
our_hmac = CreateHmac( response.content, BaseRequest.hmac_secret )
their_hmac = ToBytes( b64decode( response.headers[ _HMAC_HEADER ] ) )
if not SecureBytesEqual( our_hmac, their_hmac ):
raise RuntimeError( 'Received invalid HMAC for response!' )
return True
def _BuildUri( handler ):
return urlparse.urljoin( BaseRequest.server_location, handler )
......@@ -218,6 +222,7 @@ def _CheckServerIsHealthyWithCache():
except:
return False
def MakeServerException( data ):
if data[ 'exception' ][ 'TYPE' ] == UnknownExtraConf.__name__:
return UnknownExtraConf( data[ 'exception' ][ 'extra_conf_file' ] )
......
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
......@@ -20,7 +18,7 @@
import vim
from ycm.client.base_request import BaseRequest, BuildRequestData, ServerError
from ycm import vimsupport
from ycmd.utils import ToUtf8IfNeeded
from ycmd.utils import ToUnicode
def _EnsureBackwardsCompatibility( arguments ):
......@@ -35,10 +33,6 @@ class CommandRequest( BaseRequest ):
self._arguments = _EnsureBackwardsCompatibility( arguments )
self._completer_target = ( completer_target if completer_target
else 'filetype_default' )
self._is_goto_command = (
self._arguments and self._arguments[ 0 ].startswith( 'GoTo' ) )
self._is_fixit_command = (
self._arguments and self._arguments[ 0 ].startswith( 'FixIt' ) )
self._response = None
......@@ -63,29 +57,31 @@ class CommandRequest( BaseRequest ):
if not self.Done() or self._response is None:
return
if self._is_goto_command:
return self._HandleGotoResponse()
if self._is_fixit_command:
return self._HandleFixitResponse()
# If not a dictionary or a list, the response is necessarily a
# scalar: boolean, number, string, etc. In this case, we print
# it to the user.
if not isinstance( self._response, ( dict, list ) ):
return self._HandleBasicResponse()
if 'fixits' in self._response:
return self._HandleFixitResponse()
if 'message' in self._response:
return self._HandleMessageResponse()
if 'detailed_info' in self._response:
return self._HandleDetailedInfoResponse()
# The only other type of response we understand is GoTo, and that is the
# only one that we can't detect just by inspecting the response (it should
# either be a single location or a list)
return self._HandleGotoResponse()
def _HandleGotoResponse( self ):
if isinstance( self._response, list ):
defs = [ _BuildQfListItem( x ) for x in self._response ]
vim.eval( 'setqflist( %s )' % repr( defs ) )
vimsupport.SetQuickFixList(
[ _BuildQfListItem( x ) for x in self._response ] )
vim.eval( 'youcompleteme#OpenGoToList()' )
else:
vimsupport.JumpToLocation( self._response[ 'filepath' ],
......@@ -98,12 +94,10 @@ class CommandRequest( BaseRequest ):
vimsupport.EchoText( "No fixits found for current line" )
else:
chunks = self._response[ 'fixits' ][ 0 ][ 'chunks' ]
vimsupport.ReplaceChunksList( chunks )
vimsupport.EchoTextVimWidth( "FixIt applied "
+ str( len( chunks ) )
+ " changes" )
try:
vimsupport.ReplaceChunks( chunks )
except RuntimeError as e:
vimsupport.PostMultiLineNotice( e.message )
def _HandleBasicResponse( self ):
......@@ -129,9 +123,9 @@ def SendCommandRequest( arguments, completer ):
def _BuildQfListItem( goto_data_item ):
qf_item = {}
if 'filepath' in goto_data_item:
qf_item[ 'filename' ] = ToUtf8IfNeeded( goto_data_item[ 'filepath' ] )
qf_item[ 'filename' ] = ToUnicode( goto_data_item[ 'filepath' ] )
if 'description' in goto_data_item:
qf_item[ 'text' ] = ToUtf8IfNeeded( goto_data_item[ 'description' ] )
qf_item[ 'text' ] = ToUnicode( goto_data_item[ 'description' ] )
if 'line_num' in goto_data_item:
qf_item[ 'lnum' ] = goto_data_item[ 'line_num' ]
if 'column_num' in goto_data_item:
......
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
......
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
......@@ -17,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ycmd.utils import ToUtf8IfNeeded
from ycmd.utils import ToBytes, ToUnicode
from ycm.client.base_request import ( BaseRequest, JsonFromFuture,
HandleServerException,
MakeServerException )
......@@ -64,26 +62,29 @@ class CompletionRequest( BaseRequest ):
def ConvertCompletionDataToVimData( completion_data ):
# see :h complete-items for a description of the dictionary fields
vim_data = {
'word' : ToUtf8IfNeeded( completion_data[ 'insertion_text' ] ),
'dup' : 1,
'word' : '',
'dup' : 1,
'empty' : 1,
}
if ( 'extra_data' in completion_data and
'doc_string' in completion_data[ 'extra_data' ] ):
doc_string = ToUtf8IfNeeded(
completion_data[ 'extra_data' ][ 'doc_string' ] )
doc_string = ToBytes( completion_data[ 'extra_data' ][ 'doc_string' ] )
else:
doc_string = ""
if 'insertion_text' in completion_data:
vim_data[ 'word' ] = ToBytes( completion_data[ 'insertion_text' ] )
if 'menu_text' in completion_data:
vim_data[ 'abbr' ] = ToUtf8IfNeeded( completion_data[ 'menu_text' ] )
vim_data[ 'abbr' ] = ToBytes( completion_data[ 'menu_text' ] )
if 'extra_menu_info' in completion_data:
vim_data[ 'menu' ] = ToUtf8IfNeeded( completion_data[ 'extra_menu_info' ] )
vim_data[ 'menu' ] = ToBytes( completion_data[ 'extra_menu_info' ] )
if 'kind' in completion_data:
vim_data[ 'kind' ] = ToUtf8IfNeeded(
completion_data[ 'kind' ] )[ 0 ].lower()
kind = ToUnicode( completion_data[ 'kind' ] )
if kind:
vim_data[ 'kind' ] = ToBytes( kind[ 0 ].lower() )
if 'detailed_info' in completion_data:
vim_data[ 'info' ] = ToUtf8IfNeeded( completion_data[ 'detailed_info' ] )
vim_data[ 'info' ] = ToBytes( completion_data[ 'detailed_info' ] )
if doc_string:
vim_data[ 'info' ] += '\n' + doc_string
elif doc_string:
......
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
......
#!/usr/bin/env python
#
# Copyright (C) 2013 Google Inc.
#
# This file is part of YouCompleteMe.
......@@ -17,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from ycmd.utils import ToBytes
from ycm.client.completion_request import CompletionRequest
......@@ -34,5 +33,32 @@ class OmniCompletionRequest( CompletionRequest ):
return True
def RawResponse( self ):
return _ConvertVimDatasToCompletionDatas( self._results )
def Response( self ):
return self._results
def ConvertVimDataToCompletionData( vim_data ):
# see :h complete-items for a description of the dictionary fields
completion_data = {}
if 'word' in vim_data:
completion_data[ 'insertion_text' ] = ToBytes( vim_data[ 'word' ] )
if 'abbr' in vim_data:
completion_data[ 'menu_text' ] = ToBytes( vim_data[ 'abbr' ] )
if 'menu' in vim_data:
completion_data[ 'extra_menu_info' ] = ToBytes( vim_data[ 'menu' ] )
if 'kind' in vim_data:
completion_data[ 'kind' ] = [ ToBytes( vim_data[ 'kind' ] ) ]
if 'info' in vim_data:
completion_data[ 'detailed_info' ] = ToBytes( vim_data[ 'info' ] )
return completion_data
def _ConvertVimDatasToCompletionDatas( response_data ):
return [ ConvertVimDataToCompletionData( x )
for x in response_data ]
#
# Copyright (C) 2016 YouCompleteMe Contributors
#
# This file is part of YouCompleteMe.
......@@ -19,7 +18,9 @@
from ycm.test_utils import MockVimModule
MockVimModule()
import json
from mock import patch, call
from nose.tools import ok_
from ycm.client.command_request import CommandRequest
......@@ -86,6 +87,177 @@ class GoToResponse_QuickFix_test:
self._request.RunPostCommandActionsIfNeeded()
vim_eval.assert_has_calls( [
call( 'setqflist( {0} )'.format( repr( expected_qf_list ) ) ),
call( 'setqflist( {0} )'.format( json.dumps( expected_qf_list ) ) ),
call( 'youcompleteme#OpenGoToList()' ),
] )
class Response_Detection_test:
def BasicResponse_test( self ):
def _BasicResponseTest( command, response ):
with patch( 'vim.command' ) as vim_command:
request = CommandRequest( [ command ] )
request._response = response
request.RunPostCommandActionsIfNeeded()
vim_command.assert_called_with( "echom '{0}'".format( response ) )
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:
with patch( 'ycm.vimsupport.EchoText' ) as echo_text:
request = CommandRequest( [ command ] )
request._response = {
'fixits': []
}
request.RunPostCommandActionsIfNeeded()
echo_text.assert_called_with( 'No fixits found for current line' )
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
def FixItTest( command, response, chunks ):
with patch( 'ycm.vimsupport.ReplaceChunks' ) as replace_chunks:
with patch( 'ycm.vimsupport.EchoText' ) as echo_text:
request = CommandRequest( [ command ] )
request._response = response
request.RunPostCommandActionsIfNeeded()
replace_chunks.assert_called_with( chunks )
echo_text.assert_not_called()
basic_fixit = {
'fixits': [ {
'chunks': [ {
'dummy chunk contents': True
} ]
} ]
}
basic_fixit_chunks = basic_fixit[ 'fixits' ][ 0 ][ 'chunks' ]
multi_fixit = {
'fixits': [ {
'chunks': [ {
'dummy chunk contents': True
} ]
}, {
'additional fixits are ignored currently': True
} ]