From c67658bbce3bc3d64ef0eee8282b04efad3ed6ea Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Thu, 31 Jan 2013 16:19:56 -0800 Subject: [PATCH] Supporting multiple filetypes set for current file Vim allows setting the filetype string to something like "cpp.c", which means that the file is both cpp and c (nonsense, but allowed). We need to support such filetype strings. --- python/vimsupport.py | 5 +++-- python/ycm.py | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/python/vimsupport.py b/python/vimsupport.py index f0120bb5..725f0c10 100644 --- a/python/vimsupport.py +++ b/python/vimsupport.py @@ -67,8 +67,9 @@ def EscapeForVim( text ): return text.replace( "'", "''" ) -def CurrentFiletype(): - return vim.eval( "&filetype" ) +def CurrentFiletypes(): + ft_string = vim.eval( "&filetype" ) + return ft_string.split( '.' ) def GetVariableValue( variable ): diff --git a/python/ycm.py b/python/ycm.py index b77319f1..a787fa51 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -51,7 +51,17 @@ class YouCompleteMe( object ): def GetFiletypeCompleterForCurrentFile( self ): - filetype = vimsupport.CurrentFiletype() + filetypes = vimsupport.CurrentFiletypes() + + for filetype in filetypes: + completer = self.GetFiletypeCompleterForFiletype( filetype ) + if completer: + return completer + + return None + + + def GetFiletypeCompleterForFiletype( self, filetype ): try: return self.filetype_completers[ filetype ] except KeyError: @@ -92,8 +102,11 @@ class YouCompleteMe( object ): def FiletypeCompletionEnabledForCurrentFile( self ): - return ( vimsupport.CurrentFiletype() not in - FILETYPE_SPECIFIC_COMPLETION_TO_DISABLE and + filetypes = vimsupport.CurrentFiletypes() + filetype_disabled = all([ x in FILETYPE_SPECIFIC_COMPLETION_TO_DISABLE + for x in filetypes ]) + + return ( not filetype_disabled and self.FiletypeCompletionAvailableForFile() )