From 5ac3d40691360ccdbae922145a94d98b557f79e4 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sun, 13 Jan 2013 20:56:10 -0800 Subject: [PATCH] No error when no clang support and cpp file opened Previously, when the user opened a cpp/c/objc/objcpp file and clang support was not compiled in, there would be an error message printed in vim. --- autoload/youcompleteme.vim | 2 +- cpp/ycm/CMakeLists.txt | 7 +++++++ cpp/ycm/ycm_core.cpp | 12 ++++++++++++ python/completers/all/hook.py | 4 +--- python/completers/c/hook.py | 6 +++++- python/completers/cpp/hook.py | 6 +++++- python/completers/objc/hook.py | 7 +++++-- python/completers/objcpp/hook.py | 6 +++++- python/ycm.py | 10 ++++++---- 9 files changed, 47 insertions(+), 13 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 5871ba69..49223614 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -295,7 +295,7 @@ function! s:InvokeCompletion() " This is tricky. First, having 'refresh' set to 'always' in the dictionary " that our completion function returns makes sure that our completion function - " is called on every keystroke. Secondly, when the sequence of characters the + " is called on every keystroke. Second, when the sequence of characters the " user typed produces no results in our search an infinite loop can occur. The " problem is that our feedkeys call triggers the OnCursorMovedI event which we " are tied to. We prevent this infinite loop from starting by making sure that diff --git a/cpp/ycm/CMakeLists.txt b/cpp/ycm/CMakeLists.txt index 754e0a17..76c4a1cc 100644 --- a/cpp/ycm/CMakeLists.txt +++ b/cpp/ycm/CMakeLists.txt @@ -46,6 +46,13 @@ if ( USE_CLANG_COMPLETER AND "You HAVE to pick one option. See the docs for more information.") endif() +if ( USE_CLANG_COMPLETER ) + message( "Using libclang to provide semantic completion for C/C++/ObjC" ) +else() + message( "NOT using libclang, no semantic completion for C/C++/ObjC will be " + "available" ) +endif() + if ( PATH_TO_LLVM_ROOT ) set( CLANG_INCLUDES_DIR "${PATH_TO_LLVM_ROOT}/include" ) else() diff --git a/cpp/ycm/ycm_core.cpp b/cpp/ycm/ycm_core.cpp index 1f6aa306..dfc02f49 100644 --- a/cpp/ycm/ycm_core.cpp +++ b/cpp/ycm/ycm_core.cpp @@ -29,11 +29,23 @@ #include #include +bool HasClangSupport() +{ +#ifdef USE_CLANG_COMPLETER + return true; +#else + return false; +#endif // USE_CLANG_COMPLETER +} + + BOOST_PYTHON_MODULE(ycm_core) { using namespace boost::python; using namespace YouCompleteMe; + def( "HasClangSupport", HasClangSupport ); + class_< IdentifierCompleter, boost::noncopyable >( "IdentifierCompleter" ) .def( "EnableThreading", &IdentifierCompleter::EnableThreading ) .def( "AddCandidatesToDatabase", diff --git a/python/completers/all/hook.py b/python/completers/all/hook.py index 529c9215..03206d07 100644 --- a/python/completers/all/hook.py +++ b/python/completers/all/hook.py @@ -17,8 +17,6 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . -from identifier_completer import IdentifierCompleter - def GetCompleter(): - return IdentifierCompleter() + return None diff --git a/python/completers/c/hook.py b/python/completers/c/hook.py index 3307a130..c60f3956 100644 --- a/python/completers/c/hook.py +++ b/python/completers/c/hook.py @@ -17,8 +17,12 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +import ycm_core from completers.cpp.clang_completer import ClangCompleter def GetCompleter(): - return ClangCompleter() + if ycm_core.HasClangSupport(): + return ClangCompleter() + else: + return None diff --git a/python/completers/cpp/hook.py b/python/completers/cpp/hook.py index 77938dfd..32019761 100644 --- a/python/completers/cpp/hook.py +++ b/python/completers/cpp/hook.py @@ -17,8 +17,12 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +import ycm_core from clang_completer import ClangCompleter def GetCompleter(): - return ClangCompleter() + if ycm_core.HasClangSupport(): + return ClangCompleter() + else: + return None diff --git a/python/completers/objc/hook.py b/python/completers/objc/hook.py index 3307a130..a6a4c1a7 100644 --- a/python/completers/objc/hook.py +++ b/python/completers/objc/hook.py @@ -17,8 +17,11 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +import ycm_core from completers.cpp.clang_completer import ClangCompleter def GetCompleter(): - return ClangCompleter() - + if ycm_core.HasClangSupport(): + return ClangCompleter() + else: + return None diff --git a/python/completers/objcpp/hook.py b/python/completers/objcpp/hook.py index 3307a130..c60f3956 100644 --- a/python/completers/objcpp/hook.py +++ b/python/completers/objcpp/hook.py @@ -17,8 +17,12 @@ # You should have received a copy of the GNU General Public License # along with YouCompleteMe. If not, see . +import ycm_core from completers.cpp.clang_completer import ClangCompleter def GetCompleter(): - return ClangCompleter() + if ycm_core.HasClangSupport(): + return ClangCompleter() + else: + return None diff --git a/python/ycm.py b/python/ycm.py index 065dd4b2..8147a7d8 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -49,6 +49,7 @@ class YouCompleteMe( object ): module_path = _PathToFiletypeCompleterPluginLoader( filetype ) completer = None + supported_filetypes = [ filetype ] if os.path.exists( module_path ): sys.path.append( os.path.dirname( module_path ) ) @@ -56,10 +57,11 @@ class YouCompleteMe( object ): del sys.path[ -1 ] completer = module.GetCompleter() - for supported_filetype in completer.SupportedFiletypes(): - self.filetype_completers[ supported_filetype ] = completer - else: - self.filetype_completers[ filetype ] = None + if completer: + supported_filetypes.extend( completer.SupportedFiletypes() ) + + for supported_filetype in supported_filetypes: + self.filetype_completers[ supported_filetype ] = completer return completer