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-05-19 22:44:42 -04:00
|
|
|
from ycm.completers.general_completer import GeneralCompleter
|
2013-04-11 07:40:15 -04:00
|
|
|
from UltiSnips import UltiSnips_Manager
|
2013-09-20 20:24:34 -04:00
|
|
|
from ycm.server import responses
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
|
2013-09-02 17:45:53 -04:00
|
|
|
def __init__( self, user_options ):
|
|
|
|
super( UltiSnipsCompleter, self ).__init__( user_options )
|
2013-04-11 07:40:15 -04:00
|
|
|
self._candidates = None
|
2013-04-23 00:23:49 -04:00
|
|
|
self._filtered_candidates = None
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
2013-09-06 02:43:14 -04:00
|
|
|
def ShouldUseNowInner( self, request_data ):
|
|
|
|
return self.QueryLengthAboveMinThreshold( request_data )
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
2013-09-06 02:43:14 -04:00
|
|
|
def CandidatesForQueryAsync( self, request_data ):
|
|
|
|
self._filtered_candidates = self.FilterAndSortCandidates(
|
|
|
|
self._candidates, request_data[ '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-09-07 20:39:52 -04:00
|
|
|
def OnBufferVisit( self, request_data ):
|
|
|
|
# TODO: _GetCandidates should be called on the client and it should send
|
|
|
|
# the snippets to the server
|
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
|
2013-09-20 20:24:34 -04:00
|
|
|
return [ responses.BuildCompletionData(
|
2013-09-06 02:43:14 -04:00
|
|
|
str( snip.trigger ),
|
|
|
|
str( '<snip> ' + snip.description.encode( 'utf-8' ) ) )
|
|
|
|
for snip in rawsnips ]
|
2013-04-23 00:23:49 -04:00
|
|
|
except:
|
|
|
|
return []
|