From 3ae97644518a7b26ab6ac30860507d1722fa40d3 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Wed, 24 Apr 2013 19:59:14 -0700 Subject: [PATCH] Force filename completer on #include --- plugin/youcompleteme.vim | 2 +- python/completers/cpp/clang_completer.py | 5 +++++ python/completers/general/filename_completer.py | 15 ++++++++++++--- python/ycm.py | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/plugin/youcompleteme.vim b/plugin/youcompleteme.vim index 196f1271..206933f5 100644 --- a/plugin/youcompleteme.vim +++ b/plugin/youcompleteme.vim @@ -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 ) diff --git a/python/completers/cpp/clang_completer.py b/python/completers/cpp/clang_completer.py index 11f3db51..f2571e74 100644 --- a/python/completers/cpp/clang_completer.py +++ b/python/completers/cpp/clang_completer.py @@ -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() ] ) + diff --git a/python/completers/general/filename_completer.py b/python/completers/general/filename_completer.py index f3b1a1c4..bb03965f 100644 --- a/python/completers/general/filename_completer.py +++ b/python/completers/general/filename_completer.py @@ -17,6 +17,7 @@ # along with YouCompleteMe. If not, see . 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 ): diff --git a/python/ycm.py b/python/ycm.py index 3dea4f16..b6075600 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -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