ClangCodeModel: Remove libclang fallback for "follow symbol"

... and "switch between declaration/definition".
It's either clangd or built-in code model now.
Use the opportunity to dissolve the pointless FollowSymbolInterface
class hierarchy, which introduced a confusing parallel inheritance
chain.

Change-Id: I792ad55656c5dd9f10c6b4db7c5c36cf7be45125
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-04-25 13:37:58 +02:00
parent 8e586dfa02
commit f2c267f328
23 changed files with 117 additions and 523 deletions

View File

@@ -35,7 +35,6 @@ add_qtc_plugin(ClangCodeModel
clangeditordocumentprocessor.cpp clangeditordocumentprocessor.h clangeditordocumentprocessor.cpp clangeditordocumentprocessor.h
clangfixitoperation.cpp clangfixitoperation.h clangfixitoperation.cpp clangfixitoperation.h
clangfixitoperationsextractor.cpp clangfixitoperationsextractor.h clangfixitoperationsextractor.cpp clangfixitoperationsextractor.h
clangfollowsymbol.cpp clangfollowsymbol.h
clangfunctionhintmodel.cpp clangfunctionhintmodel.h clangfunctionhintmodel.cpp clangfunctionhintmodel.h
clangdlocatorfilters.cpp clangdlocatorfilters.h clangdlocatorfilters.cpp clangdlocatorfilters.h
clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h

View File

@@ -78,8 +78,6 @@ QtcPlugin {
"clangfixitoperation.h", "clangfixitoperation.h",
"clangfixitoperationsextractor.cpp", "clangfixitoperationsextractor.cpp",
"clangfixitoperationsextractor.h", "clangfixitoperationsextractor.h",
"clangfollowsymbol.cpp",
"clangfollowsymbol.h",
"clangfunctionhintmodel.cpp", "clangfunctionhintmodel.cpp",
"clangfunctionhintmodel.h", "clangfunctionhintmodel.h",
"clanghighlightingresultreporter.cpp", "clanghighlightingresultreporter.cpp",

View File

@@ -1,274 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "clangfollowsymbol.h"
#include "clangdclient.h"
#include "clangeditordocumentprocessor.h"
#include "clangmodelmanagersupport.h"
#include <coreplugin/editormanager/editormanager.h>
#include <cppeditor/cppmodelmanager.h>
#include <cppeditor/cppfollowsymbolundercursor.h>
#include <texteditor/texteditor.h>
#include <clangsupport/tokeninfocontainer.h>
#include <utils/textutils.h>
#include <utils/algorithm.h>
#include <memory>
namespace ClangCodeModel {
namespace Internal {
// Returns invalid Mark if it is not found at (line, column)
static bool findMark(const QVector<ClangBackEnd::TokenInfoContainer> &marks,
int line,
int column,
ClangBackEnd::TokenInfoContainer &mark)
{
mark = Utils::findOrDefault(marks,
[line, column](const ClangBackEnd::TokenInfoContainer &curMark) {
if (curMark.line != line)
return false;
if (curMark.column == column)
return true;
if (curMark.column < column && curMark.column + curMark.length > column)
return true;
return false;
});
if (mark.isInvalid())
return false;
return true;
}
static int getMarkPos(QTextCursor cursor, const ClangBackEnd::TokenInfoContainer &mark)
{
cursor.setPosition(0);
cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, mark.line - 1);
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, mark.column - 1);
return cursor.position();
}
static bool isValidIncludePathToken(const ClangBackEnd::TokenInfoContainer &token)
{
if (!token.extraInfo.includeDirectivePath)
return false;
const Utf8String &tokenName = token.extraInfo.token;
return !tokenName.startsWith("include") && tokenName != Utf8String("<")
&& tokenName != Utf8String(">") && tokenName != Utf8String("#");
}
static int includePathStartIndex(const QVector<ClangBackEnd::TokenInfoContainer> &marks,
int currentIndex)
{
int startIndex = currentIndex - 1;
while (startIndex >= 0 && isValidIncludePathToken(marks[startIndex]))
--startIndex;
return startIndex + 1;
}
static int includePathEndIndex(const QVector<ClangBackEnd::TokenInfoContainer> &marks,
int currentIndex)
{
int endIndex = currentIndex + 1;
while (endIndex < marks.size() && isValidIncludePathToken(marks[endIndex]))
++endIndex;
return endIndex - 1;
}
static Utils::Link linkAtCursor(const QTextCursor &cursor,
const QString &filePath,
uint line,
uint column,
ClangEditorDocumentProcessor *processor)
{
using Link = Utils::Link;
const QVector<ClangBackEnd::TokenInfoContainer> &marks
= processor->tokenInfos();
ClangBackEnd::TokenInfoContainer mark;
if (!findMark(marks, line, column, mark))
return Link();
if (mark.extraInfo.includeDirectivePath && !isValidIncludePathToken(mark))
return Link();
Link token(Utils::FilePath::fromString(filePath), mark.line, mark.column);
token.linkTextStart = getMarkPos(cursor, mark);
token.linkTextEnd = token.linkTextStart + mark.length;
if (mark.extraInfo.includeDirectivePath) {
// Tweak include paths to cover everything between "" or <>.
if (mark.extraInfo.token.startsWith("\"")) {
token.linkTextStart++;
token.linkTextEnd--;
} else {
// '#include <path/file.h>' case. Clang gives us a separate token for each part of
// the path. We want to have the full range instead therefore we search for < and >
// tokens around the current token.
const int index = marks.indexOf(mark);
const int startIndex = includePathStartIndex(marks, index);
const int endIndex = includePathEndIndex(marks, index);
if (startIndex != index)
token.linkTextStart = getMarkPos(cursor, marks[startIndex]);
if (endIndex != index)
token.linkTextEnd = getMarkPos(cursor, marks[endIndex]) + marks[endIndex].length;
}
return token;
}
if (mark.extraInfo.identifier || mark.extraInfo.token == "operator"
|| mark.extraInfo.token == "auto") {
return token;
}
return Link();
}
static ::Utils::ProcessLinkCallback extendedCallback(::Utils::ProcessLinkCallback &&callback,
const CppEditor::SymbolInfo &result)
{
// If globalFollowSymbol finds nothing follow to the declaration.
return [original_callback = std::move(callback), result](const ::Utils::Link &link) {
if (link.linkTextStart < 0 && result.isResultOnlyForFallBack) {
return original_callback(Utils::Link(
Utils::FilePath::fromString(result.fileName).cleanPath(),
result.startLine,
result.startColumn - 1));
}
return original_callback(link);
};
}
static bool isSameInvocationContext(const Utils::FilePath &filePath)
{
return TextEditor::BaseTextEditor::currentTextEditor()->editorWidget()->isVisible()
&& Core::EditorManager::currentDocument()->filePath() == filePath;
}
void ClangFollowSymbol::findLink(const CppEditor::CursorInEditor &data,
::Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
CppEditor::SymbolFinder *symbolFinder,
bool inNextSplit)
{
ClangdClient * const client
= ClangModelManagerSupport::instance()->clientForFile(data.filePath());
if (client && client->isFullyIndexed()) {
client->followSymbol(data.textDocument(), data.cursor(), data.editorWidget(),
std::move(processLinkCallback), resolveTarget, inNextSplit);
return;
}
int line = 0;
int column = 0;
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
Utils::Text::convertPosition(cursor.document(), cursor.position(), &line, &column);
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(
data.filePath().toString());
if (!processor)
return processLinkCallback(Utils::Link());
if (!resolveTarget) {
Utils::Link link = linkAtCursor(cursor,
data.filePath().toString(),
static_cast<uint>(line),
static_cast<uint>(column),
processor);
if (link == Utils::Link()) {
CppEditor::FollowSymbolUnderCursor followSymbol;
return followSymbol.findLink(data,
std::move(processLinkCallback),
false,
snapshot,
documentFromSemanticInfo,
symbolFinder,
inNextSplit);
}
return processLinkCallback(link);
}
QFuture<CppEditor::SymbolInfo> infoFuture
= processor->requestFollowSymbol(static_cast<int>(line),
static_cast<int>(column));
if (infoFuture.isCanceled())
return processLinkCallback(Utils::Link());
if (m_watcher)
m_watcher->cancel();
m_watcher = std::make_unique<FutureSymbolWatcher>();
QObject::connect(m_watcher.get(), &FutureSymbolWatcher::finished, [=, filePath=data.filePath(),
callback=std::move(processLinkCallback)]() mutable {
if (m_watcher->isCanceled() || !isSameInvocationContext(filePath))
return callback(Utils::Link());
CppEditor::SymbolInfo result = m_watcher->result();
// We did not fail but the result is empty
if (result.fileName.isEmpty() || result.isResultOnlyForFallBack) {
const CppEditor::RefactoringEngineInterface &refactoringEngine
= *CppEditor::CppModelManager::instance();
refactoringEngine.globalFollowSymbol(data,
extendedCallback(std::move(callback), result),
snapshot,
documentFromSemanticInfo,
symbolFinder,
inNextSplit);
} else {
callback(Link(Utils::FilePath::fromString(result.fileName).cleanPath(),
result.startLine,
result.startColumn - 1));
}
});
m_watcher->setFuture(infoFuture);
}
void ClangFollowSymbol::switchDeclDef(const CppEditor::CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
CppEditor::SymbolFinder *symbolFinder)
{
ClangdClient * const client
= ClangModelManagerSupport::instance()->clientForFile(data.filePath());
if (client && client->isFullyIndexed()) {
client->switchDeclDef(data.textDocument(), data.cursor(), data.editorWidget(),
std::move(processLinkCallback));
return;
}
CppEditor::CppModelManager::builtinFollowSymbol().switchDeclDef(
data, std::move(processLinkCallback), snapshot, documentFromSemanticInfo,
symbolFinder);
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -1,60 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <cppeditor/cpptoolsreuse.h>
#include <cppeditor/followsymbolinterface.h>
#include <QFutureWatcher>
namespace ClangCodeModel {
namespace Internal {
class ClangFollowSymbol : public CppEditor::FollowSymbolInterface
{
public:
void findLink(const CppEditor::CursorInEditor &data,
::Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
CppEditor::SymbolFinder *symbolFinder,
bool inNextSplit) override;
void switchDeclDef(const CppEditor::CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
CppEditor::SymbolFinder *symbolFinder) override;
private:
using FutureSymbolWatcher = QFutureWatcher<CppEditor::SymbolInfo>;
std::unique_ptr<FutureSymbolWatcher> m_watcher;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -29,7 +29,6 @@
#include "clangdclient.h" #include "clangdclient.h"
#include "clangdquickfixfactory.h" #include "clangdquickfixfactory.h"
#include "clangeditordocumentprocessor.h" #include "clangeditordocumentprocessor.h"
#include "clangfollowsymbol.h"
#include "clangdlocatorfilters.h" #include "clangdlocatorfilters.h"
#include "clanghoverhandler.h" #include "clanghoverhandler.h"
#include "clangoverviewmodel.h" #include "clangoverviewmodel.h"
@@ -45,11 +44,13 @@
#include <cppeditor/cppcodemodelsettings.h> #include <cppeditor/cppcodemodelsettings.h>
#include <cppeditor/cppeditorconstants.h> #include <cppeditor/cppeditorconstants.h>
#include <cppeditor/cppeditorwidget.h>
#include <cppeditor/cppfollowsymbolundercursor.h> #include <cppeditor/cppfollowsymbolundercursor.h>
#include <cppeditor/cppmodelmanager.h> #include <cppeditor/cppmodelmanager.h>
#include <cppeditor/cppprojectfile.h> #include <cppeditor/cppprojectfile.h>
#include <cppeditor/cpptoolsreuse.h> #include <cppeditor/cpptoolsreuse.h>
#include <cppeditor/editordocumenthandle.h> #include <cppeditor/editordocumenthandle.h>
#include <cppeditor/symbolfinder.h>
#include <languageclient/languageclientmanager.h> #include <languageclient/languageclientmanager.h>
@@ -106,7 +107,6 @@ static const QList<TextEditor::TextDocument *> allCppDocuments()
ClangModelManagerSupport::ClangModelManagerSupport() ClangModelManagerSupport::ClangModelManagerSupport()
: m_completionAssistProvider(m_communicator, CompletionType::Other) : m_completionAssistProvider(m_communicator, CompletionType::Other)
, m_functionHintAssistProvider(m_communicator, CompletionType::FunctionHint) , m_functionHintAssistProvider(m_communicator, CompletionType::FunctionHint)
, m_followSymbol(new ClangFollowSymbol)
, m_refactoringEngine(new RefactoringEngine) , m_refactoringEngine(new RefactoringEngine)
{ {
QTC_CHECK(!m_instance); QTC_CHECK(!m_instance);
@@ -188,9 +188,37 @@ TextEditor::BaseHoverHandler *ClangModelManagerSupport::createHoverHandler()
return new Internal::ClangHoverHandler; return new Internal::ClangHoverHandler;
} }
CppEditor::FollowSymbolInterface &ClangModelManagerSupport::followSymbolInterface() void ClangModelManagerSupport::followSymbol(const CppEditor::CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback, bool resolveTarget,
bool inNextSplit)
{ {
return *m_followSymbol; if (ClangdClient * const client = clientForFile(data.filePath());
client && client->isFullyIndexed()) {
client->followSymbol(data.textDocument(), data.cursor(), data.editorWidget(),
std::move(processLinkCallback), resolveTarget, inNextSplit);
return;
}
SymbolFinder finder;
CppModelManager::builtinFollowSymbol().findLink(data, std::move(processLinkCallback),
resolveTarget, CppModelManager::instance()->snapshot(),
data.editorWidget()->semanticInfo().doc, &finder, inNextSplit);
}
void ClangModelManagerSupport::switchDeclDef(const CppEditor::CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback)
{
if (ClangdClient * const client = clientForFile(data.filePath());
client && client->isFullyIndexed()) {
client->switchDeclDef(data.textDocument(), data.cursor(), data.editorWidget(),
std::move(processLinkCallback));
return;
}
SymbolFinder finder;
CppModelManager::builtinFollowSymbol().switchDeclDef(data, std::move(processLinkCallback),
CppModelManager::instance()->snapshot(), data.editorWidget()->semanticInfo().doc,
&finder);
} }
CppEditor::RefactoringEngineInterface &ClangModelManagerSupport::refactoringEngineInterface() CppEditor::RefactoringEngineInterface &ClangModelManagerSupport::refactoringEngineInterface()

View File

@@ -45,10 +45,7 @@ class QWidget;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace TextEditor { class TextEditorWidget; } namespace TextEditor { class TextEditorWidget; }
namespace CppEditor { namespace CppEditor { class RefactoringEngineInterface; }
class FollowSymbolInterface;
class RefactoringEngineInterface;
} // namespace CppEditor
namespace ClangCodeModel { namespace ClangCodeModel {
namespace Internal { namespace Internal {
@@ -71,7 +68,6 @@ public:
TextEditor::BaseHoverHandler *createHoverHandler() override; TextEditor::BaseHoverHandler *createHoverHandler() override;
CppEditor::BaseEditorDocumentProcessor *createEditorDocumentProcessor( CppEditor::BaseEditorDocumentProcessor *createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) override; TextEditor::TextDocument *baseTextDocument) override;
CppEditor::FollowSymbolInterface &followSymbolInterface() override;
CppEditor::RefactoringEngineInterface &refactoringEngineInterface() override; CppEditor::RefactoringEngineInterface &refactoringEngineInterface() override;
std::unique_ptr<CppEditor::AbstractOverviewModel> createOverviewModel() override; std::unique_ptr<CppEditor::AbstractOverviewModel> createOverviewModel() override;
bool supportsOutline(const TextEditor::TextDocument *document) const override; bool supportsOutline(const TextEditor::TextDocument *document) const override;
@@ -92,6 +88,12 @@ signals:
void createdClient(ClangdClient *client); void createdClient(ClangdClient *client);
private: private:
void followSymbol(const CppEditor::CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback, bool resolveTarget,
bool inNextSplit) override;
void switchDeclDef(const CppEditor::CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback) override;
void onEditorOpened(Core::IEditor *editor); void onEditorOpened(Core::IEditor *editor);
void onEditorClosed(const QList<Core::IEditor *> &editors); void onEditorClosed(const QList<Core::IEditor *> &editors);
void onCurrentEditorChanged(Core::IEditor *newCurrent); void onCurrentEditorChanged(Core::IEditor *newCurrent);
@@ -142,7 +144,6 @@ private:
BackendCommunicator m_communicator; BackendCommunicator m_communicator;
ClangCompletionAssistProvider m_completionAssistProvider; ClangCompletionAssistProvider m_completionAssistProvider;
ClangCompletionAssistProvider m_functionHintAssistProvider; ClangCompletionAssistProvider m_functionHintAssistProvider;
std::unique_ptr<CppEditor::FollowSymbolInterface> m_followSymbol;
std::unique_ptr<CppEditor::RefactoringEngineInterface> m_refactoringEngine; std::unique_ptr<CppEditor::RefactoringEngineInterface> m_refactoringEngine;
QHash<ProjectExplorer::Project *, ClangProjectSettings *> m_projectSettings; QHash<ProjectExplorer::Project *, ClangProjectSettings *> m_projectSettings;

View File

@@ -124,25 +124,5 @@ void RefactoringEngine::findUsages(const CppEditor::CursorInEditor &cursor,
client->findUsages(cursor.textDocument(), cursor.cursor(), {}); client->findUsages(cursor.textDocument(), cursor.cursor(), {});
} }
void RefactoringEngine::globalFollowSymbol(
const CppEditor::CursorInEditor &cursor,
Utils::ProcessLinkCallback &&callback,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &doc,
CppEditor::SymbolFinder *symbolFinder,
bool inNextSplit) const
{
ClangdClient * const client
= ClangModelManagerSupport::instance()->clientForFile(cursor.filePath());
if (!client || !client->isFullyIndexed()) {
CppEditor::CppModelManager::builtinRefactoringEngine()
->globalFollowSymbol(cursor, std::move(callback), snapshot, doc, symbolFinder,
inNextSplit);
return;
}
client->followSymbol(cursor.textDocument(), cursor.cursor(), cursor.editorWidget(),
std::move(callback), true, inNextSplit);
}
} // namespace Internal } // namespace Internal
} // namespace ClangCodeModel } // namespace ClangCodeModel

View File

@@ -48,12 +48,6 @@ public:
const QString &replacement) override; const QString &replacement) override;
void findUsages(const CppEditor::CursorInEditor &cursor, void findUsages(const CppEditor::CursorInEditor &cursor,
CppEditor::UsagesCallback &&callback) const override; CppEditor::UsagesCallback &&callback) const override;
void globalFollowSymbol(const CppEditor::CursorInEditor &cursor,
::Utils::ProcessLinkCallback &&callback,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &doc,
CppEditor::SymbolFinder *symbolFinder,
bool inNextSplit) const override;
private: private:
using FutureCursorWatcher = QFutureWatcher<CppEditor::CursorInfo>; using FutureCursorWatcher = QFutureWatcher<CppEditor::CursorInfo>;

View File

@@ -102,7 +102,6 @@ add_qtc_plugin(CppEditor
cursorineditor.h cursorineditor.h
doxygengenerator.cpp doxygengenerator.h doxygengenerator.cpp doxygengenerator.h
editordocumenthandle.cpp editordocumenthandle.h editordocumenthandle.cpp editordocumenthandle.h
followsymbolinterface.h
functionutils.cpp functionutils.h functionutils.cpp functionutils.h
generatedcodemodelsupport.cpp generatedcodemodelsupport.h generatedcodemodelsupport.cpp generatedcodemodelsupport.h
headerpathfilter.cpp headerpathfilter.h headerpathfilter.cpp headerpathfilter.h

View File

@@ -27,11 +27,13 @@
#include "builtineditordocumentprocessor.h" #include "builtineditordocumentprocessor.h"
#include "cppcompletionassist.h" #include "cppcompletionassist.h"
#include "cppeditorwidget.h"
#include "cppelementevaluator.h" #include "cppelementevaluator.h"
#include "cppfollowsymbolundercursor.h" #include "cppfollowsymbolundercursor.h"
#include "cppoverviewmodel.h" #include "cppoverviewmodel.h"
#include "cpprefactoringengine.h" #include "cpprefactoringengine.h"
#include "cpptoolsreuse.h" #include "cpptoolsreuse.h"
#include "symbolfinder.h"
#include <app/app_version.h> #include <app/app_version.h>
#include <texteditor/basehoverhandler.h> #include <texteditor/basehoverhandler.h>
@@ -127,11 +129,6 @@ TextEditor::BaseHoverHandler *BuiltinModelManagerSupport::createHoverHandler()
return new CppHoverHandler; return new CppHoverHandler;
} }
FollowSymbolInterface &BuiltinModelManagerSupport::followSymbolInterface()
{
return *m_followSymbol;
}
RefactoringEngineInterface &BuiltinModelManagerSupport::refactoringEngineInterface() RefactoringEngineInterface &BuiltinModelManagerSupport::refactoringEngineInterface()
{ {
return *m_refactoringEngine; return *m_refactoringEngine;
@@ -142,4 +139,23 @@ std::unique_ptr<AbstractOverviewModel> BuiltinModelManagerSupport::createOvervie
return std::make_unique<OverviewModel>(); return std::make_unique<OverviewModel>();
} }
void BuiltinModelManagerSupport::followSymbol(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget, bool inNextSplit)
{
SymbolFinder finder;
m_followSymbol->findLink(data, std::move(processLinkCallback),
resolveTarget, CppModelManager::instance()->snapshot(),
data.editorWidget()->semanticInfo().doc, &finder, inNextSplit);
}
void BuiltinModelManagerSupport::switchDeclDef(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback)
{
SymbolFinder finder;
m_followSymbol->switchDeclDef(data, std::move(processLinkCallback),
CppModelManager::instance()->snapshot(), data.editorWidget()->semanticInfo().doc,
&finder);
}
} // namespace CppEditor::Internal } // namespace CppEditor::Internal

View File

@@ -29,6 +29,8 @@
#include <QScopedPointer> #include <QScopedPointer>
namespace CppEditor { class FollowSymbolUnderCursor; }
namespace CppEditor::Internal { namespace CppEditor::Internal {
class BuiltinModelManagerSupport: public ModelManagerSupport class BuiltinModelManagerSupport: public ModelManagerSupport
@@ -44,13 +46,19 @@ public:
TextEditor::BaseHoverHandler *createHoverHandler() final; TextEditor::BaseHoverHandler *createHoverHandler() final;
BaseEditorDocumentProcessor *createEditorDocumentProcessor( BaseEditorDocumentProcessor *createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) final; TextEditor::TextDocument *baseTextDocument) final;
FollowSymbolInterface &followSymbolInterface() final;
RefactoringEngineInterface &refactoringEngineInterface() final; RefactoringEngineInterface &refactoringEngineInterface() final;
std::unique_ptr<AbstractOverviewModel> createOverviewModel() final; std::unique_ptr<AbstractOverviewModel> createOverviewModel() final;
FollowSymbolUnderCursor &followSymbolInterface() { return *m_followSymbol; }
private: private:
void followSymbol(const CursorInEditor &data, Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget, bool inNextSplit) override;
void switchDeclDef(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback) override;
QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider; QScopedPointer<CppCompletionAssistProvider> m_completionAssistProvider;
QScopedPointer<FollowSymbolInterface> m_followSymbol; QScopedPointer<FollowSymbolUnderCursor> m_followSymbol;
QScopedPointer<RefactoringEngineInterface> m_refactoringEngine; QScopedPointer<RefactoringEngineInterface> m_refactoringEngine;
}; };

View File

@@ -219,7 +219,6 @@ QtcPlugin {
"doxygengenerator.h", "doxygengenerator.h",
"editordocumenthandle.cpp", "editordocumenthandle.cpp",
"editordocumenthandle.h", "editordocumenthandle.h",
"followsymbolinterface.h",
"functionutils.cpp", "functionutils.cpp",
"functionutils.h", "functionutils.h",
"generatedcodemodelsupport.cpp", "generatedcodemodelsupport.cpp",

View File

@@ -50,7 +50,6 @@
#include "cpptoolssettings.h" #include "cpptoolssettings.h"
#include "cppuseselectionsupdater.h" #include "cppuseselectionsupdater.h"
#include "cppworkingcopy.h" #include "cppworkingcopy.h"
#include "followsymbolinterface.h"
#include "refactoringengineinterface.h" #include "refactoringengineinterface.h"
#include "symbolfinder.h" #include "symbolfinder.h"
@@ -1045,9 +1044,7 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
if (self && link.hasValidTarget()) if (self && link.hasValidTarget())
self->openLink(link, split); self->openLink(link, split);
}; };
followSymbolInterface().switchDeclDef(cursor, std::move(callback), CppModelManager::instance()->switchDeclDef(cursor, std::move(callback));
d->m_modelManager->snapshot(), d->m_lastSemanticInfo.doc,
d->m_modelManager->symbolFinder());
} }
void CppEditorWidget::findLinkAt(const QTextCursor &cursor, void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
@@ -1087,13 +1084,10 @@ void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
} }
callback(link); callback(link);
}; };
followSymbolInterface().findLink( CppModelManager::instance()->followSymbol(
CursorInEditor{cursor, filePath, this, textDocument()}, CursorInEditor{cursor, filePath, this, textDocument()},
std::move(callbackWrapper), std::move(callbackWrapper),
resolveTarget, resolveTarget,
d->m_modelManager->snapshot(),
d->m_lastSemanticInfo.doc,
d->m_modelManager->symbolFinder(),
inNextSplit); inNextSplit);
} }
@@ -1102,11 +1096,6 @@ unsigned CppEditorWidget::documentRevision() const
return document()->revision(); return document()->revision();
} }
FollowSymbolInterface &CppEditorWidget::followSymbolInterface() const
{
return d->m_modelManager->followSymbolInterface();
}
bool CppEditorWidget::isSemanticInfoValidExceptLocalUses() const bool CppEditorWidget::isSemanticInfoValidExceptLocalUses() const
{ {
return d->m_lastSemanticInfo.doc && d->m_lastSemanticInfo.revision == documentRevision() return d->m_lastSemanticInfo.doc && d->m_lastSemanticInfo.revision == documentRevision()

View File

@@ -38,7 +38,6 @@ class IAssistProvider;
} }
namespace CppEditor { namespace CppEditor {
class FollowSymbolInterface;
class SemanticInfo; class SemanticInfo;
class ProjectPart; class ProjectPart;
@@ -152,8 +151,6 @@ private:
QMenu *createRefactorMenu(QWidget *parent) const; QMenu *createRefactorMenu(QWidget *parent) const;
FollowSymbolInterface &followSymbolInterface() const;
const ProjectPart *projectPart() const; const ProjectPart *projectPart() const;
private: private:

View File

@@ -25,13 +25,18 @@
#pragma once #pragma once
#include "followsymbolinterface.h" #include "cppeditor_global.h"
#include "cursorineditor.h"
#include <cplusplus/CppDocument.h>
#include <texteditor/texteditor.h>
namespace CppEditor { namespace CppEditor {
class SymbolFinder;
class VirtualFunctionAssistProvider; class VirtualFunctionAssistProvider;
class CPPEDITOR_EXPORT FollowSymbolUnderCursor : public FollowSymbolInterface class CPPEDITOR_EXPORT FollowSymbolUnderCursor
{ {
public: public:
FollowSymbolUnderCursor(); FollowSymbolUnderCursor();
@@ -42,13 +47,13 @@ public:
const CPlusPlus::Snapshot &snapshot, const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo, const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder, SymbolFinder *symbolFinder,
bool inNextSplit) override; bool inNextSplit);
void switchDeclDef(const CursorInEditor &data, void switchDeclDef(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback, Utils::ProcessLinkCallback &&processLinkCallback,
const CPlusPlus::Snapshot &snapshot, const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo, const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder) override; SymbolFinder *symbolFinder);
QSharedPointer<VirtualFunctionAssistProvider> virtualFunctionAssistProvider(); QSharedPointer<VirtualFunctionAssistProvider> virtualFunctionAssistProvider();
void setVirtualFunctionAssistProvider( void setVirtualFunctionAssistProvider(

View File

@@ -48,7 +48,6 @@
#include "stringtable.h" #include "stringtable.h"
#include "symbolfinder.h" #include "symbolfinder.h"
#include "symbolsfindfilter.h" #include "symbolsfindfilter.h"
#include "followsymbolinterface.h"
#include <coreplugin/documentmanager.h> #include <coreplugin/documentmanager.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
@@ -348,20 +347,6 @@ void CppModelManager::findUsages(const CursorInEditor &data,
engine->findUsages(data, std::move(showUsagesCallback)); engine->findUsages(data, std::move(showUsagesCallback));
} }
void CppModelManager::globalFollowSymbol(
const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const
{
RefactoringEngineInterface *engine = getRefactoringEngine(d->m_refactoringEngines);
QTC_ASSERT(engine, return;);
engine->globalFollowSymbol(data, std::move(processLinkCallback), snapshot, documentFromSemanticInfo,
symbolFinder, inNextSplit);
}
bool CppModelManager::positionRequiresSignal(const QString &filePath, const QByteArray &content, bool CppModelManager::positionRequiresSignal(const QString &filePath, const QByteArray &content,
int position) const int position) const
{ {
@@ -487,9 +472,10 @@ RefactoringEngineInterface *CppModelManager::builtinRefactoringEngine()
return instance()->d->m_refactoringEngines.value(RefactoringEngineType::BuiltIn); return instance()->d->m_refactoringEngines.value(RefactoringEngineType::BuiltIn);
} }
FollowSymbolInterface &CppModelManager::builtinFollowSymbol() FollowSymbolUnderCursor &CppModelManager::builtinFollowSymbol()
{ {
return instance()->d->m_builtinModelManagerSupport->followSymbolInterface(); return instance()->d->m_builtinModelManagerSupport.staticCast<BuiltinModelManagerSupport>()
->followSymbolInterface();
} }
template<class FilterClass> template<class FilterClass>
@@ -560,11 +546,6 @@ Core::ILocatorFilter *CppModelManager::currentDocumentFilter() const
return d->m_currentDocumentFilter.get(); return d->m_currentDocumentFilter.get();
} }
FollowSymbolInterface &CppModelManager::followSymbolInterface() const
{
return d->m_activeModelManagerSupport->followSymbolInterface();
}
std::unique_ptr<AbstractOverviewModel> CppModelManager::createOverviewModel() const std::unique_ptr<AbstractOverviewModel> CppModelManager::createOverviewModel() const
{ {
return d->m_activeModelManagerSupport->createOverviewModel(); return d->m_activeModelManagerSupport->createOverviewModel();
@@ -1680,6 +1661,20 @@ TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler() const
return d->m_activeModelManagerSupport->createHoverHandler(); return d->m_activeModelManagerSupport->createHoverHandler();
} }
void CppModelManager::followSymbol(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget, bool inNextSplit)
{
d->m_activeModelManagerSupport->followSymbol(data, std::move(processLinkCallback),
resolveTarget, inNextSplit);
}
void CppModelManager::switchDeclDef(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback)
{
d->m_activeModelManagerSupport->switchDeclDef(data, std::move(processLinkCallback));
}
BaseEditorDocumentProcessor *CppModelManager::createEditorDocumentProcessor( BaseEditorDocumentProcessor *CppModelManager::createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) const TextEditor::TextDocument *baseTextDocument) const
{ {

View File

@@ -60,8 +60,8 @@ class CppCompletionAssistProvider;
class CppEditorDocumentHandle; class CppEditorDocumentHandle;
class CppIndexingSupport; class CppIndexingSupport;
class CppLocatorData; class CppLocatorData;
class FollowSymbolUnderCursor;
class ModelManagerSupportProvider; class ModelManagerSupportProvider;
class FollowSymbolInterface;
class SymbolFinder; class SymbolFinder;
class WorkingCopy; class WorkingCopy;
@@ -162,12 +162,6 @@ public:
const QString &replacement) final; const QString &replacement) final;
void findUsages(const CursorInEditor &data, void findUsages(const CursorInEditor &data,
UsagesCallback &&showUsagesCallback) const final; UsagesCallback &&showUsagesCallback) const final;
void globalFollowSymbol(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
const CPlusPlus::Snapshot &snapshot,
const Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const final;
bool positionRequiresSignal(const QString &filePath, const QByteArray &content, bool positionRequiresSignal(const QString &filePath, const QByteArray &content,
int position) const; int position) const;
@@ -187,7 +181,12 @@ public:
BaseEditorDocumentProcessor *createEditorDocumentProcessor( BaseEditorDocumentProcessor *createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) const; TextEditor::TextDocument *baseTextDocument) const;
TextEditor::BaseHoverHandler *createHoverHandler() const; TextEditor::BaseHoverHandler *createHoverHandler() const;
FollowSymbolInterface &followSymbolInterface() const; static FollowSymbolUnderCursor &builtinFollowSymbol();
void followSymbol(const CursorInEditor &data, Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget, bool inNextSplit);
void switchDeclDef(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback);
std::unique_ptr<AbstractOverviewModel> createOverviewModel() const; std::unique_ptr<AbstractOverviewModel> createOverviewModel() const;
CppIndexingSupport *indexingSupport(); CppIndexingSupport *indexingSupport();
@@ -217,7 +216,6 @@ public:
RefactoringEngineInterface *refactoringEngine); RefactoringEngineInterface *refactoringEngine);
static void removeRefactoringEngine(RefactoringEngineType type); static void removeRefactoringEngine(RefactoringEngineType type);
static RefactoringEngineInterface *builtinRefactoringEngine(); static RefactoringEngineInterface *builtinRefactoringEngine();
static FollowSymbolInterface &builtinFollowSymbol();
void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); void setLocatorFilter(std::unique_ptr<Core::ILocatorFilter> &&filter);
void setClassesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter); void setClassesFilter(std::unique_ptr<Core::ILocatorFilter> &&filter);

