ClangCodeModel: Remove libclang-based tooltip support

Change-Id: I63d934fc3d480e3c5198e7db1a595b3309e89533
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2022-04-27 16:36:22 +02:00
parent 7cef593ec0
commit 52d9def5e9
10 changed files with 21 additions and 295 deletions

View File

@@ -38,7 +38,6 @@ add_qtc_plugin(ClangCodeModel
clangfunctionhintmodel.cpp clangfunctionhintmodel.h clangfunctionhintmodel.cpp clangfunctionhintmodel.h
clangdlocatorfilters.cpp clangdlocatorfilters.h clangdlocatorfilters.cpp clangdlocatorfilters.h
clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h
clanghoverhandler.cpp clanghoverhandler.h
clangisdiagnosticrelatedtolocation.h clangisdiagnosticrelatedtolocation.h
clangmodelmanagersupport.cpp clangmodelmanagersupport.h clangmodelmanagersupport.cpp clangmodelmanagersupport.h
clangoverviewmodel.cpp clangoverviewmodel.h clangoverviewmodel.cpp clangoverviewmodel.h

View File

@@ -82,8 +82,6 @@ QtcPlugin {
"clangfunctionhintmodel.h", "clangfunctionhintmodel.h",
"clanghighlightingresultreporter.cpp", "clanghighlightingresultreporter.cpp",
"clanghighlightingresultreporter.h", "clanghighlightingresultreporter.h",
"clanghoverhandler.cpp",
"clanghoverhandler.h",
"clangisdiagnosticrelatedtolocation.h", "clangisdiagnosticrelatedtolocation.h",
"clangmodelmanagersupport.cpp", "clangmodelmanagersupport.cpp",
"clangmodelmanagersupport.h", "clangmodelmanagersupport.h",

View File

@@ -1,227 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2018 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 "clanghoverhandler.h"
#include "clangeditordocumentprocessor.h"
#include "clangmodelmanagersupport.h"
#include <coreplugin/helpmanager.h>
#include <cppeditor/cppmodelmanager.h>
#include <cppeditor/cpptoolsreuse.h>
#include <cppeditor/editordocumenthandle.h>
#include <texteditor/texteditor.h>
#include <utils/qtcassert.h>
#include <utils/textutils.h>
#include <utils/tooltip/tooltip.h>
#include <QFutureWatcher>
#include <QLoggingCategory>
#include <QRegularExpression>
#include <QTextCodec>
#include <QVBoxLayout>
static Q_LOGGING_CATEGORY(hoverLog, "qtc.clangcodemodel.hover", QtWarningMsg);
using namespace TextEditor;
namespace ClangCodeModel {
namespace Internal {
static CppEditor::BaseEditorDocumentProcessor *editorDocumentProcessor(TextEditorWidget *editorWidget)
{
const QString filePath = editorWidget->textDocument()->filePath().toString();
auto cppModelManager = CppEditor::CppModelManager::instance();
CppEditor::CppEditorDocumentHandle *editorHandle = cppModelManager->cppEditorDocument(filePath);
if (editorHandle)
return editorHandle->processor();
return nullptr;
}
static TextMarks diagnosticTextMarksAt(TextEditorWidget *editorWidget, int position)
{
const auto processor = qobject_cast<ClangEditorDocumentProcessor *>(
editorDocumentProcessor(editorWidget));
QTC_ASSERT(processor, return TextMarks());
int line, column;
const bool ok = Utils::Text::convertPosition(editorWidget->document(), position, &line, &column);
QTC_ASSERT(ok, return TextMarks());
return processor->diagnosticTextMarksAt(line, column);
}
static QFuture<CppEditor::ToolTipInfo> editorDocumentHandlesToolTipInfo(
TextEditorWidget *editorWidget, int pos)
{
const QByteArray textCodecName = editorWidget->textDocument()->codec()->name();
if (CppEditor::BaseEditorDocumentProcessor *processor = editorDocumentProcessor(editorWidget)) {
int line, column;
if (Utils::Text::convertPosition(editorWidget->document(), pos, &line, &column))
return processor->toolTipInfo(textCodecName, line, column + 1);
}
return QFuture<CppEditor::ToolTipInfo>();
}
ClangHoverHandler::~ClangHoverHandler()
{
abort();
}
void ClangHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
int pos,
BaseHoverHandler::ReportPriority report)
{
if (ClangModelManagerSupport::instance()
->clientForFile(editorWidget->textDocument()->filePath())) {
report(Priority_None);
return;
}
// Reset
m_futureWatcher.reset();
m_cursorPosition = -1;
// Check for diagnostics (sync)
if (!isContextHelpRequest() && !diagnosticTextMarksAt(editorWidget, pos).isEmpty()) {
qCDebug(hoverLog) << "Checking for diagnostic at" << pos;
setPriority(Priority_Diagnostic);
m_cursorPosition = pos;
}
// Check for tooltips (async)
QFuture<CppEditor::ToolTipInfo> future = editorDocumentHandlesToolTipInfo(editorWidget, pos);
if (QTC_GUARD(future.isRunning())) {
qCDebug(hoverLog) << "Requesting tooltip info at" << pos;
m_reportPriority = report;
m_futureWatcher.reset(new QFutureWatcher<CppEditor::ToolTipInfo>());
QTextCursor tc(editorWidget->document());
tc.setPosition(pos);
const QStringList fallback = CppEditor::identifierWordsUnderCursor(tc);
QObject::connect(m_futureWatcher.data(),
&QFutureWatcherBase::finished,
[this, fallback]() {
if (m_futureWatcher->isCanceled()) {
m_reportPriority(Priority_None);
} else {
CppEditor::ToolTipInfo info = m_futureWatcher->result();
qCDebug(hoverLog)
<< "Appending word-based fallback lookup" << fallback;
info.qDocIdCandidates += fallback;
processToolTipInfo(info);
}
});
m_futureWatcher->setFuture(future);
return;
}
report(priority()); // Ops, something went wrong.
}
void ClangHoverHandler::abort()
{
if (m_futureWatcher) {
m_futureWatcher->cancel();
m_futureWatcher.reset();
}
}
#define RETURN_TEXT_FOR_CASE(enumValue) case Core::HelpItem::enumValue: return #enumValue
static const char *helpItemCategoryAsString(Core::HelpItem::Category category)
{
switch (category) {
RETURN_TEXT_FOR_CASE(Unknown);
RETURN_TEXT_FOR_CASE(ClassOrNamespace);
RETURN_TEXT_FOR_CASE(Enum);
RETURN_TEXT_FOR_CASE(Typedef);
RETURN_TEXT_FOR_CASE(Macro);
RETURN_TEXT_FOR_CASE(Brief);
RETURN_TEXT_FOR_CASE(Function);
RETURN_TEXT_FOR_CASE(QmlComponent);
RETURN_TEXT_FOR_CASE(QmlProperty);
RETURN_TEXT_FOR_CASE(QMakeVariableOfFunction);
}
return "UnhandledHelpItemCategory";
}
#undef RETURN_TEXT_FOR_CASE
void ClangHoverHandler::processToolTipInfo(const CppEditor::ToolTipInfo &info)
{
qCDebug(hoverLog) << "Processing tooltip info" << info.text;
QString text = info.text;
if (!info.briefComment.isEmpty())
text.append("\n\n" + info.briefComment);
qCDebug(hoverLog) << "Querying help manager with"
<< info.qDocIdCandidates
<< info.qDocMark
<< helpItemCategoryAsString(info.qDocCategory);
setLastHelpItemIdentified({info.qDocIdCandidates, info.qDocMark, info.qDocCategory});
if (!info.sizeInBytes.isEmpty())
text.append("\n\n" + tr("%1 bytes").arg(info.sizeInBytes));
if (info.value.isValid()) {
QString value;
switch (info.value.type()) {
case static_cast<QVariant::Type>(QMetaType::LongLong):
value = QString::number(info.value.toLongLong());
break;
case static_cast<QVariant::Type>(QMetaType::ULongLong):
value = QString::number(info.value.toULongLong());
break;
case static_cast<QVariant::Type>(QMetaType::Double):
value = QString::number(info.value.toDouble());
break;
default:
QTC_CHECK(false);
}
text.append("\n\n" + tr("Value: %1").arg(value));
}
setToolTip(text);
m_reportPriority(priority());
}
void ClangHoverHandler::operateTooltip(TextEditor::TextEditorWidget *editorWidget,
const QPoint &point)
{
if (priority() == Priority_Diagnostic) {
const TextMarks textMarks = diagnosticTextMarksAt(editorWidget, m_cursorPosition);
editorWidget->showTextMarksToolTip(point, textMarks);
return;
}
// Priority_Tooltip / Priority_Help
BaseHoverHandler::operateTooltip(editorWidget, point);
}
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -1,57 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2018 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/baseeditordocumentprocessor.h>
#include <texteditor/basehoverhandler.h>
namespace ClangCodeModel {
namespace Internal {
class ClangHoverHandler final : public TextEditor::BaseHoverHandler
{
Q_DECLARE_TR_FUNCTIONS(ClangHoverHandler)
public:
~ClangHoverHandler() override;
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
int pos,
ReportPriority report) override;
void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point) override;
private:
void abort() override;
void processToolTipInfo(const CppEditor::ToolTipInfo &info);
private:
int m_cursorPosition = -1;
QScopedPointer<QFutureWatcher<CppEditor::ToolTipInfo>> m_futureWatcher;
ReportPriority m_reportPriority;
};
} // namespace Internal
} // namespace ClangCodeModel

View File

@@ -30,7 +30,6 @@
#include "clangdquickfixfactory.h" #include "clangdquickfixfactory.h"
#include "clangeditordocumentprocessor.h" #include "clangeditordocumentprocessor.h"
#include "clangdlocatorfilters.h" #include "clangdlocatorfilters.h"
#include "clanghoverhandler.h"
#include "clangoverviewmodel.h" #include "clangoverviewmodel.h"
#include "clangprojectsettings.h" #include "clangprojectsettings.h"
#include "clangrefactoringengine.h" #include "clangrefactoringengine.h"
@@ -183,11 +182,6 @@ CppEditor::CppCompletionAssistProvider *ClangModelManagerSupport::functionHintAs
return &m_functionHintAssistProvider; return &m_functionHintAssistProvider;
} }
TextEditor::BaseHoverHandler *ClangModelManagerSupport::createHoverHandler()
{
return new Internal::ClangHoverHandler;
}
void ClangModelManagerSupport::followSymbol(const CppEditor::CursorInEditor &data, void ClangModelManagerSupport::followSymbol(const CppEditor::CursorInEditor &data,
Utils::ProcessLinkCallback &&processLinkCallback, bool resolveTarget, Utils::ProcessLinkCallback &&processLinkCallback, bool resolveTarget,
bool inNextSplit) bool inNextSplit)
@@ -241,6 +235,12 @@ bool ClangModelManagerSupport::supportsLocalUses(const TextEditor::TextDocument
return !clientForFile(document->filePath()); return !clientForFile(document->filePath());
} }
bool ClangModelManagerSupport::hasSpecialHoverHandler(
const TextEditor::TextDocument *document) const
{
return clientForFile(document->filePath());
}
CppEditor::BaseEditorDocumentProcessor *ClangModelManagerSupport::createEditorDocumentProcessor( CppEditor::BaseEditorDocumentProcessor *ClangModelManagerSupport::createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) TextEditor::TextDocument *baseTextDocument)
{ {

View File

@@ -65,13 +65,14 @@ public:
CppEditor::CppCompletionAssistProvider *completionAssistProvider() override; CppEditor::CppCompletionAssistProvider *completionAssistProvider() override;
CppEditor::CppCompletionAssistProvider *functionHintAssistProvider() override; CppEditor::CppCompletionAssistProvider *functionHintAssistProvider() override;
TextEditor::BaseHoverHandler *createHoverHandler() override; TextEditor::BaseHoverHandler *createHoverHandler() override { return nullptr; }
CppEditor::BaseEditorDocumentProcessor *createEditorDocumentProcessor( CppEditor::BaseEditorDocumentProcessor *createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument) override; TextEditor::TextDocument *baseTextDocument) 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;
bool supportsLocalUses(const TextEditor::TextDocument *document) const override; bool supportsLocalUses(const TextEditor::TextDocument *document) const override;
bool hasSpecialHoverHandler(const TextEditor::TextDocument *document) const override;
BackendCommunicator &communicator(); BackendCommunicator &communicator();
QString dummyUiHeaderOnDiskDirPath() const; QString dummyUiHeaderOnDiskDirPath() const;

View File

@@ -53,6 +53,11 @@ private:
int pos, int pos,
ReportPriority report) override ReportPriority report) override
{ {
if (CppModelManager::hasSpecialHoverHandler(editorWidget->textDocument())) {
report(Priority_None);
return;
}
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); }); Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
QTextCursor tc(editorWidget->document()); QTextCursor tc(editorWidget->document());

