Not parsing empty files anymore
Also, not sending non-clang supported files as unsaved buffers when a completion is requested.
This commit is contained in:
parent
11e42b49f0
commit
2726349975
@ -127,8 +127,14 @@ class ClangCompleter( Completer ):
|
|||||||
self.contents_holder = []
|
self.contents_holder = []
|
||||||
self.filename_holder = []
|
self.filename_holder = []
|
||||||
for buffer in GetUnsavedBuffers():
|
for buffer in GetUnsavedBuffers():
|
||||||
self.contents_holder.append( '\n'.join( buffer ) )
|
if not ClangAvailableForBuffer( buffer ):
|
||||||
self.filename_holder.append( buffer.name )
|
continue
|
||||||
|
contents = '\n'.join( buffer )
|
||||||
|
name = buffer.name
|
||||||
|
if not contents or not name:
|
||||||
|
continue
|
||||||
|
self.contents_holder.append( contents )
|
||||||
|
self.filename_holder.append( name )
|
||||||
|
|
||||||
unsaved_file = indexer.UnsavedFile()
|
unsaved_file = indexer.UnsavedFile()
|
||||||
unsaved_file.contents_ = self.contents_holder[ -1 ]
|
unsaved_file.contents_ = self.contents_holder[ -1 ]
|
||||||
@ -181,6 +187,8 @@ class ClangCompleter( Completer ):
|
|||||||
|
|
||||||
|
|
||||||
def OnFileReadyToParse( self ):
|
def OnFileReadyToParse( self ):
|
||||||
|
if NumLinesInBuffer( vim.current.buffer ) < 5:
|
||||||
|
return
|
||||||
self.possibly_new_diagnostics = True
|
self.possibly_new_diagnostics = True
|
||||||
self.completer.UpdateTranslationUnitAsync( vim.current.buffer.name,
|
self.completer.UpdateTranslationUnitAsync( vim.current.buffer.name,
|
||||||
self.GetUnsavedFilesVector() )
|
self.GetUnsavedFilesVector() )
|
||||||
@ -200,6 +208,9 @@ class ClangCompleter( Completer ):
|
|||||||
return self.last_diagnostics
|
return self.last_diagnostics
|
||||||
|
|
||||||
|
|
||||||
|
def NumLinesInBuffer( buffer ):
|
||||||
|
# This is actually less than obvious, that's why it's wrapped in a function
|
||||||
|
return len( buffer )
|
||||||
|
|
||||||
def PostVimMessage( message ):
|
def PostVimMessage( message ):
|
||||||
# TODO: escape the message string before formating it
|
# TODO: escape the message string before formating it
|
||||||
@ -230,7 +241,8 @@ def CompletionDataToDict( completion_data ):
|
|||||||
def DiagnosticToDict( diagnostic ):
|
def DiagnosticToDict( diagnostic ):
|
||||||
# see :h getqflist for a description of the dictionary fields
|
# see :h getqflist for a description of the dictionary fields
|
||||||
return {
|
return {
|
||||||
'bufnr' : int( vim.eval( "bufnr('" + diagnostic.filename_ + "', 1)" ) ),
|
'bufnr' : int( vim.eval( "bufnr('{0}', 1)".format(
|
||||||
|
diagnostic.filename_ ) ) ),
|
||||||
'lnum' : diagnostic.line_number_,
|
'lnum' : diagnostic.line_number_,
|
||||||
'col' : diagnostic.column_number_,
|
'col' : diagnostic.column_number_,
|
||||||
'text' : diagnostic.text_,
|
'text' : diagnostic.text_,
|
||||||
@ -259,6 +271,11 @@ def CurrentLineAndColumn():
|
|||||||
return line, column
|
return line, column
|
||||||
|
|
||||||
|
|
||||||
|
def ClangAvailableForBuffer( buffer_object ):
|
||||||
|
filetype = vim.eval( 'getbufvar({0}, "&ft")'.format( buffer_object.number ) )
|
||||||
|
return filetype in CLANG_FILETYPES
|
||||||
|
|
||||||
|
|
||||||
def ClangAvailableForFile():
|
def ClangAvailableForFile():
|
||||||
filetype = vim.eval( "&filetype" )
|
filetype = vim.eval( "&filetype" )
|
||||||
return filetype in CLANG_FILETYPES
|
return filetype in CLANG_FILETYPES
|
||||||
|
Loading…
Reference in New Issue
Block a user