View File

@@ -27,6 +27,8 @@
#include "cppeditor_global.h" #include "cppeditor_global.h"
#include <utils/link.h>
#include <QSharedPointer> #include <QSharedPointer>
#include <QString> #include <QString>
@@ -42,7 +44,7 @@ namespace CppEditor {
class AbstractOverviewModel; class AbstractOverviewModel;
class BaseEditorDocumentProcessor; class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider; class CppCompletionAssistProvider;
class FollowSymbolInterface; class CursorInEditor;
class RefactoringEngineInterface; class RefactoringEngineInterface;
class CPPEDITOR_EXPORT ModelManagerSupport class CPPEDITOR_EXPORT ModelManagerSupport
@@ -58,11 +60,16 @@ public:
virtual TextEditor::BaseHoverHandler *createHoverHandler() = 0; virtual TextEditor::BaseHoverHandler *createHoverHandler() = 0;
virtual BaseEditorDocumentProcessor *createEditorDocumentProcessor( virtual BaseEditorDocumentProcessor *createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) = 0; TextEditor::TextDocument *baseTextDocument) = 0;
virtual FollowSymbolInterface &followSymbolInterface() = 0;
virtual RefactoringEngineInterface &refactoringEngineInterface() = 0; virtual RefactoringEngineInterface &refactoringEngineInterface() = 0;
virtual std::unique_ptr<AbstractOverviewModel> createOverviewModel() = 0; virtual std::unique_ptr<AbstractOverviewModel> createOverviewModel() = 0;
virtual bool supportsOutline(const TextEditor::TextDocument *) const { return true; } virtual bool supportsOutline(const TextEditor::TextDocument *) const { return true; }
virtual bool supportsLocalUses(const TextEditor::TextDocument *) const { return true; } virtual bool supportsLocalUses(const TextEditor::TextDocument *) const { return true; }
virtual void followSymbol(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget, bool inNextSplit) = 0;
virtual void switchDeclDef(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback) = 0;
}; };
class CPPEDITOR_EXPORT ModelManagerSupportProvider class CPPEDITOR_EXPORT ModelManagerSupportProvider

