Clang: add globalFollowSymbol to RefactoringEngine

Allows to follow outside of current TU.

Change-Id: Ieea2fd72bfdf6d60a988b40efcf2f41c5a71d045
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2017-10-05 09:54:21 +02:00
parent c760804102
commit 7a7123b1bc
27 changed files with 133 additions and 265 deletions

View File

@@ -289,7 +289,7 @@ void CppModelManager::startLocalRenaming(const CursorInEditor &data,
CppTools::ProjectPart *projectPart,
RenameCallback &&renameSymbolsCallback)
{
RefactoringEngineInterface *engine = getRefactoringEngine(instance()->d->m_refactoringEngines,
RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines,
false);
QTC_ASSERT(engine, return;);
engine->startLocalRenaming(data, projectPart, std::move(renameSymbolsCallback));
@@ -298,7 +298,7 @@ void CppModelManager::startLocalRenaming(const CursorInEditor &data,
void CppModelManager::globalRename(const CursorInEditor &data, UsagesCallback &&renameCallback,
const QString &replacement)
{
RefactoringEngineInterface *engine = getRefactoringEngine(instance()->d->m_refactoringEngines);
RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines);
QTC_ASSERT(engine, return;);
engine->globalRename(data, std::move(renameCallback), replacement);
}
@@ -306,11 +306,24 @@ void CppModelManager::globalRename(const CursorInEditor &data, UsagesCallback &&
void CppModelManager::findUsages(const CppTools::CursorInEditor &data,
UsagesCallback &&showUsagesCallback) const
{
RefactoringEngineInterface *engine = getRefactoringEngine(instance()->d->m_refactoringEngines);
RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines);
QTC_ASSERT(engine, return;);
engine->findUsages(data, std::move(showUsagesCallback));
}
CppModelManager::Link CppModelManager::globalFollowSymbol(
const CursorInEditor &data,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const
{
RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines);
QTC_ASSERT(engine, return Link(););
return engine->globalFollowSymbol(data, snapshot, documentFromSemanticInfo,
symbolFinder, inNextSplit);
}
void CppModelManager::addRefactoringEngine(RefactoringEngineType type,
RefactoringEngineInterface *refactoringEngine)
{

View File

@@ -155,6 +155,11 @@ public:
const QString &replacement) final;
void findUsages(const CppTools::CursorInEditor &data,
UsagesCallback &&showUsagesCallback) const final;
Link globalFollowSymbol(const CursorInEditor &data,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const final;
void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context,
const QString &replacement = QString());

View File

@@ -28,6 +28,7 @@
#include "cpprefactoringengine.h"
#include "cppsemanticinfo.h"
#include "cpptoolsreuse.h"
#include "cppfollowsymbolundercursor.h"
#include <texteditor/texteditor.h>
@@ -99,4 +100,16 @@ void CppRefactoringEngine::findUsages(const CursorInEditor &data,
}
}
CppRefactoringEngine::Link CppRefactoringEngine::globalFollowSymbol(
const CursorInEditor &data,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const
{
FollowSymbolUnderCursor followSymbol;
return followSymbol.findLink(data, true, snapshot, documentFromSemanticInfo,
symbolFinder, inNextSplit);
}
} // namespace CppEditor

View File

@@ -38,6 +38,11 @@ public:
void globalRename(const CursorInEditor &data, UsagesCallback &&,
const QString &replacement) override;
void findUsages(const CursorInEditor &data, UsagesCallback &&) const override;
Link globalFollowSymbol(const CursorInEditor &data,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const override;
};
} // namespace CppEditor

View File

@@ -29,12 +29,15 @@
#include "cursorineditor.h"
#include "usages.h"
#include <utils/link.h>
#include <utils/fileutils.h>
#include <utils/smallstring.h>
#include <clangsupport/sourcelocationscontainer.h>
#include <clangsupport/refactoringclientinterface.h>
#include <cplusplus/CppDocument.h>
namespace TextEditor {
class TextEditorWidget;
} // namespace TextEditor
@@ -42,6 +45,7 @@ class TextEditorWidget;
namespace CppTools {
class ProjectPart;
class SymbolFinder;
enum class CallType
{
@@ -54,6 +58,7 @@ class CPPTOOLS_EXPORT RefactoringEngineInterface
{
public:
using RenameCallback = ClangBackEnd::RefactoringClientInterface::RenameCallback;
using Link = Utils::Link;
virtual ~RefactoringEngineInterface() {}
@@ -65,6 +70,11 @@ public:
const QString &replacement) = 0;
virtual void findUsages(const CppTools::CursorInEditor &data,
UsagesCallback &&showUsagesCallback) const = 0;
virtual Link globalFollowSymbol(const CursorInEditor &data,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const = 0;
virtual bool isRefactoringEngineAvailable() const { return true; }
};

View File

@@ -37,6 +37,7 @@ namespace CppTools {
class Usage
{
public:
Usage() {}
Usage(Utils::SmallStringView path, int line, int column)
: path(QString::fromUtf8(path.data(), int(path.size()))),
line(line),
@@ -52,8 +53,8 @@ public:
public:
QString path;
int line;
int column;
int line = 0;
int column = 0;
};
using Usages = std::vector<Usage>;