Creating a new Completer Python base class
Common logic for the IdentifierCompleter and ClangCompleter (from the python plugin) is now in the base class.
This commit is contained in:
parent
20f0d2a280
commit
ca861d9f0c
@ -24,22 +24,10 @@ import indexer
|
|||||||
min_num_chars = int( vim.eval( "g:ycm_min_num_of_chars_for_completion" ) )
|
min_num_chars = int( vim.eval( "g:ycm_min_num_of_chars_for_completion" ) )
|
||||||
clang_filetypes = set( [ 'c', 'cpp', 'objc', 'objcpp' ] )
|
clang_filetypes = set( [ 'c', 'cpp', 'objc', 'objcpp' ] )
|
||||||
|
|
||||||
|
class Completer( object ):
|
||||||
class IdentifierCompleter( object ):
|
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
self.completer = indexer.IdentifierCompleter()
|
|
||||||
self.completer.EnableThreading()
|
|
||||||
self.pattern = re.compile( r"[_a-zA-Z]\w*" )
|
|
||||||
self.future = None
|
self.future = None
|
||||||
|
|
||||||
|
|
||||||
def CandidatesForQueryAsync( self, query ):
|
|
||||||
filetype = vim.eval( "&filetype" )
|
|
||||||
self.future = self.completer.CandidatesForQueryAndTypeAsync(
|
|
||||||
SanitizeQuery( query ),
|
|
||||||
filetype )
|
|
||||||
|
|
||||||
|
|
||||||
def AsyncCandidateRequestReady( self ):
|
def AsyncCandidateRequestReady( self ):
|
||||||
return self.future.ResultsReady()
|
return self.future.ResultsReady()
|
||||||
|
|
||||||
@ -47,10 +35,23 @@ class IdentifierCompleter( object ):
|
|||||||
def CandidatesFromStoredRequest( self ):
|
def CandidatesFromStoredRequest( self ):
|
||||||
if not self.future:
|
if not self.future:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return self.future.GetResults()
|
return self.future.GetResults()
|
||||||
|
|
||||||
|
|
||||||
|
class IdentifierCompleter( Completer ):
|
||||||
|
def __init__( self ):
|
||||||
|
self.completer = indexer.IdentifierCompleter()
|
||||||
|
self.completer.EnableThreading()
|
||||||
|
self.pattern = re.compile( r"[_a-zA-Z]\w*" )
|
||||||
|
|
||||||
|
|
||||||
|
def CandidatesForQueryAsync( self, query ):
|
||||||
|
filetype = vim.eval( "&filetype" )
|
||||||
|
self.future = self.completer.CandidatesForQueryAndTypeAsync(
|
||||||
|
SanitizeQuery( query ),
|
||||||
|
filetype )
|
||||||
|
|
||||||
|
|
||||||
def AddIdentifier( self, identifier ):
|
def AddIdentifier( self, identifier ):
|
||||||
filetype = vim.eval( "&filetype" )
|
filetype = vim.eval( "&filetype" )
|
||||||
filepath = vim.eval( "expand('%:p')" )
|
filepath = vim.eval( "expand('%:p')" )
|
||||||
@ -88,7 +89,7 @@ class IdentifierCompleter( object ):
|
|||||||
filepath,
|
filepath,
|
||||||
True )
|
True )
|
||||||
|
|
||||||
class ClangCompleter( object ):
|
class ClangCompleter( Completer ):
|
||||||
def __init__( self ):
|
def __init__( self ):
|
||||||
self.completer = indexer.ClangCompleter()
|
self.completer = indexer.ClangCompleter()
|
||||||
|
|
||||||
@ -142,6 +143,7 @@ def CurrentColumn():
|
|||||||
# vim's columns are 1-based while vim.current.line columns are 0-based
|
# vim's columns are 1-based while vim.current.line columns are 0-based
|
||||||
# ... but vim.current.window.cursor (which returns a (line, column) tuple)
|
# ... but vim.current.window.cursor (which returns a (line, column) tuple)
|
||||||
# columns are 0-based, while the line from that same tuple is 1-based.
|
# columns are 0-based, while the line from that same tuple is 1-based.
|
||||||
|
# vim.buffers buffer objects OTOH have 0-based lines and columns.
|
||||||
# Pigs have wings and I'm a loopy purple duck. Everything makes sense now.
|
# Pigs have wings and I'm a loopy purple duck. Everything makes sense now.
|
||||||
return vim.current.window.cursor[ 1 ]
|
return vim.current.window.cursor[ 1 ]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user