Now reparsing clang files on buffer enter

This creates an auto PCH that speeds up code completion.
This commit is contained in:
Strahinja Val Markovic 2012-07-23 18:35:48 -07:00
parent cfede619f2
commit ad32584a10
2 changed files with 33 additions and 19 deletions

View File

@ -75,6 +75,10 @@ endfunction
function! s:OnBufferVisit()
call s:SetCompleteFunc()
py identcomp.OnFileEnter()
if pyeval('ycm.ClangAvailableForFile()')
py clangcomp.OnFileEnter()
endif
endfunction

View File

@ -123,19 +123,8 @@ class ClangCompleter( Completer ):
self.filename_holder = []
def CandidatesForQueryAsync( self, query ):
# TODO: sanitize query
def GetUnsavedFilesVector( self ):
files = indexer.UnsavedFileVec()
# CAREFUL HERE! For UnsavedFile filename and contents we are referring
# directly to Python-allocated and -managed memory since we are accepting
# pointers to data members of python objects. We need to ensure that those
# objects outlive our UnsavedFile objects. This is why we need the
# contents_holder and filename_holder lists, to make sure the string objects
# are still around when we call CandidatesForQueryAndLocationInFile. We do
# this to avoid an extra copy of the entire file contents.
if not query:
self.contents_holder = []
self.filename_holder = []
for buffer in GetUnsavedBuffers():
@ -149,6 +138,24 @@ class ClangCompleter( Completer ):
files.append( unsaved_file )
return files
def CandidatesForQueryAsync( self, query ):
# TODO: sanitize query
# CAREFUL HERE! For UnsavedFile filename and contents we are referring
# directly to Python-allocated and -managed memory since we are accepting
# pointers to data members of python objects. We need to ensure that those
# objects outlive our UnsavedFile objects. This is why we need the
# contents_holder and filename_holder lists, to make sure the string objects
# are still around when we call CandidatesForQueryAndLocationInFile. We do
# this to avoid an extra copy of the entire file contents.
files = indexer.UnsavedFileVec()
if not query:
files = self.GetUnsavedFilesVector()
line, _ = vim.current.window.cursor
column = int( vim.eval( "s:completion_start_column" ) ) + 1
current_buffer = vim.current.buffer
@ -167,7 +174,9 @@ class ClangCompleter( Completer ):
def OnFileEnter( self ):
pass
self.future = self.completer.UpdateTranslationUnit(
vim.current.buffer.name,
self.GetUnsavedFilesVector() )
@ -211,12 +220,13 @@ def CurrentLineAndColumn():
return line, column
def ShouldUseClang( start_column ):
if not CLANG_COMPLETION_ENABLED:
return False
def ClangAvailableForFile():
filetype = vim.eval( "&filetype" )
if filetype not in CLANG_FILETYPES:
return filetype in CLANG_FILETYPES
def ShouldUseClang( start_column ):
if not CLANG_COMPLETION_ENABLED or not ClangAvailableForFile():
return False
line = vim.current.line