forked from qt-creator/qt-creator
ClangCodeModel: Fall back to built-in code model when following symbols
In normal interactive mode, users likely want fuzzy look-up, e.g. to a non-matching overload if no exact match is present. Fixes: QTCREATORBUG-29814 Change-Id: I55ca32c001e619d374cc015a7dd2f1564ed2a2c9 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -199,8 +199,7 @@ void ClangdFollowSymbol::emitDone(const Link &link)
|
||||
return;
|
||||
|
||||
d->done = true;
|
||||
if (link.hasValidTarget())
|
||||
d->callback(link);
|
||||
d->callback(link);
|
||||
emit done();
|
||||
}
|
||||
|
||||
|
@@ -53,6 +53,7 @@
|
||||
#include <QLabel>
|
||||
#include <QLoggingCategory>
|
||||
#include <QMenu>
|
||||
#include <QPointer>
|
||||
#include <QTextBlock>
|
||||
#include <QTimer>
|
||||
#include <QtDebug>
|
||||
@@ -299,17 +300,27 @@ ClangModelManagerSupport::~ClangModelManagerSupport()
|
||||
|
||||
void ClangModelManagerSupport::followSymbol(const CursorInEditor &data,
|
||||
const LinkHandler &processLinkCallback,
|
||||
FollowSymbolMode mode,
|
||||
bool resolveTarget, bool inNextSplit)
|
||||
{
|
||||
if (ClangdClient * const client = clientForFile(data.filePath());
|
||||
client && client->isFullyIndexed()) {
|
||||
LinkHandler extendedCallback = [editor = QPointer(data.editorWidget()), data,
|
||||
processLinkCallback, mode, resolveTarget, inNextSplit]
|
||||
(const Link &link) {
|
||||
if (link.hasValidTarget() || mode == FollowSymbolMode::Exact || !editor)
|
||||
return processLinkCallback(link);
|
||||
CppModelManager::followSymbol(data, processLinkCallback, resolveTarget, inNextSplit,
|
||||
mode, CppModelManager::Backend::Builtin);
|
||||
|
||||
};
|
||||
client->followSymbol(data.textDocument(), data.cursor(), data.editorWidget(),
|
||||
processLinkCallback, resolveTarget, FollowTo::SymbolDef, inNextSplit);
|
||||
extendedCallback, resolveTarget, FollowTo::SymbolDef, inNextSplit);
|
||||
return;
|
||||
}
|
||||
|
||||
CppModelManager::followSymbol(data, processLinkCallback, resolveTarget, inNextSplit,
|
||||
CppModelManager::Backend::Builtin);
|
||||
mode, CppModelManager::Backend::Builtin);
|
||||
}
|
||||
|
||||
void ClangModelManagerSupport::followSymbolToType(const CursorInEditor &data,
|
||||
|
@@ -52,8 +52,9 @@ public:
|
||||
|
||||
private:
|
||||
void followSymbol(const CppEditor::CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback, bool resolveTarget,
|
||||
bool inNextSplit) override;
|
||||
const Utils::LinkHandler &processLinkCallback,
|
||||
CppEditor::FollowSymbolMode mode,
|
||||
bool resolveTarget, bool inNextSplit) override;
|
||||
void followSymbolToType(const CppEditor::CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback,
|
||||
bool inNextSplit) override;
|
||||
|
@@ -101,8 +101,13 @@ TextEditor::BaseHoverHandler *BuiltinModelManagerSupport::createHoverHandler()
|
||||
|
||||
void BuiltinModelManagerSupport::followSymbol(const CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback,
|
||||
FollowSymbolMode mode,
|
||||
bool resolveTarget, bool inNextSplit)
|
||||
{
|
||||
// findMatchingDefinition() has an "strict" parameter, but it doesn't seem worth to
|
||||
// pass the mode down all the way. In practice, we are always fuzzy.
|
||||
Q_UNUSED(mode)
|
||||
|
||||
SymbolFinder finder;
|
||||
m_followSymbol->findLink(data, processLinkCallback,
|
||||
resolveTarget, CppModelManager::snapshot(),
|
||||
|
@@ -29,7 +29,7 @@ public:
|
||||
|
||||
private:
|
||||
void followSymbol(const CursorInEditor &data, const Utils::LinkHandler &processLinkCallback,
|
||||
bool resolveTarget, bool inNextSplit) override;
|
||||
FollowSymbolMode mode, bool resolveTarget, bool inNextSplit) override;
|
||||
void followSymbolToType(const CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback,
|
||||
bool inNextSplit) override;
|
||||
|
@@ -625,7 +625,7 @@ void CppEditorWidget::renameUsages(const QString &replacement, QTextCursor curso
|
||||
};
|
||||
CppModelManager::followSymbol(
|
||||
CursorInEditor{cursor, textDocument()->filePath(), this, textDocument()},
|
||||
continuation, true, false);
|
||||
continuation, true, false, FollowSymbolMode::Exact);
|
||||
}
|
||||
|
||||
void CppEditorWidget::renameUsages(const Utils::FilePath &filePath, const QString &replacement,
|
||||
@@ -986,7 +986,8 @@ void CppEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
CppModelManager::followSymbol(CursorInEditor{cursor, filePath, this, textDocument()},
|
||||
callbackWrapper,
|
||||
resolveTarget,
|
||||
inNextSplit);
|
||||
inNextSplit,
|
||||
FollowSymbolMode::Fuzzy);
|
||||
}
|
||||
|
||||
void CppEditorWidget::findTypeAt(const QTextCursor &cursor,
|
||||
|
@@ -2065,10 +2065,11 @@ TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler()
|
||||
|
||||
void CppModelManager::followSymbol(const CursorInEditor &data,
|
||||
const LinkHandler &processLinkCallback,
|
||||
bool resolveTarget, bool inNextSplit, Backend backend)
|
||||
bool resolveTarget, bool inNextSplit,
|
||||
FollowSymbolMode mode, Backend backend)
|
||||
{
|
||||
modelManagerSupport(backend)->followSymbol(data, processLinkCallback,
|
||||
resolveTarget, inNextSplit);
|
||||
modelManagerSupport(backend)->followSymbol(data, processLinkCallback, mode,
|
||||
resolveTarget, inNextSplit);
|
||||
}
|
||||
|
||||
void CppModelManager::followSymbolToType(const CursorInEditor &data,
|
||||
|
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "cppeditor_global.h"
|
||||
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "cursorineditor.h"
|
||||
#include "projectinfo.h"
|
||||
#include "projectpart.h"
|
||||
@@ -174,7 +175,8 @@ public:
|
||||
enum class Backend { Builtin, Best };
|
||||
static void followSymbol(const CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback,
|
||||
bool resolveTarget, bool inNextSplit, Backend backend = Backend::Best);
|
||||
bool resolveTarget, bool inNextSplit,
|
||||
FollowSymbolMode mode, Backend backend = Backend::Best);
|
||||
static void followSymbolToType(const CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback, bool inNextSplit,
|
||||
Backend backend = Backend::Best);
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "cppeditor_global.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "cursorineditor.h"
|
||||
|
||||
#include <utils/link.h>
|
||||
@@ -12,7 +13,6 @@
|
||||
#include <QString>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace Core { class SearchResult; }
|
||||
namespace TextEditor {
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
|
||||
virtual void followSymbol(const CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback,
|
||||
FollowSymbolMode mode,
|
||||
bool resolveTarget, bool inNextSplit) = 0;
|
||||
virtual void followSymbolToType(const CursorInEditor &data,
|
||||
const Utils::LinkHandler &processLinkCallback,
|
||||
|
@@ -3017,6 +3017,7 @@ void AddDeclarationForUndeclaredIdentifier::match(const CppQuickFixInterface &in
|
||||
collectOperations(interface, result);
|
||||
};
|
||||
CppModelManager::followSymbol(cursorInEditor, followSymbolFallback, false, false,
|
||||
FollowSymbolMode::Exact,
|
||||
CppModelManager::Backend::Builtin);
|
||||
}
|
||||
|
||||
@@ -9649,7 +9650,8 @@ private:
|
||||
(const Link &link) {
|
||||
moveComments(link, symbolLoc, comments);
|
||||
};
|
||||
CppModelManager::followSymbol(cursorInEditor, callback, true, false);
|
||||
CppModelManager::followSymbol(cursorInEditor, callback, true, false,
|
||||
FollowSymbolMode::Exact);
|
||||
}
|
||||
|
||||
static void moveComments(const Link &targetLoc, const Link &symbolLoc,
|
||||
|
@@ -33,6 +33,8 @@ class CppRefactoringFile;
|
||||
class ProjectInfo;
|
||||
class CppCompletionAssistProcessor;
|
||||
|
||||
enum class FollowSymbolMode { Exact, Fuzzy };
|
||||
|
||||
void CPPEDITOR_EXPORT moveCursorToEndOfIdentifier(QTextCursor *tc);
|
||||
void CPPEDITOR_EXPORT moveCursorToStartOfIdentifier(QTextCursor *tc);
|
||||
|
||||
|
Reference in New Issue
Block a user