From 8452914046963c47bf61aa0b5866f260a68749e1 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Wed, 30 Jan 2013 14:46:58 -0800 Subject: [PATCH] Adding a command to force recompilation and diags --- README.md | 36 +++++++++++++++++++++--- autoload/youcompleteme.vim | 24 ++++++++++++++++ python/completers/cpp/clang_completer.py | 3 ++ 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d0d8d97d..50676eeb 100644 --- a/README.md +++ b/README.md @@ -264,10 +264,38 @@ project. That should be enough for 99% of projects. Yes, [Clang's `CompilationDatabase` system][compdb] is also supported. Again, see the above linked example file. -TODO: compile flags, include paths, ycm_extra_conf, CompilationDatabase -support, how the search system works (subsequence match), extending the semantic -engine for other langs, using ListToggle, when does YCM recompile the file, when -does YCM update the diagnostics +### Syntastic integration + +YCM has explicit support for [Syntastic][] (and vice-versa) if you compiled YCM +with Clang support; this means that any diagnostics (errors or warnings) that +Clang encounters while compiling your file will be fed back to Syntastic for +display. + +YCM will recompile your file in the background `updatetime` (see `:h updatetime` +in Vim) milliseconds after you stop typing (to be specific, on `CursorHold` and +`CursorHoldI` Vim events). YCM will change your `updatetime` value to be `2000` +milliseconds (there's an option to tell it not to do this if you wish). + +The new diagnostics (if any) will be fed back to Syntastic the next time you +press any key on the keyboard. So if you stop typing and just wait for the new +diagnostics to come in, that _will not work_. You need to press some key for the +GUI to update. + +Having to press a key to get the updates is unfortunate, but cannot be changed +due to the way Vim internals operate; there is no way that a background task can +update Vim's GUI after it has finished running. You _have to_ press a key. This +will make YCM check for any pending diagnostics updates. + +You _can_ force a full, blocking compilation cycle with the +`:YcmForceCompileAndDiagnostics` command (you may want to map that command to a +key; try putting `nnoremap :YcmForceCompileAndDiagnostics` in your +vimrc). Calling this command will force YCM to immediately recompile your file +and display any new diagnostics it encounters. Do note that recompilation with +this command may take a while and during this time the Vim GUI _will_ be +blocked. + +TODO: how the search system works (subsequence match), extending the semantic +engine for other langs, using ListToggle Options ------- diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index e821668d..45f28140 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -418,6 +418,30 @@ endfunction command! YcmDebugInfo call s:DebugInfo() +function! s:ForceCompileAndDiagnostics() + if !pyeval( 'ycm_state.FiletypeCompletionEnabledForCurrentFile()' ) + echom "Filetype completion not supported for current file, " + \ . "cannot force recompilation." + endif + + echom "Forcing compilation, this will block Vim until done." + py ycm_state.OnFileReadyToParse() + while 1 + let diagnostics_ready = pyeval( + \ 'ycm_state.DiagnosticsForCurrentFileReady()' ) + if diagnostics_ready + break + endif + sleep 100m + endwhile + + call s:UpdateDiagnosticNotifications() + echom "Diagnostics refreshed." +endfunction + +command! YcmForceCompileAndDiagnostics call s:ForceCompileAndDiagnostics() + + " This is basic vim plugin boilerplate let &cpo = s:save_cpo unlet s:save_cpo diff --git a/python/completers/cpp/clang_completer.py b/python/completers/cpp/clang_completer.py index 4bdc50a2..7ffbd971 100644 --- a/python/completers/cpp/clang_completer.py +++ b/python/completers/cpp/clang_completer.py @@ -124,6 +124,9 @@ class ClangCompleter( Completer ): return filename = vim.current.buffer.name + if self.completer.UpdatingTranslationUnit( filename ): + return + flags = self.flags.FlagsForFile( filename ) if not flags: self.parse_future = None