YouCompleteMe/python/ycm/completers/general/general_completer_store.py

130 lines
4.2 KiB
Python
Raw Normal View History

2013-04-01 07:44:41 -04:00
#!/usr/bin/env python
#
# Copyright (C) 2013 Stanislav Golovanov <stgolovanov@gmail.com>
# Strahinja Val Markovic <val@markovic.io>
2013-04-01 07:44:41 -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/>.
2013-05-19 22:44:42 -04:00
from ycm.completers.completer import Completer
from ycm.completers.all.identifier_completer import IdentifierCompleter
from ycm.completers.general.filename_completer import FilenameCompleter
2013-09-25 13:56:46 -04:00
from ycm.completers.general.ultisnips_completer import UltiSnipsCompleter
2013-04-01 07:44:41 -04:00
class GeneralCompleterStore( Completer ):
"""
Holds a list of completers that can be used in all filetypes.
2013-04-01 07:44:41 -04:00
It overrides all Competer API methods so that specific calls to
GeneralCompleterStore are passed to all general completers.
"""
def __init__( self, user_options ):
super( GeneralCompleterStore, self ).__init__( user_options )
self._identifier_completer = IdentifierCompleter( user_options )
self._filename_completer = FilenameCompleter( user_options )
2013-09-25 13:56:46 -04:00
self._ultisnips_completer = UltiSnipsCompleter( user_options )
self._non_filename_completers = filter( lambda x: x,
[ self._ultisnips_completer,
self._identifier_completer ] )
self._all_completers = filter( lambda x: x,
[ self._identifier_completer,
self._filename_completer,
self._ultisnips_completer ] )
self._current_query_completers = []
2013-04-01 07:44:41 -04:00
def SupportedFiletypes( self ):
return set()
2013-04-01 07:44:41 -04:00
2013-09-27 16:52:04 -04:00
def GetIdentifierCompleter( self ):
return self._identifier_completer
def ShouldUseNow( self, request_data ):
self._current_query_completers = []
2013-04-01 07:44:41 -04:00
if self._filename_completer.ShouldUseNow( request_data ):
self._current_query_completers = [ self._filename_completer ]
return True
2013-04-01 07:44:41 -04:00
should_use_now = False
2013-04-01 07:44:41 -04:00
for completer in self._non_filename_completers:
should_use_this_completer = completer.ShouldUseNow( request_data )
should_use_now = should_use_now or should_use_this_completer
2013-04-01 07:44:41 -04:00
if should_use_this_completer:
self._current_query_completers.append( completer )
2013-04-01 07:44:41 -04:00
return should_use_now
2013-04-01 07:44:41 -04:00
def CandidatesForQueryAsync( self, request_data ):
for completer in self._current_query_completers:
completer.CandidatesForQueryAsync( request_data )
2013-04-01 07:44:41 -04:00
def AsyncCandidateRequestReady( self ):
return all( x.AsyncCandidateRequestReady() for x in
self._current_query_completers )
2013-04-01 07:44:41 -04:00
def CandidatesFromStoredRequest( self ):
candidates = []
for completer in self._current_query_completers:
candidates += completer.CandidatesFromStoredRequest()
2013-04-01 07:44:41 -04:00
return candidates
2013-04-01 07:44:41 -04:00
def OnFileReadyToParse( self, request_data ):
for completer in self._all_completers:
completer.OnFileReadyToParse( request_data )
2013-04-01 07:44:41 -04:00
def OnBufferVisit( self, request_data ):
for completer in self._all_completers:
completer.OnBufferVisit( request_data )
2013-04-01 07:44:41 -04:00
def OnBufferUnload( self, request_data ):
for completer in self._all_completers:
completer.OnBufferUnload( request_data )
2013-04-01 07:44:41 -04:00
def OnInsertLeave( self, request_data ):
for completer in self._all_completers:
completer.OnInsertLeave( request_data )
2013-04-01 07:44:41 -04:00
def OnCurrentIdentifierFinished( self, request_data ):
for completer in self._all_completers:
completer.OnCurrentIdentifierFinished( request_data )
def GettingCompletions( self ):
for completer in self._all_completers:
completer.GettingCompletions()
def Shutdown( self ):
for completer in self._all_completers:
completer.Shutdown()