def __init__(self): super(CsharpCompleter, self).__init__() self._omnisharp_port = int( vimsupport.GetVariableValue('g:ycm_csharp_server_port')) self._omnisharp_host = 'http://localhost:' + str(self._omnisharp_port) if vimsupport.GetBoolValue('g:ycm_auto_start_csharp_server'): self._StartServer()
def _FindFreePort(self): """ Find port without an OmniSharp server running on it """ port = int(vimsupport.GetVariableValue('g:ycm_csharp_server_port')) while self._GetResponse('/checkalivestatus', silent=True, port=port) != None: port += 1 return port
def _GetCompletionsUserMayHaveCompleted(self): completed_item = vimsupport.GetVariableValue('v:completed_item') completions = self.RawResponse()['completions'] if 'user_data' in completed_item and completed_item['user_data']: # Vim supports user_data (8.0.1493) or later, so we actually know the # _exact_ element that was selected, having put its index in the # user_data field. return [completions[int(completed_item['user_data'])]] # Otherwise, we have to guess by matching the values in the completed item # and the list of completions. Sometimes this returns multiple # possibilities, which is essentially unresolvable. result = _FilterToMatchingCompletions(completed_item, completions, True) result = list(result) if result: return result if _HasCompletionsThatCouldBeCompletedWithMoreText( completed_item, completions): # Since the way that YCM works leads to CompleteDone called on every # character, return blank if the completion might not be done. This won't # match if the completion is ended with typing a non-keyword character. return [] result = _FilterToMatchingCompletions(completed_item, completions, False) return list(result)
def _HasCompletionsThatCouldBeCompletedWithMoreText(self, completions): completed_item = vimsupport.GetVariableValue('v:completed_item') if not completed_item: return False completed_word = utils.ToUnicode(completed_item['word']) if not completed_word: return False # Sometimes CompleteDone is called after the next character is inserted. # If so, use inserted character to filter possible completions further. text = vimsupport.TextBeforeCursor() reject_exact_match = True if text and text[-1] != completed_word[-1]: reject_exact_match = False completed_word += text[-1] for completion in completions: word = utils.ToUnicode( ConvertCompletionDataToVimData(completion)['word']) if reject_exact_match and word == completed_word: continue if word.startswith(completed_word): return True return False
def _FilterToMatchingCompletions_NewerVim(self, completions, full_match_only): """ Filter to completions matching the item Vim said was completed """ completed = vimsupport.GetVariableValue('v:completed_item') for completion in completions: item = ConvertCompletionDataToVimData(completion) match_keys = (["word", "abbr", "menu", "info"] if full_match_only else ['word']) matcher = lambda key: completed.get(key, "") == item.get(key, "") if all([matcher(i) for i in match_keys]): yield completion
def _AddUltiSnipsDataIfNeeded( self, extra_data ): # See :h UltiSnips#SnippetsInCurrentScope. try: vim.eval( 'UltiSnips#SnippetsInCurrentScope( 1 )' ) except vim.error: return snippets = vimsupport.GetVariableValue( 'g:current_ulti_dict_info' ) extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': trigger, 'description': snippet[ 'description' ] } for trigger, snippet in iteritems( snippets ) ]
def _FilterToMatchingCompletions( self, completions, full_match_only ): """Filter to completions matching the item Vim said was completed""" completed = vimsupport.GetVariableValue( 'v:completed_item' ) for completion in completions: item = ConvertCompletionDataToVimData( completion ) match_keys = ( [ "word", "abbr", "menu", "info" ] if full_match_only else [ 'word' ] ) def matcher( key ): return ( utils.ToUnicode( completed.get( key, "" ) ) == utils.ToUnicode( item.get( key, "" ) ) ) if all( [ matcher( i ) for i in match_keys ] ): yield completion
def _GetExtraDataUserMayHaveCompleted(self): completed_item = vimsupport.GetVariableValue('v:completed_item') # If Vim supports user_data (8.0.1493 or later), we actually know the # _exact_ element that was selected, having put its extra_data in the # user_data field. Otherwise, we have to guess by matching the values in the # completed item and the list of completions. Sometimes this returns # multiple possibilities, which is essentially unresolvable. if 'user_data' not in completed_item: completions = self._RawResponse()['completions'] return _FilterToMatchingCompletions(completed_item, completions) if completed_item['user_data']: return [json.loads(completed_item['user_data'])] return []
def _ShouldLoad(module_file): """Checks if a module is safe to be loaded. By default this will try to decide using a white-/blacklist and ask the user for confirmation as a fallback.""" if (module_file == GLOBAL_YCM_EXTRA_CONF_FILE or not vimsupport.GetBoolValue('g:ycm_confirm_extra_conf')): return True globlist = vimsupport.GetVariableValue('g:ycm_extra_conf_globlist') for glob in globlist: is_blacklisted = glob[0] == '!' if _MatchesGlobPattern(module_file, glob.lstrip('!')): return not is_blacklisted return vimsupport.Confirm(CONFIRM_CONF_FILE_MESSAGE.format(module_file))
def _AddUltiSnipsDataIfNeeded( extra_data ): if not USE_ULTISNIPS_DATA: return try: # Since UltiSnips may run in a different python interpreter (python 3) than # YCM, UltiSnips_Manager singleton is not necessary the same as the one # used by YCM. In particular, it means that we cannot rely on UltiSnips to # set the current filetypes to the singleton. We need to do it ourself. UltiSnips_Manager.reset_buffer_filetypes() UltiSnips_Manager.add_buffer_filetypes( vimsupport.GetVariableValue( '&filetype' ) ) rawsnips = UltiSnips_Manager._snips( '', True ) except: return # UltiSnips_Manager._snips() returns a class instance where: # class.trigger - name of snippet trigger word ( e.g. defn or testcase ) # class.description - description of the snippet extra_data[ 'ultisnips_snippets' ] = [ { 'trigger': x.trigger, 'description': x.description } for x in rawsnips ]
def _AddUltiSnipsDataIfNeeded(self, extra_data): # See :h UltiSnips#SnippetsInCurrentScope. # Errors when evaluating Vim expressions are not caught by Python # try/except blocks prior to Vim 7.4.107. We check that the UltiSnips # function exists for these versions. # TODO: remove this when bumping version requirement to 7.4.107 or greater. if (not vimsupport.VimVersionAtLeast("7.4.107") and not vimsupport.GetBoolValue( "exists( '*UltiSnips#SnippetsInCurrentScope' )")): return try: vim.eval('UltiSnips#SnippetsInCurrentScope( 1 )') except vim.error: return snippets = vimsupport.GetVariableValue('g:current_ulti_dict_info') extra_data['ultisnips_snippets'] = [{ 'trigger': trigger, 'description': snippet['description'] } for trigger, snippet in iteritems(snippets)]
# # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>. import os import vim import ycm_core from collections import defaultdict from ycm.completers.general_completer import GeneralCompleter from ycm.completers.general import syntax_parse from ycm import vimsupport from ycm import utils MAX_IDENTIFIER_COMPLETIONS_RETURNED = 10 MIN_NUM_COMPLETION_START_CHARS = int( vimsupport.GetVariableValue("g:ycm_min_num_of_chars_for_completion")) MIN_NUM_CANDIDATE_SIZE_CHARS = int( vimsupport.GetVariableValue("g:ycm_min_num_identifier_candidate_chars")) SYNTAX_FILENAME = 'YCM_PLACEHOLDER_FOR_SYNTAX' class IdentifierCompleter(GeneralCompleter): def __init__(self): super(IdentifierCompleter, self).__init__() self.completer = ycm_core.IdentifierCompleter() self.completer.EnableThreading() self.tags_file_last_mtime = defaultdict(int) self.filetypes_with_keywords_loaded = set() def ShouldUseNow(self, start_column): return self.QueryLengthAboveMinThreshold(start_column)
# 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/>. from collections import defaultdict import vim import ycm_core from ycm import vimsupport from ycm import extra_conf_store from ycm.completers.completer import Completer from ycm.completers.cpp.flags import Flags CLANG_FILETYPES = set(['c', 'cpp', 'objc', 'objcpp']) MAX_DIAGNOSTICS_TO_DISPLAY = int( vimsupport.GetVariableValue("g:ycm_max_diagnostics_to_display")) class ClangCompleter(Completer): def __init__(self): super(ClangCompleter, self).__init__() self.completer = ycm_core.ClangCompleter() self.completer.EnableThreading() self.contents_holder = [] self.filename_holder = [] self.last_prepared_diagnostics = [] self.parse_future = None self.flags = Flags() self.diagnostic_store = None # We set this flag when a compilation request comes in while one is already
# 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/>. import os import vim import ycm_core from collections import defaultdict from ycm.completers.general_completer import GeneralCompleter from ycm.completers.general import syntax_parse from ycm import vimsupport from ycm import utils MAX_IDENTIFIER_COMPLETIONS_RETURNED = 10 MIN_NUM_CHARS = int( vimsupport.GetVariableValue( "g:ycm_min_num_of_chars_for_completion" ) ) SYNTAX_FILENAME = 'YCM_PLACEHOLDER_FOR_SYNTAX' class IdentifierCompleter( GeneralCompleter ): def __init__( self ): super( IdentifierCompleter, self ).__init__() self.completer = ycm_core.IdentifierCompleter() self.completer.EnableThreading() self.tags_file_last_mtime = defaultdict( int ) self.filetypes_with_keywords_loaded = set() def ShouldUseNow( self, start_column ): return self.QueryLengthAboveMinThreshold( start_column )
# You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>. import os import vim import re import ycm_core from collections import defaultdict from ycm.completers.general_completer import GeneralCompleter from ycm.completers.general import syntax_parse from ycm import vimsupport from ycm import utils MAX_IDENTIFIER_COMPLETIONS_RETURNED = 10 MIN_NUM_CHARS = int( vimsupport.GetVariableValue("g:ycm_min_num_of_chars_for_completion")) SYNTAX_FILENAME = 'YCM_PLACEHOLDER_FOR_SYNTAX' DISTANCE_RANGE = 10000 COMMON_FILETYPE = "YCM_COMMON_FILETYPE_GROUP" class IdentifierCompleter(GeneralCompleter): def __init__(self): super(IdentifierCompleter, self).__init__() self.completer = ycm_core.IdentifierCompleter() self.completer.EnableThreading() self.tags_file_last_mtime = defaultdict(int) self.filetypes_with_keywords_loaded = set() self.identifier_regex = re.compile("[_a-zA-Z]\\w*") def GetFiletypeOrCommonGroup(self):
def SyntaxKeywordsForCurrentBuffer(): vim.command('redir => b:ycm_syntax') vim.command('silent! syntax list') vim.command('redir END') syntax_output = vimsupport.GetVariableValue('b:ycm_syntax') return _KeywordsFromSyntaxListOutput(syntax_output)
def _StopServer(self): """ Stop the OmniSharp server """ self._GetResponse('/stopserver') self._omnisharp_port = int( vimsupport.GetVariableValue('g:ycm_csharp_server_port')) vimsupport.PostVimMessage('Stopping OmniSharp server')
import os import imp import random import string import sys import vim from ycm import vimsupport from fnmatch import fnmatch # Constants YCM_EXTRA_CONF_FILENAME = '.ycm_extra_conf.py' CONFIRM_CONF_FILE_MESSAGE = ('Found {0}. Load? \n\n(Question can be turned ' 'off with options, see YCM docs)') GLOBAL_YCM_EXTRA_CONF_FILE = os.path.expanduser( vimsupport.GetVariableValue("g:ycm_global_ycm_extra_conf")) # Singleton variables _module_for_module_file = {} _module_file_for_source_file = {} def ModuleForSourceFile(filename): return _Load(ModuleFileForSourceFile(filename)) def ModuleFileForSourceFile(filename): """This will try all files returned by _ExtraConfModuleSourceFilesForFile in order and return the filename of the first module that was allowed to load. If no module was found or allowed to load, None is returned."""