2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 15:08:31 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "cpphoverhandler.h"
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2010-08-13 16:38:45 +02:00
|
|
|
#include "cppelementevaluator.h"
|
2019-02-08 16:12:02 +01:00
|
|
|
#include "cpptoolsreuse.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-08-27 12:11:55 +02:00
|
|
|
#include <coreplugin/helpmanager.h>
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2014-05-22 11:04:57 -04:00
|
|
|
|
2017-09-21 12:35:24 +02:00
|
|
|
#include <utils/textutils.h>
|
2018-01-18 10:47:45 +01:00
|
|
|
#include <utils/executeondestruction.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTextCursor>
|
|
|
|
|
#include <QUrl>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
using namespace Core;
|
2014-09-09 13:25:10 +02:00
|
|
|
using namespace TextEditor;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-01-12 12:29:43 +01:00
|
|
|
namespace CppTools {
|
2016-01-27 13:37:19 +01:00
|
|
|
|
2018-01-18 10:47:45 +01:00
|
|
|
void CppHoverHandler::identifyMatch(TextEditorWidget *editorWidget, int pos, ReportPriority report)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-01-18 10:47:45 +01:00
|
|
|
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
|
|
|
|
|
2017-10-23 15:53:57 +02:00
|
|
|
QTextCursor tc(editorWidget->document());
|
|
|
|
|
tc.setPosition(pos);
|
|
|
|
|
|
|
|
|
|
CppElementEvaluator evaluator(editorWidget);
|
|
|
|
|
evaluator.setTextCursor(tc);
|
|
|
|
|
evaluator.execute();
|
2018-01-25 15:51:36 +01:00
|
|
|
QString tip;
|
2017-10-23 15:53:57 +02:00
|
|
|
if (evaluator.hasDiagnosis()) {
|
2018-01-25 15:51:36 +01:00
|
|
|
tip += evaluator.diagnosis();
|
2017-10-23 15:53:57 +02:00
|
|
|
setPriority(Priority_Diagnostic);
|
2018-01-25 15:51:36 +01:00
|
|
|
}
|
2019-02-08 16:12:02 +01:00
|
|
|
const QStringList fallback = identifierWordsUnderCursor(tc);
|
2018-01-25 15:51:36 +01:00
|
|
|
if (evaluator.identifiedCppElement()) {
|
2017-10-23 15:53:57 +02:00
|
|
|
const QSharedPointer<CppElement> &cppElement = evaluator.cppElement();
|
2019-02-08 16:12:02 +01:00
|
|
|
const QStringList candidates = cppElement->helpIdCandidates;
|
|
|
|
|
const HelpItem helpItem(candidates + fallback, cppElement->helpMark, cppElement->helpCategory);
|
2019-01-28 13:00:03 +01:00
|
|
|
setLastHelpItemIdentified(helpItem); // tool tip appended by decorateToolTip
|
|
|
|
|
if (!helpItem.isValid())
|
2018-01-25 15:51:36 +01:00
|
|
|
tip += cppElement->tooltip;
|
2019-02-08 16:12:02 +01:00
|
|
|
} else {
|
|
|
|
|
setLastHelpItemIdentified({fallback, {}, HelpItem::Unknown});
|
2008-12-10 11:58:25 +01:00
|
|
|
}
|
2018-01-25 15:51:36 +01:00
|
|
|
setToolTip(tip);
|
2010-07-20 12:35:08 +02:00
|
|
|
}
|
2014-09-09 13:25:10 +02:00
|
|
|
|
2018-01-11 17:06:26 +01:00
|
|
|
} // namespace CppTools
|