From 333b71f8d54443a60d8e1287051a70b4d38a8bcd Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sun, 29 Jul 2012 22:08:02 -0700 Subject: [PATCH] Triggering syntastic error display more often --- autoload/youcompleteme.vim | 23 ++++++++++++++++++++--- cpp/ycm/ClangCompleter.cpp | 2 ++ cpp/ycm/indexer.cpp | 1 + python/ycm.py | 7 ++++--- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index ccb8d151..457d7921 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -25,7 +25,6 @@ let s:searched_and_no_results_found = 0 let s:should_use_clang = 0 let s:completion_start_column = 0 let s:omnifunc_mode = 0 -let g:ycm_min_num_of_chars_for_completion = 2 function! youcompleteme#Enable() " If the user set the current filetype as a filetype that YCM should ignore, @@ -36,7 +35,8 @@ function! youcompleteme#Enable() augroup youcompleteme autocmd! - autocmd CursorMovedI * call s:OnMovedI() + autocmd CursorMovedI * call s:OnCursorMovedInsertMode() + " autocmd CursorMoved * call s:OnCursorMovedNormalMode() " Note that these events will NOT trigger for the file vim is started with; " so if you do "vim foo.cc", these events will not trigger when that buffer " is read. This is because youcompleteme#Enable() is called on VimEnter and @@ -94,6 +94,7 @@ endfunction function! s:OnCursorHold() call s:ParseFile() + call s:UpdateDiagnosticNotifications() endfunction @@ -122,14 +123,27 @@ function! s:SetCompleteFunc() endfunction -function! s:OnMovedI() +function! s:OnCursorMovedInsertMode() call s:IdentifierFinishedOperations() call s:InvokeCompletion() endfunction +" function! s:OnCursorMovedNormalMode() +" call s:UpdateDiagnosticNotifications() +" endfunction + + function! s:OnInsertLeave() let s:omnifunc_mode = 0 + call s:UpdateDiagnosticNotifications() +endfunction + + +function! s:UpdateDiagnosticNotifications() + if g:loaded_syntastic_plugin && s:ClangEnabledForCurrentFile() + SyntasticCheck + endif endfunction @@ -275,6 +289,9 @@ function! youcompleteme#ClangOmniComplete( findstart, base ) endfunction +" This is what Syntastic calls indirectly when it decides an auto-check is +" required (currently that's on buffer save) OR when the SyntasticCheck command +" is invoked function! youcompleteme#CurrentFileDiagnostics() if s:ClangEnabledForCurrentFile() return pyeval( 'clangcomp.GetDiagnosticsForCurrentFile()' ) diff --git a/cpp/ycm/ClangCompleter.cpp b/cpp/ycm/ClangCompleter.cpp index afc5112d..0a61fcc1 100644 --- a/cpp/ycm/ClangCompleter.cpp +++ b/cpp/ycm/ClangCompleter.cpp @@ -340,6 +340,8 @@ void ClangCompleter::SetFileCompileFlags( std::vector< Diagnostic > ClangCompleter::DiagnosticsForFile( const std::string &filename ) { + // TODO: make sure that accessing the translation unit is thread safe; what if + // a bg thread is parsing the TU when we try to access the diagnostics? CXTranslationUnit unit = FindWithDefault( filename_to_translation_unit_, filename, NULL ); diff --git a/cpp/ycm/indexer.cpp b/cpp/ycm/indexer.cpp index ab969ed2..79c6c0e1 100644 --- a/cpp/ycm/indexer.cpp +++ b/cpp/ycm/indexer.cpp @@ -99,6 +99,7 @@ BOOST_PYTHON_MODULE(indexer) .def( "SetFileCompileFlags", &ClangCompleter::SetFileCompileFlags ) .def( "DiagnosticsForFile", &ClangCompleter::DiagnosticsForFile ) .def( "UpdatingTranslationUnit", &ClangCompleter::UpdatingTranslationUnit ) + .def( "UpdateTranslationUnit", &ClangCompleter::UpdateTranslationUnit ) .def( "UpdateTranslationUnitAsync", &ClangCompleter::UpdateTranslationUnitAsync ) .def( "CandidatesForQueryAndLocationInFileAsync", diff --git a/python/ycm.py b/python/ycm.py index ef952306..b8cb9421 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -179,12 +179,13 @@ class ClangCompleter( Completer ): def OnFileReadyToParse( self ): - self.future = self.completer.UpdateTranslationUnitAsync( - vim.current.buffer.name, - self.GetUnsavedFilesVector() ) + self.completer.UpdateTranslationUnitAsync( vim.current.buffer.name, + self.GetUnsavedFilesVector() ) def GetDiagnosticsForCurrentFile( self ): + if self.completer.UpdatingTranslationUnit(): + return [] return [ DiagnosticToDict( x ) for x in self.completer.DiagnosticsForFile( vim.current.buffer.name ) ]