Browse Source

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.
Strahinja Val Markovic 11 years ago
parent
commit
9d34fad24f
2 changed files with 14 additions and 0 deletions
  1. 1 0
      autoload/youcompleteme.vim
  2. 13 0
      python/ycm/completers/cpp/clang_completer.py

+ 1 - 0
autoload/youcompleteme.vim

@@ -327,6 +327,7 @@ function! s:OnCursorMovedNormalMode()
   endif
 
   call s:UpdateDiagnosticNotifications()
+  call s:OnFileReadyToParse()
 endfunction
 
 

+ 13 - 0
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