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-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-30 16:40:25 -04:00
|
|
|
def ShouldUseNow( self, request_data ):
|
2013-09-06 02:43:14 -04:00
|
|
|
return self.QueryLengthAboveMinThreshold( request_data )
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
2013-09-30 16:40:25 -04:00
|
|
|
def ComputeCandidates( self, request_data ):
|
|
|
|
if not self.ShouldUseNow( request_data ):
|
|
|
|
return []
|
|
|
|
return self.FilterAndSortCandidates(
|
2013-09-06 02:43:14 -04:00
|
|
|
self._candidates, request_data[ 'query' ] )
|
2013-04-11 07:40:15 -04:00
|
|
|
|
|
|
|
|
2013-09-07 20:39:52 -04:00
|
|
|
def OnBufferVisit( self, request_data ):
|
2013-10-14 15:32:18 -04:00
|
|
|
raw_candidates = request_data.get( 'ultisnips_snippets', [] )
|
2013-09-25 13:56:46 -04:00
|
|
|
self._candidates = [
|
|
|
|
responses.BuildCompletionData(
|
|
|
|
str( snip[ 'trigger' ] ),
|
|
|
|
str( '<snip> ' + snip[ 'description' ].encode( 'utf-8' ) ) )
|
|
|
|
for snip in raw_candidates ]
|
2013-04-11 07:42:36 -04:00
|
|
|
|