diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-17 00:40:40 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-17 00:40:40 +0000 |
commit | 727d93ef49e18147149354fadd10e86b13bc4ab0 (patch) | |
tree | 766ea8102f5eed89cb508c795bd8de7e0dadaeff /lib/Frontend/ASTUnit.cpp | |
parent | 649a33a8bb711ae88c97846e80a7cb7eb1a20ab4 (diff) |
When the # of top-level declarations changes after reparsing a
translation unit, refresh code-completion results because they've
probably changed. However, enforce a cooldown period between
refreshes, to avoid thrashing.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111218 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | lib/Frontend/ASTUnit.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index c66f08df3d..428647f03f 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -53,7 +53,9 @@ ASTUnit::ASTUnit(bool _MainFileIsAST) : CaptureDiagnostics(false), MainFileIsAST(_MainFileIsAST), CompleteTranslationUnit(true), ConcurrencyCheckValue(CheckUnlocked), PreambleRebuildCounter(0), SavedMainFileBuffer(0), - ShouldCacheCodeCompletionResults(false) { + ShouldCacheCodeCompletionResults(false), + NumTopLevelDeclsAtLastCompletionCache(0), + CacheCodeCompletionCoolDown(0) { } ASTUnit::~ASTUnit() { @@ -285,6 +287,10 @@ void ASTUnit::CacheCodeCompletionResults() { if (CachingTimer) CachingTimer->stopTimer(); + + // Make a note of the state when we performed this caching. + NumTopLevelDeclsAtLastCompletionCache = top_level_size(); + CacheCodeCompletionCoolDown = 15; } void ASTUnit::ClearCachedCompletionResults() { @@ -1411,6 +1417,14 @@ bool ASTUnit::Reparse(RemappedFile *RemappedFiles, unsigned NumRemappedFiles) { bool Result = Parse(OverrideMainBuffer); if (ReparsingTimer) ReparsingTimer->stopTimer(); + + if (ShouldCacheCodeCompletionResults) { + if (CacheCodeCompletionCoolDown > 0) + --CacheCodeCompletionCoolDown; + else if (top_level_size() != NumTopLevelDeclsAtLastCompletionCache) + CacheCodeCompletionResults(); + } + return Result; } |