From 1acd3e84c7bea013204ef8c1a6905bde507fce37 Mon Sep 17 00:00:00 2001 From: Zeh Rizzatti Date: Sat, 2 Mar 2013 22:02:29 -0400 Subject: [PATCH 1/3] Support for multile filetypes in clang_completer clang_completer would check if the raw value of '&ft' was one of supported filetypes for the completer. Vim allows for multiple filetypes with a '.' separator. A file with ft=qt.cpp, for example, would not be supported by clang_completer even though it was a cpp file. This patch changes that behaviour. --- python/completers/cpp/clang_completer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/completers/cpp/clang_completer.py b/python/completers/cpp/clang_completer.py index 456f80e3..4fc93a1c 100644 --- a/python/completers/cpp/clang_completer.py +++ b/python/completers/cpp/clang_completer.py @@ -246,5 +246,9 @@ def DiagnosticsToDiagStructure( diagnostics ): def ClangAvailableForBuffer( buffer_object ): - filetype = vim.eval( 'getbufvar({0}, "&ft")'.format( buffer_object.number ) ) - return filetype in CLANG_FILETYPES + filetypes = vim.eval( 'getbufvar({0}, "&ft")'.format( buffer_object.number ) ) + supported_fts = [ft for ft in filetypes.split('.') if ft in CLANG_FILETYPES] + if supported_fts: + return True + else: + return False From ac1e04fc14cd136270b938cd8a8f13ead0bf572d Mon Sep 17 00:00:00 2001 From: Zeh Rizzatti Date: Sat, 2 Mar 2013 22:14:22 -0400 Subject: [PATCH 2/3] Check for a native completer with multiple filetypes GetFiletypeCompleter would always return a omnicompleter for the first filetype in case there was no native completer, and the lookup would stop. This changes that behaviour to get all possible completers and tries to find a native one among them. If no native completer is found, it returns the omnicompleter for the first filetypes, as it used to. --- python/ycm.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/python/ycm.py b/python/ycm.py index f39ee81a..e027a86c 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -60,11 +60,19 @@ class YouCompleteMe( object ): def GetFiletypeCompleter( self ): filetypes = vimsupport.CurrentFiletypes() - for filetype in filetypes: - completer = self.GetFiletypeCompleterForFiletype( filetype ) - if completer: + completers = [self.GetFiletypeCompleterForFiletype( filetype ) + for filetype in filetypes ] + + if not completers: + return None + + # Try to find a native completer first + for completer in completers: + if completer and completer is not self.omnicomp: return completer - return None + + # Return the omni completer for the first filetype + return completers[0] def GetFiletypeCompleterForFiletype( self, filetype ): From c6aefaef86d44472dc41dab8714790833c84601d Mon Sep 17 00:00:00 2001 From: Zeh Rizzatti Date: Sun, 3 Mar 2013 01:52:56 -0400 Subject: [PATCH 3/3] Select correct triggers for multiple filetypes The base class completer Inner chose the first filetype available and would use the triggers for it. The triggers are now chosen considering the first for the current buffer that is supported by the current completer. If there is no intersection, it fallsback to considering the first filetype for the buffer. --- python/completers/completer.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/python/completers/completer.py b/python/completers/completer.py index fbdcf67e..f96aed49 100644 --- a/python/completers/completer.py +++ b/python/completers/completer.py @@ -134,7 +134,7 @@ class Completer( object ): if not line_length or start_column - 1 >= line_length: return False - filetype = vimsupport.CurrentFiletypes()[ 0 ] + filetype = self._CurrentFiletype() triggers = self.triggers_for_filetype[ filetype ] for trigger in triggers: @@ -266,6 +266,17 @@ class Completer( object ): return False + def _CurrentFiletype( self ): + filetypes = vimsupport.CurrentFiletypes() + supported = self.SupportedFiletypes() + + for filetype in filetypes: + if filetype in supported: + return filetype + + return filetypes[0] + + @abc.abstractmethod def SupportedFiletypes( self ): pass