forked from qt-creator/qt-creator
C++: Share symbol finder across editor instances
Change-Id: I75880597d237bbbe1393dd02153cedba1165bed6 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
This commit is contained in:
@@ -412,6 +412,8 @@ CPPEditor::CPPEditor(CPPEditorWidget *editor)
|
|||||||
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
|
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
|
||||||
|
|
||||||
CPPEditorWidget::CPPEditorWidget(QWidget *parent)
|
CPPEditorWidget::CPPEditorWidget(QWidget *parent)
|
||||||
: TextEditor::BaseTextEditorWidget(parent)
|
: TextEditor::BaseTextEditorWidget(parent)
|
||||||
, m_currentRenameSelection(NoCurrentRenameSelection)
|
, m_currentRenameSelection(NoCurrentRenameSelection)
|
||||||
@@ -420,7 +422,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent)
|
|||||||
, m_firstRenameChange(false)
|
, m_firstRenameChange(false)
|
||||||
, m_objcEnabled(false)
|
, m_objcEnabled(false)
|
||||||
, m_commentsSettings(CppTools::CppToolsSettings::instance()->commentsSettings())
|
, m_commentsSettings(CppTools::CppToolsSettings::instance()->commentsSettings())
|
||||||
, m_symbolFinder(new CppTools::SymbolFinder)
|
|
||||||
{
|
{
|
||||||
m_initialized = false;
|
m_initialized = false;
|
||||||
qRegisterMetaType<CppEditor::Internal::SemanticInfo>("CppEditor::Internal::SemanticInfo");
|
qRegisterMetaType<CppEditor::Internal::SemanticInfo>("CppEditor::Internal::SemanticInfo");
|
||||||
@@ -1078,7 +1079,7 @@ void CPPEditorWidget::switchDeclarationDefinition()
|
|||||||
openCppEditorAt(linkToSymbol(best.first()));
|
openCppEditorAt(linkToSymbol(best.first()));
|
||||||
|
|
||||||
} else if (lastVisibleSymbol && lastVisibleSymbol->isDeclaration() && lastVisibleSymbol->type()->isFunctionType()) {
|
} else if (lastVisibleSymbol && lastVisibleSymbol->isDeclaration() && lastVisibleSymbol->type()->isFunctionType()) {
|
||||||
if (Symbol *def = m_symbolFinder->findMatchingDefinition(lastVisibleSymbol, snapshot))
|
if (Symbol *def = symbolFinder()->findMatchingDefinition(lastVisibleSymbol, snapshot))
|
||||||
openCppEditorAt(linkToSymbol(def));
|
openCppEditorAt(linkToSymbol(def));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1174,12 +1175,12 @@ CPPEditorWidget::Link CPPEditorWidget::attemptFuncDeclDef(const QTextCursor &cur
|
|||||||
Symbol *target = 0;
|
Symbol *target = 0;
|
||||||
if (FunctionDefinitionAST *funDef = declParent->asFunctionDefinition()) {
|
if (FunctionDefinitionAST *funDef = declParent->asFunctionDefinition()) {
|
||||||
QList<Declaration *> candidates =
|
QList<Declaration *> candidates =
|
||||||
m_symbolFinder->findMatchingDeclaration(LookupContext(doc, snapshot),
|
symbolFinder()->findMatchingDeclaration(LookupContext(doc, snapshot),
|
||||||
funDef->symbol);
|
funDef->symbol);
|
||||||
if (!candidates.isEmpty()) // TODO: improve disambiguation
|
if (!candidates.isEmpty()) // TODO: improve disambiguation
|
||||||
target = candidates.first();
|
target = candidates.first();
|
||||||
} else if (declParent->asSimpleDeclaration()) {
|
} else if (declParent->asSimpleDeclaration()) {
|
||||||
target = m_symbolFinder->findMatchingDefinition(funcDecl->symbol, snapshot);
|
target = symbolFinder()->findMatchingDefinition(funcDecl->symbol, snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target) {
|
if (target) {
|
||||||
@@ -1430,7 +1431,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
def = 0; // jump to declaration then.
|
def = 0; // jump to declaration then.
|
||||||
|
|
||||||
if (symbol->isForwardClassDeclaration())
|
if (symbol->isForwardClassDeclaration())
|
||||||
def = m_symbolFinder->findMatchingClassDeclaration(symbol, snapshot);
|
def = symbolFinder()->findMatchingClassDeclaration(symbol, snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
link = linkToSymbol(def ? def : symbol);
|
link = linkToSymbol(def ? def : symbol);
|
||||||
@@ -1466,7 +1467,7 @@ Symbol *CPPEditorWidget::findDefinition(Symbol *symbol, const Snapshot &snapshot
|
|||||||
else if (! symbol->type()->isFunctionType())
|
else if (! symbol->type()->isFunctionType())
|
||||||
return 0; // not a function declaration
|
return 0; // not a function declaration
|
||||||
|
|
||||||
return m_symbolFinder->findMatchingDefinition(symbol, snapshot);
|
return symbolFinder()->findMatchingDefinition(symbol, snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned CPPEditorWidget::editorRevision() const
|
unsigned CPPEditorWidget::editorRevision() const
|
||||||
@@ -2256,11 +2257,6 @@ void CPPEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch)
|
|||||||
updateFunctionDeclDefLink();
|
updateFunctionDeclDefLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSharedPointer<CppTools::SymbolFinder> CPPEditorWidget::symbolFinder() const
|
|
||||||
{
|
|
||||||
return m_symbolFinder;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CPPEditorWidget::abortDeclDefLink()
|
void CPPEditorWidget::abortDeclDefLink()
|
||||||
{
|
{
|
||||||
if (!m_declDefLink)
|
if (!m_declDefLink)
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ class CppModelManagerInterface;
|
|||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
class CppCodeStyleSettings;
|
class CppCodeStyleSettings;
|
||||||
class CppRefactoringFile;
|
class CppRefactoringFile;
|
||||||
class SymbolFinder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
@@ -201,8 +200,6 @@ public:
|
|||||||
QSharedPointer<FunctionDeclDefLink> declDefLink() const;
|
QSharedPointer<FunctionDeclDefLink> declDefLink() const;
|
||||||
void applyDeclDefLinkChanges(bool jumpToMatch);
|
void applyDeclDefLinkChanges(bool jumpToMatch);
|
||||||
|
|
||||||
QSharedPointer<CppTools::SymbolFinder> symbolFinder() const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void outlineModelIndexChanged(const QModelIndex &index);
|
void outlineModelIndexChanged(const QModelIndex &index);
|
||||||
|
|
||||||
@@ -336,7 +333,6 @@ private:
|
|||||||
QSharedPointer<FunctionDeclDefLink> m_declDefLink;
|
QSharedPointer<FunctionDeclDefLink> m_declDefLink;
|
||||||
|
|
||||||
CppTools::CommentsSettings m_commentsSettings;
|
CppTools::CommentsSettings m_commentsSettings;
|
||||||
QSharedPointer<CppTools::SymbolFinder> m_symbolFinder;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/ifile.h>
|
#include <coreplugin/ifile.h>
|
||||||
#include <cpptools/cpptoolsreuse.h>
|
#include <cpptools/cpptoolsreuse.h>
|
||||||
#include <cpptools/symbolfinder.h>
|
|
||||||
|
|
||||||
#include <FullySpecifiedType.h>
|
#include <FullySpecifiedType.h>
|
||||||
#include <Literals.h>
|
#include <Literals.h>
|
||||||
@@ -186,8 +185,7 @@ void CppElementEvaluator::handleLookupItemMatch(const Snapshot &snapshot,
|
|||||||
|| declaration->asTemplate()->declaration()->isForwardClassDeclaration()))) {
|
|| declaration->asTemplate()->declaration()->isForwardClassDeclaration()))) {
|
||||||
if (declaration->isForwardClassDeclaration())
|
if (declaration->isForwardClassDeclaration())
|
||||||
if (Symbol *classDeclaration =
|
if (Symbol *classDeclaration =
|
||||||
m_editor->symbolFinder()->findMatchingClassDeclaration(
|
m_symbolFinder.findMatchingClassDeclaration(declaration, snapshot)) {
|
||||||
declaration, snapshot)) {
|
|
||||||
declaration = classDeclaration;
|
declaration = classDeclaration;
|
||||||
}
|
}
|
||||||
CppClass *cppClass = new CppClass(declaration);
|
CppClass *cppClass = new CppClass(declaration);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
#include "cppeditor.h"
|
#include "cppeditor.h"
|
||||||
|
|
||||||
#include <texteditor/helpitem.h>
|
#include <texteditor/helpitem.h>
|
||||||
|
#include <cpptools/symbolfinder.h>
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
#include <cplusplus/Overview.h>
|
#include <cplusplus/Overview.h>
|
||||||
|
|
||||||
@@ -92,6 +92,7 @@ private:
|
|||||||
bool m_lookupDerivedClasses;
|
bool m_lookupDerivedClasses;
|
||||||
QSharedPointer<CppElement> m_element;
|
QSharedPointer<CppElement> m_element;
|
||||||
QString m_diagnosis;
|
QString m_diagnosis;
|
||||||
|
CppTools::SymbolFinder m_symbolFinder;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CppElement
|
class CppElement
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
|
||||||
static const int kMaxSize = 10;
|
static const int kMaxCacheSize = 10;
|
||||||
|
|
||||||
SymbolFinder::SymbolFinder()
|
SymbolFinder::SymbolFinder()
|
||||||
{}
|
{}
|
||||||
@@ -339,7 +339,7 @@ void SymbolFinder::trackCacheUse(const QString &referenceFile)
|
|||||||
m_recent.append(referenceFile);
|
m_recent.append(referenceFile);
|
||||||
|
|
||||||
// We don't want this to grow too much.
|
// We don't want this to grow too much.
|
||||||
if (m_recent.size() > kMaxSize) {
|
if (m_recent.size() > kMaxCacheSize) {
|
||||||
const QString &oldest = m_recent.takeFirst();
|
const QString &oldest = m_recent.takeFirst();
|
||||||
m_filePriorityCache.remove(oldest);
|
m_filePriorityCache.remove(oldest);
|
||||||
m_fileMetaCache.remove(oldest);
|
m_fileMetaCache.remove(oldest);
|
||||||
|
|||||||
Reference in New Issue
Block a user