From 11e42b49f07d99e31715ce7488beb3b7fdd588c1 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Mon, 30 Jul 2012 19:42:41 -0700 Subject: [PATCH] Smarter updating of clang diagnostics display --- autoload/youcompleteme.vim | 9 +++++---- cpp/ycm/ClangCompleter.cpp | 9 +++++---- cpp/ycm/indexer.cpp | 4 ++-- python/ycm.py | 18 ++++++++++++++---- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 3551ea32..b3112293 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -41,7 +41,7 @@ function! youcompleteme#Enable() augroup youcompleteme autocmd! autocmd CursorMovedI * call s:OnCursorMovedInsertMode() - " autocmd CursorMoved * call s:OnCursorMovedNormalMode() + 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 @@ -134,9 +134,9 @@ function! s:OnCursorMovedInsertMode() endfunction -" function! s:OnCursorMovedNormalMode() -" call s:UpdateDiagnosticNotifications() -" endfunction +function! s:OnCursorMovedNormalMode() + call s:UpdateDiagnosticNotifications() +endfunction function! s:OnInsertLeave() @@ -147,6 +147,7 @@ endfunction function! s:UpdateDiagnosticNotifications() if get( g:, 'loaded_syntastic_plugin', 0 ) && s:ClangEnabledForCurrentFile() + \ && pyeval( 'clangcomp.DiagnosticsForCurrentFileReady()' ) SyntasticCheck endif endfunction diff --git a/cpp/ycm/ClangCompleter.cpp b/cpp/ycm/ClangCompleter.cpp index 0a61fcc1..25db2330 100644 --- a/cpp/ycm/ClangCompleter.cpp +++ b/cpp/ycm/ClangCompleter.cpp @@ -413,10 +413,11 @@ void ClangCompleter::UpdateTranslationUnitAsync( // Only ever set the task when it's NULL; if it's not, that means that the // clang thread is working on it - if ( !file_parse_task_ ) { - file_parse_task_ = make_shared< packaged_task< void > >( functor ); - file_parse_task_condition_variable_.notify_all(); - } + if ( file_parse_task_ ) + return; + + file_parse_task_ = make_shared< packaged_task< void > >( functor ); + file_parse_task_condition_variable_.notify_all(); } diff --git a/cpp/ycm/indexer.cpp b/cpp/ycm/indexer.cpp index 79c6c0e1..75fe02de 100644 --- a/cpp/ycm/indexer.cpp +++ b/cpp/ycm/indexer.cpp @@ -58,11 +58,11 @@ BOOST_PYTHON_MODULE(indexer) class_< std::vector< Diagnostic > >( "DiagnosticVec" ) .def( vector_indexing_suite< std::vector< Diagnostic > >() ); - class_< Future< AsyncResults > >( "Future" ) + class_< Future< AsyncResults > >( "FutureResults" ) .def( "ResultsReady", &Future< AsyncResults >::ResultsReady ) .def( "GetResults", &Future< AsyncResults >::GetResults ); - class_< Future< AsyncCompletions > >( "Future" ) + class_< Future< AsyncCompletions > >( "FutureCompletions" ) .def( "ResultsReady", &Future< AsyncCompletions >::ResultsReady ) .def( "GetResults", &Future< AsyncCompletions >::GetResults ); diff --git a/python/ycm.py b/python/ycm.py index b8cb9421..7de65946 100644 --- a/python/ycm.py +++ b/python/ycm.py @@ -118,6 +118,8 @@ class ClangCompleter( Completer ): self.completer.EnableThreading() self.contents_holder = [] self.filename_holder = [] + self.last_diagnostics = [] + self.possibly_new_diagnostics = False def GetUnsavedFilesVector( self ): @@ -179,15 +181,23 @@ class ClangCompleter( Completer ): def OnFileReadyToParse( self ): + self.possibly_new_diagnostics = True self.completer.UpdateTranslationUnitAsync( vim.current.buffer.name, self.GetUnsavedFilesVector() ) + def DiagnosticsForCurrentFileReady( self ): + return ( self.possibly_new_diagnostics and not + self.completer.UpdatingTranslationUnit() ) + + def GetDiagnosticsForCurrentFile( self ): - if self.completer.UpdatingTranslationUnit(): - return [] - return [ DiagnosticToDict( x ) for x in - self.completer.DiagnosticsForFile( vim.current.buffer.name ) ] + if self.DiagnosticsForCurrentFileReady(): + self.last_diagnostics = [ DiagnosticToDict( x ) for x in + self.completer.DiagnosticsForFile( + vim.current.buffer.name ) ] + self.possibly_new_diagnostics = False + return self.last_diagnostics