2013-04-11 07:40:15 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Stanislav Golovanov <stgolovanov@gmail.com>
|
2013-04-23 00:23:49 -04:00
|
|
|
# Strahinja Val Markovic <val@markovic.io>
|
2013-04-11 07:40:15 -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-04-23 01:19:26 -04:00
|
|
|
from completers.general_completer import GeneralCompleter
|
2013-04-11 07:40:15 -04:00
|
|
|
from UltiSnips import UltiSnips_Manager
|
|
|
|
|
|
|
|
|
2013-04-11 07:42:36 -04:00
|
|
|
class UltiSnipsCompleter( GeneralCompleter ):
|
2013-04-11 07:40:15 -04:00
|
|
|
"""
|
|
|
|
General completer that provides UltiSnips snippet names in completions.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__( self ):
|
|
|
|
super( UltiSnipsCompleter, self ).__init__()
|
|
|
|
self._candidates = None
|
2013-04-23 00:23:49 -04:00
|
|
|
self._filtered_candidates = None
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
def ShouldUseNowInner( self, start_column ):
|
2013-04-11 07:42:36 -04:00
|
|
|
return self.QueryLengthAboveMinThreshold( start_column )
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
2013-04-23 00:23:49 -04:00
|
|
|
def CandidatesForQueryAsync( self, query, unused_start_column ):
|
|
|
|
self._filtered_candidates = self.FilterAndSortCandidates( self._candidates,
|
|
|
|
query )
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
2013-04-23 00:23:49 -04:00
|
|
|
def AsyncCandidateRequestReady( self ):
|
2013-04-24 16:07:56 -04:00
|
|
|
return True
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
2013-04-23 00:23:49 -04:00
|
|
|
def CandidatesFromStoredRequest( self ):
|
2013-04-24 16:07:56 -04:00
|
|
|
return self._filtered_candidates if self._filtered_candidates else []
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
2013-04-24 16:31:28 -04:00
|
|
|
def OnBufferVisit( self ):
|
2013-04-23 00:23:49 -04:00
|
|
|
self._candidates = _GetCandidates()
|
2013-04-11 07:42:36 -04:00
|
|
|
|
2013-04-11 07:40:15 -04:00
|
|
|
|
2013-04-23 00:23:49 -04:00
|
|
|
def _GetCandidates():
|
|
|
|
try:
|
|
|
|
rawsnips = UltiSnips_Manager._snips( '', 1 )
|
2013-04-11 07:40:15 -04:00
|
|
|
|
2013-04-23 00:23:49 -04:00
|
|
|
# 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
|
|
|
|
return [ { 'word': str( snip.trigger ),
|
|
|
|
'menu': str( '<snip> ' + snip.description ) }
|
|
|
|
for snip in rawsnips ]
|
|
|
|
except:
|
|
|
|
return []
|