Force filename completer on #include

This commit is contained in:
Strahinja Val Markovic 2013-04-24 19:59:14 -07:00
parent 7500a94cda
commit 3ae9764451
4 changed files with 20 additions and 6 deletions

View File

@ -89,7 +89,7 @@ let g:ycm_add_preview_to_completeopt =
\ get( g:, 'ycm_add_preview_to_completeopt', 0 )
let g:ycm_complete_in_comments_and_strings =
\ get( g:, 'ycm_complete_in_comments_and_strings', 0 )
\ get( g:, 'ycm_complete_in_comments_and_strings', 1 )
let g:ycm_collect_identifiers_from_comments_and_strings =
\ get( g:, 'ycm_collect_identifiers_from_comments_and_strings', 0 )

View File

@ -331,3 +331,8 @@ def ClangAvailableForBuffer( buffer_object ):
filetypes = vimsupport.FiletypesForBuffer( buffer_object )
return any( [ filetype in CLANG_FILETYPES for filetype in filetypes ] )
def InCFamilyFile():
return any( [ filetype in CLANG_FILETYPES for filetype in
vimsupport.CurrentFiletypes() ] )

View File

@ -17,6 +17,7 @@
# along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
from completers.threaded_completer import ThreadedCompleter
from completers.cpp.clang_completer import InCFamilyFile
import vim
import vimsupport
import os
@ -30,10 +31,10 @@ class FilenameCompleter( ThreadedCompleter ):
General completer that provides filename and filepath completions.
"""
def __init__(self):
def __init__( self ):
super( FilenameCompleter, self ).__init__()
self._path_regex = re.compile("""
self._path_regex = re.compile( """
# 1 or more 'D:/'-like token or '/' or '~' or './' or '../'
(?:[A-z]+:/|[/~]|\./|\.+/)+
@ -47,9 +48,17 @@ class FilenameCompleter( ThreadedCompleter ):
\\.)*$
""", re.X )
self._include_regex = re.compile( '^\s*#(?:include|import)\s*(?:"|<)$' )
def AtIncludeStatmentStart( self, start_column ):
return ( InCFamilyFile() and
self._include_regex.match( vim.current.line[ :start_column ] ) )
def ShouldUseNowInner( self, start_column ):
return vim.current.line[ start_column - 1 ] == '/'
return ( vim.current.line[ start_column - 1 ] == '/' or
self.AtIncludeStatmentStart( start_column ) )
def SupportedFiletypes( self ):

View File

@ -59,8 +59,8 @@ class YouCompleteMe( object ):
def GetFiletypeCompleter( self ):
filetypes = vimsupport.CurrentFiletypes()
completers = [self.GetFiletypeCompleterForFiletype( filetype )
for filetype in filetypes ]
completers = [ self.GetFiletypeCompleterForFiletype( filetype )
for filetype in filetypes ]
if not completers:
return None