diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 8af91e75..2284a578 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -37,6 +37,20 @@ function! youcompleteme#Enable() return endif + py import sys + py import vim + exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )' + py import ycm + + if !pyeval( 'ycm.CompatibleWithYcmCore()') + echohl WarningMsg | + \ echomsg "YouCompleteMe unavailable, ycm_core too old, PLEASE RECOMPILE" | + \ echohl None + return + endif + + py ycm_state = ycm.YouCompleteMe() + augroup youcompleteme autocmd! autocmd CursorMovedI * call s:OnCursorMovedInsertMode() @@ -60,12 +74,6 @@ function! youcompleteme#Enable() set ut=2000 endif - py import sys - py import vim - exe 'python sys.path.insert( 0, "' . s:script_folder_path . '/../python" )' - py import ycm - py ycm_state = ycm.YouCompleteMe() - " Calling this once solves the problem of BufRead/BufEnter not triggering for " the first loaded file. This should be the last command executed in this " function! @@ -477,7 +485,7 @@ function! s:ForceCompile() if !pyeval( 'ycm_state.NativeFiletypeCompletionUsable()' ) echom "Native filetype completion not supported for current file, " \ . "cannot force recompilation." - return + return 0 endif echom "Forcing compilation, this will block Vim until done." diff --git a/cpp/ycm/ycm_core.cpp b/cpp/ycm/ycm_core.cpp index fc23837e..51e64825 100644 --- a/cpp/ycm/ycm_core.cpp +++ b/cpp/ycm/ycm_core.cpp @@ -41,6 +41,13 @@ bool HasClangSupport() #endif // USE_CLANG_COMPLETER } +int YcmCoreVersion() +{ + // We increment this every time when we want to force users to recompile + // ycm_core. + return 1; +} + BOOST_PYTHON_MODULE(ycm_core) { @@ -49,6 +56,7 @@ BOOST_PYTHON_MODULE(ycm_core) def( "HasClangSupport", HasClangSupport ); def( "FilterAndSortCandidates", FilterAndSortCandidates ); + def( "YcmCoreVersion", YcmCoreVersion ); class_< IdentifierCompleter, boost::noncopyable >( "IdentifierCompleter" ) .def( "EnableThreading", &IdentifierCompleter::EnableThreading ) diff --git a/python/ycm.py b/python/ycm.py index 337793d5..09219049 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -33,6 +33,7 @@ except ImportError, e: 'the docs. Full error: {1}'.format( os.path.dirname( os.path.abspath( __file__ ) ), str( e ) ) ) + from completers.all.identifier_completer import IdentifierCompleter from completers.all.omni_completer import OmniCompleter @@ -237,3 +238,13 @@ def CurrentIdentifierFinished(): return line[ : current_column ].isspace() +COMPATIBLE_WITH_CORE_VERSION = 1 + +def CompatibleWithYcmCore(): + try: + current_core_version = ycm_core.YcmCoreVersion() + except AttributeError: + return False + + return current_core_version == COMPATIBLE_WITH_CORE_VERSION +