Ident completer loads syntax keywords again

This commit is contained in:
Strahinja Val Markovic 2013-09-23 15:31:11 -07:00
parent c527cda436
commit 3b9b9ed036
3 changed files with 65 additions and 21 deletions

View File

@ -37,7 +37,6 @@ class IdentifierCompleter( GeneralCompleter ):
self.completer = ycm_core.IdentifierCompleter()
self.completer.EnableThreading()
self.tags_file_last_mtime = defaultdict( int )
self.filetypes_with_keywords_loaded = set()
self._logger = logging.getLogger( __name__ )
@ -124,29 +123,23 @@ class IdentifierCompleter( GeneralCompleter ):
absolute_paths_to_tag_files )
# def AddIdentifiersFromSyntax( self ):
# filetype = vim.eval( "&filetype" )
# if filetype in self.filetypes_with_keywords_loaded:
# return
# self.filetypes_with_keywords_loaded.add( filetype )
# keyword_set = syntax_parse.SyntaxKeywordsForCurrentBuffer()
# keywords = ycm_core.StringVec()
# for keyword in keyword_set:
# keywords.append( keyword )
# filepath = SYNTAX_FILENAME + filetype
# self.completer.AddIdentifiersToDatabase( keywords,
# filetype,
# filepath )
def AddIdentifiersFromSyntax( self, keyword_list, filetypes ):
keyword_vector = ycm_core.StringVec()
for keyword in keyword_list:
keyword_vector.append( ToUtf8IfNeeded( keyword ) )
filepath = SYNTAX_FILENAME + filetypes[ 0 ]
self.completer.AddIdentifiersToDatabase( keyword_vector,
ToUtf8IfNeeded( filetypes[ 0 ] ),
ToUtf8IfNeeded( filepath ) )
def OnFileReadyToParse( self, request_data ):
self.AddBufferIdentifiers( request_data )
if 'tag_files' in request_data:
self.AddIdentifiersFromTagFiles( request_data[ 'tag_files' ] )
#self.AddIdentifiersFromSyntax()
if 'syntax_keywords' in request_data:
self.AddIdentifiersFromSyntax( request_data[ 'syntax_keywords' ],
request_data[ 'filetypes' ] )
def OnInsertLeave( self, request_data ):

View File

@ -42,7 +42,7 @@ def GetCompletions_IdentifierCompleterWorks_test():
app.post_json( '/event_notification', event_data )
line_value = 'oo foo foogoo ba';
line_value = 'oo foo foogoo ba'
completion_data = {
'query': 'oo',
'filetypes': ['foo'],
@ -64,6 +64,45 @@ def GetCompletions_IdentifierCompleterWorks_test():
app.post_json( '/get_completions', completion_data ).json )
def GetCompletions_IdentifierCompleter_SyntaxKeywordsAdded_test():
app = TestApp( server.app )
event_data = {
'event_name': 'FileReadyToParse',
'filetypes': ['foo'],
'filepath': '/foo/bar',
'file_data': {
'/foo/bar': {
'contents': '',
'filetypes': ['foo']
}
},
'syntax_keywords': ['foo', 'bar', 'zoo']
}
app.post_json( '/event_notification', event_data )
line_value = 'oo '
completion_data = {
'query': 'oo',
'filetypes': ['foo'],
'filepath': '/foo/bar',
'line_num': 0,
'column_num': 2,
'start_column': 0,
'line_value': line_value,
'file_data': {
'/foo/bar': {
'contents': line_value,
'filetypes': ['foo']
}
}
}
eq_( [ BuildCompletionData( 'foo' ),
BuildCompletionData( 'zoo' ) ],
app.post_json( '/get_completions', completion_data ).json )
def FiletypeCompletionAvailable_Works_test():
app = TestApp( server.app )
request_data = {

View File

@ -25,6 +25,7 @@ import subprocess
from ycm import vimsupport
from ycm import utils
from ycm.completers.all.omni_completer import OmniCompleter
from ycm.completers.general import syntax_parse
from ycm.client.base_request import BaseRequest
from ycm.client.command_request import CommandRequest
from ycm.client.completion_request import CompletionRequest
@ -40,6 +41,7 @@ class YouCompleteMe( object ):
self._server_stdout = None
self._server_stderr = None
self._server_popen = None
self._filetypes_with_keywords_loaded = set()
self._SetupServer()
@ -127,8 +129,8 @@ class YouCompleteMe( object ):
if self._user_options[ 'collect_identifiers_from_tags_files' ]:
extra_data[ 'tag_files' ] = _GetTagFiles()
# TODO: make this work again
# if self._user_options[ 'seed_identifiers_with_syntax' ]:
if self._user_options[ 'seed_identifiers_with_syntax' ]:
self._AddSyntaxDataIfNeeded( extra_data )
SendEventNotificationAsync( 'FileReadyToParse', extra_data )
@ -210,6 +212,15 @@ class YouCompleteMe( object ):
return not all([ x in filetype_to_disable for x in filetypes ])
def _AddSyntaxDataIfNeeded( self, extra_data ):
filetype = vimsupport.CurrentFiletypes()[ 0 ]
if filetype in self._filetypes_with_keywords_loaded:
return
self._filetypes_with_keywords_loaded.add( filetype )
extra_data[ 'syntax_keywords' ] = list(
syntax_parse.SyntaxKeywordsForCurrentBuffer() )
def _GetTagFiles():
tag_files = vim.eval( 'tagfiles()' )
@ -220,3 +231,4 @@ def _GetTagFiles():
def _PathToServerScript():
dir_of_current_script = os.path.dirname( os.path.abspath( __file__ ) )
return os.path.join( dir_of_current_script, 'server/server.py' )