From 52d9def5e97c10b2dcd09f21ed1ea4c994ddf767 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 27 Apr 2022 16:36:22 +0200 Subject: [PATCH] ClangCodeModel: Remove libclang-based tooltip support Change-Id: I63d934fc3d480e3c5198e7db1a595b3309e89533 Reviewed-by: Reviewed-by: Qt CI Bot Reviewed-by: David Schulz --- src/plugins/clangcodemodel/CMakeLists.txt | 1 - src/plugins/clangcodemodel/clangcodemodel.qbs | 2 - .../clangcodemodel/clanghoverhandler.cpp | 227 ------------------ .../clangcodemodel/clanghoverhandler.h | 57 ----- .../clangmodelmanagersupport.cpp | 12 +- .../clangcodemodel/clangmodelmanagersupport.h | 3 +- .../cppbuiltinmodelmanagersupport.cpp | 5 + src/plugins/cppeditor/cppmodelmanager.cpp | 7 +- src/plugins/cppeditor/cppmodelmanager.h | 1 + .../cppeditor/cppmodelmanagersupport.h | 1 + 10 files changed, 21 insertions(+), 295 deletions(-) delete mode 100644 src/plugins/clangcodemodel/clanghoverhandler.cpp delete mode 100644 src/plugins/clangcodemodel/clanghoverhandler.h diff --git a/src/plugins/clangcodemodel/CMakeLists.txt b/src/plugins/clangcodemodel/CMakeLists.txt index 153bc4ae62d..52349f1dd20 100644 --- a/src/plugins/clangcodemodel/CMakeLists.txt +++ b/src/plugins/clangcodemodel/CMakeLists.txt @@ -38,7 +38,6 @@ add_qtc_plugin(ClangCodeModel clangfunctionhintmodel.cpp clangfunctionhintmodel.h clangdlocatorfilters.cpp clangdlocatorfilters.h clanghighlightingresultreporter.cpp clanghighlightingresultreporter.h - clanghoverhandler.cpp clanghoverhandler.h clangisdiagnosticrelatedtolocation.h clangmodelmanagersupport.cpp clangmodelmanagersupport.h clangoverviewmodel.cpp clangoverviewmodel.h diff --git a/src/plugins/clangcodemodel/clangcodemodel.qbs b/src/plugins/clangcodemodel/clangcodemodel.qbs index f6a62d42cb9..6cc695f233f 100644 --- a/src/plugins/clangcodemodel/clangcodemodel.qbs +++ b/src/plugins/clangcodemodel/clangcodemodel.qbs @@ -82,8 +82,6 @@ QtcPlugin { "clangfunctionhintmodel.h", "clanghighlightingresultreporter.cpp", "clanghighlightingresultreporter.h", - "clanghoverhandler.cpp", - "clanghoverhandler.h", "clangisdiagnosticrelatedtolocation.h", "clangmodelmanagersupport.cpp", "clangmodelmanagersupport.h", diff --git a/src/plugins/clangcodemodel/clanghoverhandler.cpp b/src/plugins/clangcodemodel/clanghoverhandler.cpp deleted file mode 100644 index 10e3524db41..00000000000 --- a/src/plugins/clangcodemodel/clanghoverhandler.cpp +++ /dev/null @@ -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 -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -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( - 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 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(); -} - -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 future = editorDocumentHandlesToolTipInfo(editorWidget, pos); - if (QTC_GUARD(future.isRunning())) { - qCDebug(hoverLog) << "Requesting tooltip info at" << pos; - m_reportPriority = report; - m_futureWatcher.reset(new QFutureWatcher()); - 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(QMetaType::LongLong): - value = QString::number(info.value.toLongLong()); - break; - case static_cast(QMetaType::ULongLong): - value = QString::number(info.value.toULongLong()); - break; - case static_cast(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 diff --git a/src/plugins/clangcodemodel/clanghoverhandler.h b/src/plugins/clangcodemodel/clanghoverhandler.h deleted file mode 100644 index 90ae5f05955..00000000000 --- a/src/plugins/clangcodemodel/clanghoverhandler.h +++ /dev/null @@ -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 -#include - -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> m_futureWatcher; - ReportPriority m_reportPriority; -}; - -} // namespace Internal -} // namespace ClangCodeModel diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp index fe7ddcf4cdb..610619a9d11 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.cpp @@ -30,7 +30,6 @@ #include "clangdquickfixfactory.h" #include "clangeditordocumentprocessor.h" #include "clangdlocatorfilters.h" -#include "clanghoverhandler.h" #include "clangoverviewmodel.h" #include "clangprojectsettings.h" #include "clangrefactoringengine.h" @@ -183,11 +182,6 @@ CppEditor::CppCompletionAssistProvider *ClangModelManagerSupport::functionHintAs return &m_functionHintAssistProvider; } -TextEditor::BaseHoverHandler *ClangModelManagerSupport::createHoverHandler() -{ - return new Internal::ClangHoverHandler; -} - void ClangModelManagerSupport::followSymbol(const CppEditor::CursorInEditor &data, Utils::ProcessLinkCallback &&processLinkCallback, bool resolveTarget, bool inNextSplit) @@ -241,6 +235,12 @@ bool ClangModelManagerSupport::supportsLocalUses(const TextEditor::TextDocument return !clientForFile(document->filePath()); } +bool ClangModelManagerSupport::hasSpecialHoverHandler( + const TextEditor::TextDocument *document) const +{ + return clientForFile(document->filePath()); +} + CppEditor::BaseEditorDocumentProcessor *ClangModelManagerSupport::createEditorDocumentProcessor( TextEditor::TextDocument *baseTextDocument) { diff --git a/src/plugins/clangcodemodel/clangmodelmanagersupport.h b/src/plugins/clangcodemodel/clangmodelmanagersupport.h index 06355f8ab2b..99d21b9bc94 100644 --- a/src/plugins/clangcodemodel/clangmodelmanagersupport.h +++ b/src/plugins/clangcodemodel/clangmodelmanagersupport.h @@ -65,13 +65,14 @@ public: CppEditor::CppCompletionAssistProvider *completionAssistProvider() override; CppEditor::CppCompletionAssistProvider *functionHintAssistProvider() override; - TextEditor::BaseHoverHandler *createHoverHandler() override; + TextEditor::BaseHoverHandler *createHoverHandler() override { return nullptr; } CppEditor::BaseEditorDocumentProcessor *createEditorDocumentProcessor( TextEditor::TextDocument *baseTextDocument) override; CppEditor::RefactoringEngineInterface &refactoringEngineInterface() override; std::unique_ptr createOverviewModel() override; bool supportsOutline(const TextEditor::TextDocument *document) const override; bool supportsLocalUses(const TextEditor::TextDocument *document) const override; + bool hasSpecialHoverHandler(const TextEditor::TextDocument *document) const override; BackendCommunicator &communicator(); QString dummyUiHeaderOnDiskDirPath() const; diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp index 317a1edf846..ed9defff588 100644 --- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp +++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp @@ -53,6 +53,11 @@ private: int pos, ReportPriority report) override { + if (CppModelManager::hasSpecialHoverHandler(editorWidget->textDocument())) { + report(Priority_None); + return; + } + Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); }); QTextCursor tc(editorWidget->document()); diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index 8a94e9bb19b..3ade5912bd9 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -1307,6 +1307,11 @@ bool CppModelManager::supportsLocalUses(const TextEditor::TextDocument *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 { return d->m_activeModelManagerSupport != d->m_builtinModelManagerSupport; @@ -1658,7 +1663,7 @@ CppCompletionAssistProvider *CppModelManager::functionHintAssistProvider() const TextEditor::BaseHoverHandler *CppModelManager::createHoverHandler() const { - return d->m_activeModelManagerSupport->createHoverHandler(); + return d->m_builtinModelManagerSupport->createHoverHandler(); } void CppModelManager::followSymbol(const CursorInEditor &data, diff --git a/src/plugins/cppeditor/cppmodelmanager.h b/src/plugins/cppeditor/cppmodelmanager.h index 1c499479fd4..102a798b9f5 100644 --- a/src/plugins/cppeditor/cppmodelmanager.h +++ b/src/plugins/cppeditor/cppmodelmanager.h @@ -141,6 +141,7 @@ public: static bool isCppEditor(Core::IEditor *editor); static bool supportsOutline(const TextEditor::TextDocument *document); static bool supportsLocalUses(const TextEditor::TextDocument *document); + static bool hasSpecialHoverHandler(const TextEditor::TextDocument *document); bool isClangCodeModelActive() const; QSet abstractEditorSupports() const; diff --git a/src/plugins/cppeditor/cppmodelmanagersupport.h b/src/plugins/cppeditor/cppmodelmanagersupport.h index 29c258a1a09..ca4f3f050d7 100644 --- a/src/plugins/cppeditor/cppmodelmanagersupport.h +++ b/src/plugins/cppeditor/cppmodelmanagersupport.h @@ -63,6 +63,7 @@ public: virtual RefactoringEngineInterface &refactoringEngineInterface() = 0; virtual std::unique_ptr createOverviewModel() = 0; 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 void followSymbol(const CursorInEditor &data,