summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r--src/plugins/cpptools/cppfindreferences.cpp21
-rw-r--r--src/plugins/cpptools/cppfindreferences.h7
-rw-r--r--src/plugins/cpptools/cppmodelmanager.cpp5
-rw-r--r--src/plugins/cpptools/cppmodelmanagerinterface.h2
-rw-r--r--src/plugins/cpptools/cppsnapshotupdater.cpp14
-rw-r--r--src/plugins/cpptools/cppsnapshotupdater.h2
-rw-r--r--src/plugins/cpptools/cpptoolseditorsupport.cpp32
-rw-r--r--src/plugins/cpptools/cpptoolseditorsupport.h9
8 files changed, 83 insertions, 9 deletions
diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp
index 2bd90a6059..a1e9625e85 100644
--- a/src/plugins/cpptools/cppfindreferences.cpp
+++ b/src/plugins/cpptools/cppfindreferences.cpp
@@ -247,8 +247,9 @@ public:
CppFindReferences::CppFindReferences(CppModelManagerInterface *modelManager)
: QObject(modelManager),
- _modelManager(modelManager)
+ m_modelManager(modelManager)
{
+ connect(modelManager, SIGNAL(globalSnapshotChanged()), this, SLOT(flushDependencyTable()));
}
CppFindReferences::~CppFindReferences()
@@ -365,7 +366,7 @@ void CppFindReferences::findAll_helper(Find::SearchResult *search, CPlusPlus::Sy
this, SLOT(openEditor(Find::SearchResultItem)));
Find::SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
- const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
+ const CppModelManagerInterface::WorkingCopy workingCopy = m_modelManager->workingCopy();
QFuture<Usage> result;
result = QtConcurrent::run(&find_helper, workingCopy, context, this, symbol);
createWatcher(result, search);
@@ -382,7 +383,7 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text,
{
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
if (!fileNames.isEmpty()) {
- _modelManager->updateSourceFiles(fileNames);
+ m_modelManager->updateSourceFiles(fileNames);
Find::SearchResultWindow::instance()->hide();
}
}
@@ -451,7 +452,7 @@ CPlusPlus::Symbol *CppFindReferences::findSymbol(const CppFindReferencesParamete
Document::Ptr newSymbolDocument = snapshot.document(symbolFile);
// document is not parsed and has no bindings yet, do it
- QByteArray source = getSource(newSymbolDocument->fileName(), _modelManager->workingCopy());
+ QByteArray source = getSource(newSymbolDocument->fileName(), m_modelManager->workingCopy());
Document::Ptr doc =
snapshot.preprocessedDocument(source, newSymbolDocument->fileName());
doc->check();
@@ -492,6 +493,7 @@ void CppFindReferences::searchFinished()
if (search)
search->finishSearch(watcher->isCanceled());
m_watchers.remove(watcher);
+ watcher->deleteLater();
}
void CppFindReferences::cancel()
@@ -651,8 +653,8 @@ void CppFindReferences::findMacroUses(const Macro &macro, const QString &replace
connect(search, SIGNAL(cancelled()), this, SLOT(cancel()));
connect(search, SIGNAL(paused(bool)), this, SLOT(setPaused(bool)));
- const Snapshot snapshot = _modelManager->snapshot();
- const CppModelManagerInterface::WorkingCopy workingCopy = _modelManager->workingCopy();
+ const Snapshot snapshot = m_modelManager->snapshot();
+ const CppModelManagerInterface::WorkingCopy workingCopy = m_modelManager->workingCopy();
// add the macro definition itself
{
@@ -691,6 +693,13 @@ DependencyTable CppFindReferences::updateDependencyTable(CPlusPlus::Snapshot sna
return newDeps;
}
+void CppFindReferences::flushDependencyTable()
+{
+ QMutexLocker locker(&m_depsLock);
+ Q_UNUSED(locker);
+ m_deps = DependencyTable();
+}
+
DependencyTable CppFindReferences::dependencyTable() const
{
QMutexLocker locker(&m_depsLock);
diff --git a/src/plugins/cpptools/cppfindreferences.h b/src/plugins/cpptools/cppfindreferences.h
index c902ed0a85..72e75c70c5 100644
--- a/src/plugins/cpptools/cppfindreferences.h
+++ b/src/plugins/cpptools/cppfindreferences.h
@@ -78,7 +78,10 @@ public:
CPlusPlus::DependencyTable updateDependencyTable(CPlusPlus::Snapshot snapshot);
-private Q_SLOTS:
+public slots:
+ void flushDependencyTable();
+
+private slots:
void displayResults(int first, int last);
void searchFinished();
void cancel();
@@ -101,7 +104,7 @@ private:
const CPlusPlus::Snapshot &snapshot, CPlusPlus::LookupContext *context);
private:
- QPointer<CppModelManagerInterface> _modelManager;
+ QPointer<CppModelManagerInterface> m_modelManager;
QMap<QFutureWatcher<CPlusPlus::Usage> *, QPointer<Find::SearchResult> > m_watchers;
mutable QMutex m_depsLock;
diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp
index fd4430320c..533b803808 100644
--- a/src/plugins/cpptools/cppmodelmanager.cpp
+++ b/src/plugins/cpptools/cppmodelmanager.cpp
@@ -234,6 +234,11 @@ CppModelManager::CppModelManager(QObject *parent)
, m_indexingSupporter(0)
, m_enableGC(true)
{
+ connect(this, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
+ this, SIGNAL(globalSnapshotChanged()));
+ connect(this, SIGNAL(aboutToRemoveFiles(QStringList)),
+ this, SIGNAL(globalSnapshotChanged()));
+
m_findReferences = new CppFindReferences(this);
m_indexerEnabled = qgetenv("QTCREATOR_NO_CODE_INDEXER").isNull();
diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h
index bb6787bd2f..49a9eea066 100644
--- a/src/plugins/cpptools/cppmodelmanagerinterface.h
+++ b/src/plugins/cpptools/cppmodelmanagerinterface.h
@@ -279,6 +279,8 @@ signals:
/// Other classes can use this to get notified when the \c ProjectExplorer has updated the parts.
void projectPartsUpdated(ProjectExplorer::Project *project);
+ void globalSnapshotChanged();
+
public slots:
// Documented in source file.
virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles,
diff --git a/src/plugins/cpptools/cppsnapshotupdater.cpp b/src/plugins/cpptools/cppsnapshotupdater.cpp
index 11cd3ff5b3..0a97a98fdf 100644
--- a/src/plugins/cpptools/cppsnapshotupdater.cpp
+++ b/src/plugins/cpptools/cppsnapshotupdater.cpp
@@ -41,6 +41,7 @@ SnapshotUpdater::SnapshotUpdater(const QString &fileInEditor)
, m_fileInEditor(fileInEditor)
, m_editorDefinesChangedSinceLastUpdate(false)
, m_usePrecompiledHeaders(false)
+ , m_forceSnapshotInvalidation(false)
{
}
@@ -62,6 +63,11 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
updateProjectPart();
+ if (m_forceSnapshotInvalidation) {
+ invalidateSnapshot = true;
+ m_forceSnapshotInvalidation = false;
+ }
+
if (m_projectPart) {
configFile += m_projectPart->defines;
includePaths = m_projectPart->includePaths;
@@ -186,6 +192,14 @@ void SnapshotUpdater::update(CppModelManager::WorkingCopy workingCopy)
}
}
+void SnapshotUpdater::releaseSnapshot()
+{
+ QMutexLocker locker(&m_mutex);
+ m_snapshot = Snapshot();
+ m_deps = DependencyTable();
+ m_forceSnapshotInvalidation = true;
+}
+
Document::Ptr SnapshotUpdater::document() const
{
QMutexLocker locker(&m_mutex);
diff --git a/src/plugins/cpptools/cppsnapshotupdater.h b/src/plugins/cpptools/cppsnapshotupdater.h
index 98564357a7..739cb57d5a 100644
--- a/src/plugins/cpptools/cppsnapshotupdater.h
+++ b/src/plugins/cpptools/cppsnapshotupdater.h
@@ -52,6 +52,7 @@ public:
{ return m_fileInEditor; }
void update(CppModelManagerInterface::WorkingCopy workingCopy);
+ void releaseSnapshot();
CPlusPlus::Document::Ptr document() const;
CPlusPlus::Snapshot snapshot() const;
@@ -81,6 +82,7 @@ private:
CPlusPlus::Snapshot m_snapshot;
CPlusPlus::DependencyTable m_deps;
bool m_usePrecompiledHeaders;
+ bool m_forceSnapshotInvalidation;
};
} // namespace CppTools
diff --git a/src/plugins/cpptools/cpptoolseditorsupport.cpp b/src/plugins/cpptools/cpptoolseditorsupport.cpp
index 631b1c1a44..e9ec1d23a0 100644
--- a/src/plugins/cpptools/cpptoolseditorsupport.cpp
+++ b/src/plugins/cpptools/cpptoolseditorsupport.cpp
@@ -115,6 +115,7 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
, m_textEditor(textEditor)
, m_updateDocumentInterval(UpdateDocumentDefaultInterval)
, m_revision(0)
+ , m_editorVisible(textEditor->widget()->isVisible())
, m_cachedContentsEditorRevision(-1)
, m_fileIsBeingReloaded(false)
, m_initialized(false)
@@ -152,6 +153,13 @@ CppEditorSupport::CppEditorSupport(CppModelManager *modelManager, BaseTextEditor
connect(m_textEditor->document(), SIGNAL(reloadFinished(bool)),
this, SLOT(onReloadFinished()));
+ connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor *)),
+ this, SLOT(onCurrentEditorChanged()));
+ m_editorGCTimer = new QTimer(this);
+ m_editorGCTimer->setSingleShot(true);
+ m_editorGCTimer->setInterval(EditorHiddenGCTimeout);
+ connect(m_editorGCTimer, SIGNAL(timeout()), this, SLOT(releaseResources()));
+
updateDocument();
}
@@ -460,6 +468,30 @@ void CppEditorSupport::updateEditorNow()
editorWidget->setIfdefedOutBlocks(m_editorUpdates.ifdefedOutBlocks);
}
+void CppEditorSupport::onCurrentEditorChanged()
+{
+ bool editorVisible = m_textEditor->widget()->isVisible();
+
+ if (m_editorVisible != editorVisible) {
+ m_editorVisible = editorVisible;
+ if (editorVisible) {
+ m_editorGCTimer->stop();
+ QMutexLocker locker(&m_lastSemanticInfoLock);
+ if (!m_lastSemanticInfo.doc)
+ updateDocumentNow();
+ } else {
+ m_editorGCTimer->start(EditorHiddenGCTimeout);
+ }
+ }
+}
+
+void CppEditorSupport::releaseResources()
+{
+ snapshotUpdater()->releaseSnapshot();
+ QMutexLocker semanticLocker(&m_lastSemanticInfoLock);
+ m_lastSemanticInfo = SemanticInfo();
+}
+
SemanticInfo::Source CppEditorSupport::currentSource(bool force)
{
int line = 0, column = 0;
diff --git a/src/plugins/cpptools/cpptoolseditorsupport.h b/src/plugins/cpptools/cpptoolseditorsupport.h
index 838b8cab4f..02beb1d295 100644
--- a/src/plugins/cpptools/cpptoolseditorsupport.h
+++ b/src/plugins/cpptools/cpptoolseditorsupport.h
@@ -148,6 +148,9 @@ private slots:
void updateEditor();
void updateEditorNow();
+ void onCurrentEditorChanged();
+ void releaseResources();
+
private:
struct EditorUpdates {
EditorUpdates()
@@ -160,7 +163,8 @@ private:
enum {
UpdateDocumentDefaultInterval = 150,
- UpdateEditorInterval = 300
+ UpdateEditorInterval = 300,
+ EditorHiddenGCTimeout = 2 * 60 * 1000 // 2 minutes
};
private:
@@ -178,6 +182,9 @@ private:
unsigned m_revision;
QFuture<void> m_documentParser;
+ QTimer *m_editorGCTimer;
+ bool m_editorVisible;
+
// content caching
mutable QMutex m_cachedContentsLock;
mutable QByteArray m_cachedContents;