Browse Source

Adding the ClearCompilationFlagCache subcommand

With this command the user can clean the in-memory cache of the compilation
flags that the clang completer uses.
Strahinja Val Markovic 12 years ago
parent
commit
38faa0e94e
3 changed files with 25 additions and 3 deletions
  1. 10 0
      README.md
  2. 11 3
      python/ycm/completers/cpp/clang_completer.py
  3. 4 0
      python/ycm/completers/cpp/flags.py

+ 10 - 0
README.md

@@ -538,6 +538,16 @@ symbol's declaration.
 
 Supported in filetypes: `c, cpp, objc, objcpp, python`
 
+### The `ClearCompilationFlagCache` subcommand
+
+YCM caches the flags it gets from the `FlagsForFile` function if you return them
+with the `do_cache` parameter set to `True`. The cache is in memory and is never
+invalidated (unless you restart Vim of course).
+
+This command clears that cache entirely. YCM will then re-query your
+`FlagsForFile` function as needed in the future.
+
+Supported in filetypes: `c, cpp, objc, objcpp`
 
 Options
 -------

+ 11 - 3
python/ycm/completers/cpp/clang_completer.py

@@ -125,9 +125,10 @@ class ClangCompleter( Completer ):
 
 
   def DefinedSubcommands( self ):
-    return [ "GoToDefinition",
-             "GoToDeclaration",
-             "GoToDefinitionElseDeclaration" ]
+    return [ 'GoToDefinition',
+             'GoToDeclaration',
+             'GoToDefinitionElseDeclaration',
+             'ClearCompilationFlagCache']
 
 
   def OnUserCommand( self, arguments ):
@@ -142,6 +143,8 @@ class ClangCompleter( Completer ):
       self._GoToDeclaration()
     elif command == 'GoToDefinitionElseDeclaration':
       self._GoToDefinitionElseDeclaration()
+    elif command == 'ClearCompilationFlagCache':
+      self._ClearCompilationFlagCache()
 
 
   def _LocationForGoTo( self, goto_function ):
@@ -202,6 +205,11 @@ class ClangCompleter( Completer ):
                                location.column_number_ )
 
 
+  def _ClearCompilationFlagCache( self ):
+    self.flags.Clear()
+
+
+
   def OnFileReadyToParse( self ):
     if vimsupport.NumLinesInBuffer( vim.current.buffer ) < 5:
       self.parse_future = None

+ 4 - 0
python/ycm/completers/cpp/flags.py

@@ -90,6 +90,10 @@ class Flags( object ):
     return [ x for x in include_paths if x ]
 
 
+  def Clear( self ):
+    self.flags_for_file.clear()
+
+
 def _PrepareFlagsForClang( flags, filename ):
   flags = _RemoveUnusedFlags( flags, filename )
   flags = _SanitizeFlags( flags )