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 | 2c8bd47a6a7806004dc025fcbd3c2a6422129fe4 (patch) | |
tree | 04ec2a6e427655bd0e2f3f182dc1b47c08c11b13 /clang/lib/Frontend/ASTUnit.cpp | |
parent | a66d1694f41cc4c7ccb5ce607fcf7949fc3f6384 (diff) | |
download | bcm5719-llvm-2c8bd47a6a7806004dc025fcbd3c2a6422129fe4.tar.gz bcm5719-llvm-2c8bd47a6a7806004dc025fcbd3c2a6422129fe4.zip |
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.
llvm-svn: 111218
Diffstat (limited to 'clang/lib/Frontend/ASTUnit.cpp')
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index c66f08df3d4..428647f03f4 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/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; } |