Commit 6ced48ea authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor: Move static symbol finder instance to CppTools

...to it can be reused by other clients more easily. Also, in a
follow-up change it will have a project part dependency that can be
cleared inside the CppModelManager more easily.

Change-Id: Ic9f2ce5212a94fd05ab0571e9ad99d0a25f5bc5c
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent b4993e14
...@@ -98,8 +98,6 @@ CppEditor::CppEditor() ...@@ -98,8 +98,6 @@ CppEditor::CppEditor()
addContext(ProjectExplorer::Constants::LANG_CXX); addContext(ProjectExplorer::Constants::LANG_CXX);
} }
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
class CppEditorWidgetPrivate class CppEditorWidgetPrivate
{ {
public: public:
...@@ -384,7 +382,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit) ...@@ -384,7 +382,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
// Link to function definition/declaration // Link to function definition/declaration
CppEditorWidget::Link symbolLink; CppEditorWidget::Link symbolLink;
if (functionDeclarationSymbol) { if (functionDeclarationSymbol) {
symbolLink = linkToSymbol(symbolFinder() symbolLink = linkToSymbol(d->m_modelManager->symbolFinder()
->findMatchingDefinition(functionDeclarationSymbol, d->m_modelManager->snapshot())); ->findMatchingDefinition(functionDeclarationSymbol, d->m_modelManager->snapshot()));
} else if (functionDefinitionSymbol) { } else if (functionDefinitionSymbol) {
const Snapshot snapshot = d->m_modelManager->snapshot(); const Snapshot snapshot = d->m_modelManager->snapshot();
...@@ -426,7 +424,7 @@ CppEditorWidget::Link CppEditorWidget::findLinkAt(const QTextCursor &cursor, boo ...@@ -426,7 +424,7 @@ CppEditorWidget::Link CppEditorWidget::findLinkAt(const QTextCursor &cursor, boo
return d->m_followSymbolUnderCursor->findLink(cursor, resolveTarget, return d->m_followSymbolUnderCursor->findLink(cursor, resolveTarget,
d->m_modelManager->snapshot(), d->m_modelManager->snapshot(),
d->m_lastSemanticInfo.doc, d->m_lastSemanticInfo.doc,
symbolFinder(), d->m_modelManager->symbolFinder(),
inNextSplit); inNextSplit);
} }
......
...@@ -405,10 +405,10 @@ void CppFindReferences::searchAgain() ...@@ -405,10 +405,10 @@ void CppFindReferences::searchAgain()
} }
namespace { namespace {
class SymbolFinder : public SymbolVisitor class UidSymbolFinder : public SymbolVisitor
{ {
public: public:
SymbolFinder(const QList<QByteArray> &uid) : m_uid(uid), m_index(0), m_result(0) { } UidSymbolFinder(const QList<QByteArray> &uid) : m_uid(uid), m_index(0), m_result(0) { }
Symbol *result() const { return m_result; } Symbol *result() const { return m_result; }
bool preVisit(Symbol *symbol) bool preVisit(Symbol *symbol)
...@@ -460,7 +460,7 @@ Symbol *CppFindReferences::findSymbol(const CppFindReferencesParameters &paramet ...@@ -460,7 +460,7 @@ Symbol *CppFindReferences::findSymbol(const CppFindReferencesParameters &paramet
doc->check(); doc->check();
// find matching symbol in new document and return the new parameters // find matching symbol in new document and return the new parameters
SymbolFinder finder(parameters.symbolId); UidSymbolFinder finder(parameters.symbolId);
finder.accept(doc->globalNamespace()); finder.accept(doc->globalNamespace());
if (finder.result()) { if (finder.result()) {
*context = LookupContext(doc, snapshot); *context = LookupContext(doc, snapshot);
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "cpptoolsplugin.h" #include "cpptoolsplugin.h"
#include "cpptoolsreuse.h" #include "cpptoolsreuse.h"
#include "editordocumenthandle.h" #include "editordocumenthandle.h"
#include "symbolfinder.h"
#include <coreplugin/documentmanager.h> #include <coreplugin/documentmanager.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
...@@ -163,6 +164,8 @@ public: ...@@ -163,6 +164,8 @@ public:
CppFindReferences *m_findReferences; CppFindReferences *m_findReferences;
SymbolFinder m_symbolFinder;
bool m_enableGC; bool m_enableGC;
QTimer m_delayedGcTimer; QTimer m_delayedGcTimer;
}; };
...@@ -1272,4 +1275,9 @@ void CppModelManager::enableGarbageCollector(bool enable) ...@@ -1272,4 +1275,9 @@ void CppModelManager::enableGarbageCollector(bool enable)
d->m_enableGC = enable; d->m_enableGC = enable;
} }
SymbolFinder *CppModelManager::symbolFinder()
{
return &d->m_symbolFinder;
}
} // namespace CppTools } // namespace CppTools
...@@ -58,6 +58,7 @@ class BaseEditorDocumentProcessor; ...@@ -58,6 +58,7 @@ class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider; class CppCompletionAssistProvider;
class CppEditorDocumentHandle; class CppEditorDocumentHandle;
class CppIndexingSupport; class CppIndexingSupport;
class SymbolFinder;
class WorkingCopy; class WorkingCopy;
namespace Internal { namespace Internal {
...@@ -161,6 +162,8 @@ public: ...@@ -161,6 +162,8 @@ public:
void enableGarbageCollector(bool enable); void enableGarbageCollector(bool enable);
SymbolFinder *symbolFinder();
static QSet<QString> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck); static QSet<QString> timeStampModifiedFiles(const QList<Document::Ptr> &documentsToCheck);
static Internal::CppSourceProcessor *createSourceProcessor(); static Internal::CppSourceProcessor *createSourceProcessor();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment