def OnFileReadyToParse( self ): self.AddBufferIdentifiers() if vimsupport.GetBoolValue( 'g:ycm_collect_identifiers_from_tags_files' ): self.AddIdentifiersFromTagFiles() if vimsupport.GetBoolValue( 'g:ycm_seed_identifiers_with_syntax' ): self.AddIdentifiersFromSyntax()
def SendCommandRequest( self, arguments, modifiers, has_range, start_line, end_line ): final_arguments = [] for argument in arguments: # The ft= option which specifies the completer when running a command is # ignored because it has not been working for a long time. The option is # still parsed to not break users that rely on it. if argument.startswith( 'ft=' ): continue final_arguments.append( argument ) extra_data = { 'options': { 'tab_size': vimsupport.GetIntValue( 'shiftwidth()' ), 'insert_spaces': vimsupport.GetBoolValue( '&expandtab' ) } } if has_range: extra_data.update( vimsupport.BuildRange( start_line, end_line ) ) self._AddExtraConfDataIfNeeded( extra_data ) return SendCommandRequest( final_arguments, modifiers, self._user_options[ 'goto_buffer_command' ], extra_data )
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 _GetCommandRequestArguments( self, arguments, has_range, start_line, end_line ): extra_data = { 'options': { 'tab_size': vimsupport.GetIntValue( 'shiftwidth()' ), 'insert_spaces': vimsupport.GetBoolValue( '&expandtab' ) } } final_arguments = [] for argument in arguments: if argument.startswith( 'ft=' ): extra_data[ 'completer_target' ] = argument[ 3: ] continue elif argument.startswith( '--bufnr=' ): extra_data[ 'bufnr' ] = int( argument[ len( '--bufnr=' ): ] ) continue final_arguments.append( argument ) if has_range: extra_data.update( vimsupport.BuildRange( start_line, end_line ) ) self._AddExtraConfDataIfNeeded( extra_data ) return final_arguments, extra_data
def GetCompletions( self ): request = self.GetCurrentCompletionRequest() request.Start() while not request.Done(): try: if vimsupport.GetBoolValue( 'complete_check()' ): return { 'words' : [], 'refresh' : 'always' } except KeyboardInterrupt: return { 'words' : [], 'refresh' : 'always' } results = base.AdjustCandidateInsertionText( request.Response() ) return { 'words' : results, 'refresh' : 'always' }
def SendCommandRequest(self, arguments, completer, modifiers, has_range, start_line, end_line): extra_data = { 'options': { 'tab_size': vimsupport.GetIntValue('shiftwidth()'), 'insert_spaces': vimsupport.GetBoolValue('&expandtab') } } if has_range: extra_data.update(vimsupport.BuildRange(start_line, end_line)) self._AddExtraConfDataIfNeeded(extra_data) return SendCommandRequest(arguments, completer, modifiers, extra_data)
def AddBufferIdentifiers(self): filetype = vim.eval("&filetype") filepath = vim.eval("expand('%:p')") collect_from_comments_and_strings = vimsupport.GetBoolValue( "g:ycm_collect_identifiers_from_comments_and_strings") if not filetype or not filepath: return text = "\n".join(vim.current.buffer) self.completer.AddCandidatesToDatabaseFromBufferAsync( text, filetype, filepath, collect_from_comments_and_strings)
def AddBufferIdentifiers(self): # TODO: use vimsupport.GetFiletypes; also elsewhere in file filetype = self.GetFiletypeOrCommonGroup() filepath = vim.eval("expand('%:p')") collect_from_comments_and_strings = vimsupport.GetBoolValue( "g:ycm_collect_identifiers_from_comments_and_strings") if not filetype or not filepath: return text = "\n".join(vim.current.buffer) self.completer.AddIdentifiersToDatabaseFromBufferAsync( text, filetype, filepath, collect_from_comments_and_strings)
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(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)]
def GetFiletypeOrCommonGroup(self): if vimsupport.GetBoolValue("g:ycm_filetype_identifier_grouping"): return vim.eval("&filetype") else: return COMMON_FILETYPE
def OnVimLeave(self): if (vimsupport.GetBoolValue('g:ycm_auto_stop_csharp_server') and self._ServerIsRunning()): self._StopServer()
def ShouldUseCache(self): return vimsupport.GetBoolValue("g:ycm_cache_omnifunc")
def __init__(self): super(CsharpCompleter, self).__init__() self._omnisharp_port = None if vimsupport.GetBoolValue('g:ycm_auto_start_csharp_server'): self._StartServer()
# 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/>. import vim import os import re from ycm import vimsupport from ycm.completers.threaded_completer import ThreadedCompleter from ycm.completers.cpp.clang_completer import InCFamilyFile from ycm.completers.cpp.flags import Flags USE_WORKING_DIR = vimsupport.GetBoolValue( 'g:ycm_filepath_completion_use_working_dir' ) class FilenameCompleter( ThreadedCompleter ): """ General completer that provides filename and filepath completions. """ def __init__( self ): super( FilenameCompleter, self ).__init__() self._flags = Flags() self._path_regex = re.compile( """ # 1 or more 'D:/'-like token or '/' or '~' or './' or '../' (?:[A-z]+:/|[/~]|\./|\.+/)+