forked from qt-creator/qt-creator
TextEditor: Return hover handler priority by callback
...to get rid of the asynchronous code path. Change-Id: I56377510440631b0be712333b2a4018717c86389 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -102,17 +102,16 @@ static QFuture<CppTools::ToolTipInfo> editorDocumentHandlesToolTipInfo(
|
||||
|
||||
ClangHoverHandler::ClangHoverHandler()
|
||||
{
|
||||
setIsAsyncHandler(true);
|
||||
}
|
||||
|
||||
ClangHoverHandler::~ClangHoverHandler()
|
||||
{
|
||||
cancelAsyncCheck();
|
||||
abort();
|
||||
}
|
||||
|
||||
void ClangHoverHandler::identifyMatchAsync(TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
BaseHoverHandler::ReportPriority report)
|
||||
void ClangHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
BaseHoverHandler::ReportPriority report)
|
||||
{
|
||||
// Reset
|
||||
m_futureWatcher.reset();
|
||||
@@ -143,7 +142,7 @@ void ClangHoverHandler::identifyMatchAsync(TextEditorWidget *editorWidget,
|
||||
report(Priority_None); // Ops, something went wrong.
|
||||
}
|
||||
|
||||
void ClangHoverHandler::cancelAsyncCheck()
|
||||
void ClangHoverHandler::abort()
|
||||
{
|
||||
if (m_futureWatcher)
|
||||
m_futureWatcher->cancel();
|
||||
|
@@ -40,14 +40,14 @@ public:
|
||||
ClangHoverHandler();
|
||||
~ClangHoverHandler() override;
|
||||
|
||||
void identifyMatchAsync(TextEditor::TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report) override;
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report) override;
|
||||
void decorateToolTip() override;
|
||||
void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point) override;
|
||||
|
||||
private:
|
||||
void cancelAsyncCheck() override;
|
||||
void abort() override;
|
||||
void processToolTipInfo(const CppTools::ToolTipInfo &info);
|
||||
|
||||
private:
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include <dynamicastmatcherdiagnosticmessagecontainer.h>
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
|
||||
namespace ClangRefactoring {
|
||||
|
||||
@@ -38,8 +39,12 @@ ClangQueryHoverHandler::ClangQueryHoverHandler(ClangQueryHighlighter *highligher
|
||||
{
|
||||
}
|
||||
|
||||
void ClangQueryHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int position)
|
||||
void ClangQueryHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
int position,
|
||||
ReportPriority report)
|
||||
{
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
|
||||
using Messages = ClangBackEnd::DynamicASTMatcherDiagnosticMessageContainers;
|
||||
using Contexts = ClangBackEnd::DynamicASTMatcherDiagnosticContextContainers;
|
||||
|
||||
|
@@ -37,7 +37,9 @@ public:
|
||||
ClangQueryHoverHandler(ClangQueryHighlighter *highligher);
|
||||
|
||||
protected:
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int position) override;
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
int position,
|
||||
ReportPriority report) override;
|
||||
|
||||
private:
|
||||
ClangQueryHighlighter *m_highligher;
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/project.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
|
||||
#include <QPoint>
|
||||
#include <QTextBlock>
|
||||
@@ -164,8 +165,12 @@ static QString findResourceInProject(const QString &resName)
|
||||
return QString();
|
||||
}
|
||||
|
||||
void ResourcePreviewHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos)
|
||||
void ResourcePreviewHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report)
|
||||
{
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
|
||||
if (editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
||||
const QTextBlock tb = editorWidget->document()->findBlock(pos);
|
||||
const int tbpos = pos - tb.position();
|
||||
|
@@ -35,7 +35,9 @@ namespace Internal {
|
||||
class ResourcePreviewHoverHandler : public TextEditor::BaseHoverHandler
|
||||
{
|
||||
private:
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos) override;
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report) override;
|
||||
void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point) override;
|
||||
|
||||
private:
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <utils/textutils.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QUrl>
|
||||
@@ -67,8 +68,10 @@ QString CppHoverHandler::tooltipTextForHelpItem(const HelpItem &helpItem)
|
||||
return QString();
|
||||
}
|
||||
|
||||
void CppHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos)
|
||||
void CppHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, ReportPriority report)
|
||||
{
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
|
||||
QTextCursor tc(editorWidget->document());
|
||||
tc.setPosition(pos);
|
||||
|
||||
|
@@ -37,7 +37,9 @@ public:
|
||||
static QString tooltipTextForHelpItem(const TextEditor::HelpItem &help);
|
||||
|
||||
private:
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos) override;
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report) override;
|
||||
void decorateToolTip() override;
|
||||
};
|
||||
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include <coreplugin/helpmanager.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <utils/htmldocextractor.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
|
||||
#include <QTextBlock>
|
||||
#include <QUrl>
|
||||
@@ -44,8 +45,12 @@ ProFileHoverHandler::ProFileHoverHandler()
|
||||
{
|
||||
}
|
||||
|
||||
void ProFileHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos)
|
||||
void ProFileHoverHandler::identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report)
|
||||
{
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
|
||||
m_docFragment.clear();
|
||||
m_manualKind = UnknownManual;
|
||||
if (!editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
||||
|
@@ -40,7 +40,9 @@ public:
|
||||
ProFileHoverHandler();
|
||||
|
||||
private:
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos) override;
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report) override;
|
||||
void identifyQMakeKeyword(const QString &text, int pos);
|
||||
|
||||
enum ManualKind {
|
||||
|
@@ -45,6 +45,7 @@
|
||||
#include <qmljs/qmljsqrcparser.h>
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/helpitem.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
|
||||
#include <QDir>
|
||||
@@ -201,8 +202,10 @@ bool QmlJSHoverHandler::setQmlTypeHelp(const ScopeChain &scopeChain, const Docum
|
||||
return true;
|
||||
}
|
||||
|
||||
void QmlJSHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos)
|
||||
void QmlJSHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, ReportPriority report)
|
||||
{
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
|
||||
reset();
|
||||
|
||||
if (!m_modelManager)
|
||||
|
@@ -58,7 +58,9 @@ public:
|
||||
private:
|
||||
void reset();
|
||||
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget, int pos) override;
|
||||
void identifyMatch(TextEditor::TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report) override;
|
||||
void operateTooltip(TextEditor::TextEditorWidget *editorWidget, const QPoint &point) override;
|
||||
|
||||
bool matchDiagnosticMessage(QmlJSEditorWidget *qmlEditor, int pos);
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#include "basehoverhandler.h"
|
||||
#include "texteditor.h"
|
||||
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
|
||||
@@ -34,11 +35,6 @@ namespace TextEditor {
|
||||
BaseHoverHandler::~BaseHoverHandler()
|
||||
{}
|
||||
|
||||
bool BaseHoverHandler::isAsyncHandler() const
|
||||
{
|
||||
return m_isAsyncHandler;
|
||||
}
|
||||
|
||||
void BaseHoverHandler::showToolTip(TextEditorWidget *widget, const QPoint &point, bool decorate)
|
||||
{
|
||||
if (decorate)
|
||||
@@ -55,11 +51,6 @@ void BaseHoverHandler::checkPriority(TextEditorWidget *widget,
|
||||
process(widget, pos, report);
|
||||
}
|
||||
|
||||
void BaseHoverHandler::cancelAsyncCheck()
|
||||
{
|
||||
QTC_CHECK(false && "BaseHoverHandler: Implement cancelCheck() in derived class!");
|
||||
}
|
||||
|
||||
int BaseHoverHandler::priority() const
|
||||
{
|
||||
if (m_priority >= 0)
|
||||
@@ -117,31 +108,18 @@ void BaseHoverHandler::process(TextEditorWidget *widget, int pos, ReportPriority
|
||||
m_priority = -1;
|
||||
m_lastHelpItemIdentified = HelpItem();
|
||||
|
||||
if (m_isAsyncHandler) {
|
||||
identifyMatchAsync(widget, pos, report);
|
||||
} else {
|
||||
identifyMatch(widget, pos);
|
||||
report(priority());
|
||||
}
|
||||
identifyMatch(widget, pos, report);
|
||||
}
|
||||
|
||||
void BaseHoverHandler::setIsAsyncHandler(bool isAsyncHandler)
|
||||
void BaseHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, ReportPriority report)
|
||||
{
|
||||
m_isAsyncHandler = isAsyncHandler;
|
||||
}
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
|
||||
void BaseHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos)
|
||||
{
|
||||
QString tooltip = editorWidget->extraSelectionTooltip(pos);
|
||||
if (!tooltip.isEmpty())
|
||||
setToolTip(tooltip);
|
||||
}
|
||||
|
||||
void BaseHoverHandler::identifyMatchAsync(TextEditorWidget *, int, BaseHoverHandler::ReportPriority)
|
||||
{
|
||||
QTC_CHECK(false && "BaseHoverHandler: Implement identifyMatchAsync() in derived class!");
|
||||
}
|
||||
|
||||
void BaseHoverHandler::decorateToolTip()
|
||||
{
|
||||
if (Qt::mightBeRichText(toolTip()))
|
||||
|
@@ -43,14 +43,11 @@ class TEXTEDITOR_EXPORT BaseHoverHandler
|
||||
public:
|
||||
virtual ~BaseHoverHandler();
|
||||
|
||||
bool isAsyncHandler() const;
|
||||
void setIsAsyncHandler(bool isAsyncHandler);
|
||||
|
||||
QString contextHelpId(TextEditorWidget *widget, int pos);
|
||||
|
||||
using ReportPriority = std::function<void(int priority)>;
|
||||
void checkPriority(TextEditorWidget *widget, int pos, ReportPriority report);
|
||||
virtual void cancelAsyncCheck();
|
||||
virtual void abort() {} // Implement for asynchronous priority reporter
|
||||
|
||||
void showToolTip(TextEditorWidget *widget, const QPoint &point, bool decorate = true);
|
||||
|
||||
@@ -70,16 +67,17 @@ protected:
|
||||
void setLastHelpItemIdentified(const HelpItem &help);
|
||||
const HelpItem &lastHelpItemIdentified() const;
|
||||
|
||||
virtual void identifyMatch(TextEditorWidget *editorWidget, int pos);
|
||||
virtual void identifyMatchAsync(TextEditorWidget *editorWidget, int pos, ReportPriority report);
|
||||
// identifyMatch() is required to report a priority by using the "report" callback.
|
||||
// It is recommended to use e.g.
|
||||
// Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
// at the beginning of an implementation to ensure this in any case.
|
||||
virtual void identifyMatch(TextEditorWidget *editorWidget, int pos, ReportPriority report);
|
||||
virtual void decorateToolTip();
|
||||
virtual void operateTooltip(TextEditorWidget *editorWidget, const QPoint &point);
|
||||
|
||||
private:
|
||||
void process(TextEditorWidget *widget, int pos, ReportPriority report);
|
||||
|
||||
bool m_isAsyncHandler = false;
|
||||
|
||||
QString m_toolTip;
|
||||
HelpItem m_lastHelpItemIdentified;
|
||||
int m_priority = -1;
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#include "texteditor.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <utils/executeondestruction.h>
|
||||
#include <utils/tooltip/tooltip.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -355,8 +356,12 @@ static QColor colorFromFuncAndArgs(const QString &func, const QStringList &args)
|
||||
return colorFromArgs(args, spec);
|
||||
}
|
||||
|
||||
void ColorPreviewHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos)
|
||||
void ColorPreviewHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
|
||||
int pos,
|
||||
ReportPriority report)
|
||||
{
|
||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
||||
|
||||
if (editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
||||
const QTextBlock tb = editorWidget->document()->findBlock(pos);
|
||||
const int tbpos = pos - tb.position();
|
||||
|
@@ -39,7 +39,7 @@ class TextEditorWidget;
|
||||
class TEXTEDITOR_EXPORT ColorPreviewHoverHandler : public BaseHoverHandler
|
||||
{
|
||||
private:
|
||||
void identifyMatch(TextEditorWidget *editorWidget, int pos) override;
|
||||
void identifyMatch(TextEditorWidget *editorWidget, int pos, ReportPriority report) override;
|
||||
void operateTooltip(TextEditorWidget *editorWidget, const QPoint &point) override;
|
||||
|
||||
QColor m_colorTip;
|
||||
|
@@ -314,10 +314,8 @@ public:
|
||||
}
|
||||
|
||||
// Cancel currently running checks
|
||||
for (BaseHoverHandler *handler : m_handlers) {
|
||||
if (handler->isAsyncHandler())
|
||||
handler->cancelAsyncCheck();
|
||||
}
|
||||
for (BaseHoverHandler *handler : m_handlers)
|
||||
handler->abort();
|
||||
|
||||
// Update invocation data
|
||||
m_documentRevision = documentRevision;
|
||||
|
Reference in New Issue
Block a user