From 9d34fad24f91972357db5c03814d4e92ff8c8b3a Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 13 Aug 2013 14:03:57 -0700 Subject: [PATCH] Now parsing file on every normal mode cursor move This is still fast & efficient because if we detect that the buffer hasn't been changed (by examining b:changedtick), the parse doesn't proceed. In effect, we now make sure we parse the file after every change to the buffer as soon as that change happens. This means that compilation error feedback will now be much, MUCH quicker. --- autoload/youcompleteme.vim | 1 + python/ycm/completers/cpp/clang_completer.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 3a5b28c3..51f6e1d1 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -327,6 +327,7 @@ function! s:OnCursorMovedNormalMode() endif call s:UpdateDiagnosticNotifications() + call s:OnFileReadyToParse() endfunction diff --git a/python/ycm/completers/cpp/clang_completer.py b/python/ycm/completers/cpp/clang_completer.py index 6c38a3ba..dfbb1ab9 100644 --- a/python/ycm/completers/cpp/clang_completer.py +++ b/python/ycm/completers/cpp/clang_completer.py @@ -42,6 +42,12 @@ class ClangCompleter( Completer ): self.flags = Flags() self.diagnostic_store = None + # We set this flag when a compilation request comes in while one is already + # in progress. We use this to trigger the pending request after the previous + # one completes (from GetDiagnosticsForCurrentFile because that's the only + # method that knows when the compilation has finished). + self.extra_parse_desired = False + def SupportedFiletypes( self ): return CLANG_FILETYPES @@ -220,6 +226,7 @@ class ClangCompleter( Completer ): return if self.completer.UpdatingTranslationUnit( filename ): + self.extra_parse_desired = True return flags = self.flags.FlagsForFile( filename ) @@ -232,6 +239,8 @@ class ClangCompleter( Completer ): self.GetUnsavedFilesVector(), flags ) + self.extra_parse_desired = False + def OnBufferUnload( self, deleted_buffer_file ): self.completer.DeleteCachesForFileAsync( deleted_buffer_file ) @@ -255,6 +264,10 @@ class ClangCompleter( Completer ): self.last_prepared_diagnostics = [ DiagnosticToDict( x ) for x in diagnostics[ : MAX_DIAGNOSTICS_TO_DISPLAY ] ] self.parse_future = None + + if self.extra_parse_desired: + self.OnFileReadyToParse() + return self.last_prepared_diagnostics