View File

@@ -103,17 +103,4 @@ void CppRefactoringEngine::findUsages(const CursorInEditor &data,
} }
} }
void CppRefactoringEngine::globalFollowSymbol(
const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const
{
FollowSymbolUnderCursor followSymbol;
return followSymbol.findLink(data, std::move(processLinkCallback), true, snapshot,
documentFromSemanticInfo, symbolFinder, inNextSplit);
}
} // namespace CppEditor::Internal } // namespace CppEditor::Internal

View File

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

View File

@@ -350,9 +350,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
switch (action) { switch (action) {
case FollowSymbolUnderCursorAction: { case FollowSymbolUnderCursorAction: {
CppEditorWidget *widget = initialTestFile->m_editorWidget; CppEditorWidget *widget = initialTestFile->m_editorWidget;
FollowSymbolInterface &delegate = CppModelManager::instance()->followSymbolInterface(); if (CppModelManager::instance()->isClangCodeModelActive()) {
auto* builtinFollowSymbol = dynamic_cast<FollowSymbolUnderCursor *>(&delegate);
if (!builtinFollowSymbol) {
if (curTestName == "testFollowSymbolQTCREATORBUG7903") if (curTestName == "testFollowSymbolQTCREATORBUG7903")
QSKIP((curTestName + " is not supported by Clang FollowSymbol").toLatin1()); QSKIP((curTestName + " is not supported by Clang FollowSymbol").toLatin1());
widget->enableTestMode(); widget->enableTestMode();
@@ -360,6 +358,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
break; break;
} }
FollowSymbolUnderCursor *builtinFollowSymbol = &CppModelManager::builtinFollowSymbol();
QSharedPointer<VirtualFunctionAssistProvider> original QSharedPointer<VirtualFunctionAssistProvider> original
= builtinFollowSymbol->virtualFunctionAssistProvider(); = builtinFollowSymbol->virtualFunctionAssistProvider();

View File

@@ -1,59 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "cppeditor_global.h"
#include "cursorineditor.h"
#include <cplusplus/CppDocument.h>
#include <texteditor/texteditor.h>
namespace CppEditor {
class SymbolFinder;
class CPPEDITOR_EXPORT FollowSymbolInterface
{
public:
using Link = Utils::Link;
virtual ~FollowSymbolInterface() = default;
virtual void findLink(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
bool resolveTarget,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) = 0;
virtual void switchDeclDef(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder) = 0;
};
} // namespace CppEditor

View File

@@ -67,12 +67,6 @@ public:
const QString &replacement) = 0; const QString &replacement) = 0;
virtual void findUsages(const CursorInEditor &data, virtual void findUsages(const CursorInEditor &data,
UsagesCallback &&showUsagesCallback) const = 0; UsagesCallback &&showUsagesCallback) const = 0;
virtual void globalFollowSymbol(const CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback,
const CPlusPlus::Snapshot &snapshot,
const CPlusPlus::Document::Ptr &documentFromSemanticInfo,
SymbolFinder *symbolFinder,
bool inNextSplit) const = 0;
virtual bool isRefactoringEngineAvailable() const { return true; } virtual bool isRefactoringEngineAvailable() const { return true; }
}; };