View File

@@ -1307,6 +1307,11 @@ bool CppModelManager::supportsLocalUses(const TextEditor::TextDocument *document
return instance()->d->m_activeModelManagerSupport->supportsLocalUses(document); return instance()->d->m_activeModelManagerSupport->supportsLocalUses(document);
} }
bool CppModelManager::hasSpecialHoverHandler(const TextEditor::TextDocument *document)
{
return instance()->d->m_activeModelManagerSupport->hasSpecialHoverHandler(document);
}
bool CppModelManager::isClangCodeModelActive() const bool CppModelManager::isClangCodeModelActive() const
{ {
return d->m_activeModelManagerSupport != d->m_builtinModelManagerSupport; return d->m_activeModelManagerSupport != d->m_builtinModelManagerSupport;
@@ -1658,7 +1663,7 @@ CppCompletionAssistProvider *CppModelManager::functionHintAssistProvider() const
TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler() const TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler() const
{ {
return d->m_activeModelManagerSupport->createHoverHandler(); return d->m_builtinModelManagerSupport->createHoverHandler();
} }
void CppModelManager::followSymbol(const CursorInEditor &data, void CppModelManager::followSymbol(const CursorInEditor &data,

View File

@@ -141,6 +141,7 @@ public:
static bool isCppEditor(Core::IEditor *editor); static bool isCppEditor(Core::IEditor *editor);
static bool supportsOutline(const TextEditor::TextDocument *document); static bool supportsOutline(const TextEditor::TextDocument *document);
static bool supportsLocalUses(const TextEditor::TextDocument *document); static bool supportsLocalUses(const TextEditor::TextDocument *document);
static bool hasSpecialHoverHandler(const TextEditor::TextDocument *document);
bool isClangCodeModelActive() const; bool isClangCodeModelActive() const;
QSet<AbstractEditorSupport*> abstractEditorSupports() const; QSet<AbstractEditorSupport*> abstractEditorSupports() const;

View File

@@ -63,6 +63,7 @@ public:
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 hasSpecialHoverHandler(const TextEditor::TextDocument *) const { return false; }
virtual bool supportsLocalUses(const TextEditor::TextDocument *) const { return true; } virtual bool supportsLocalUses(const TextEditor::TextDocument *) const { return true; }
virtual void followSymbol(const CursorInEditor &data, virtual void followSymbol(const CursorInEditor &data,