forked from qt-creator/qt-creator
Add possibility to fetch rule details for issues
Allows to fetch further information of an issue and display it inside the output pane. Change-Id: I94ec27b9c060dca9f9523d763b8628a2fce7ca59 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <QLabel>
|
||||
#include <QScrollArea>
|
||||
#include <QStackedWidget>
|
||||
#include <QTextBrowser>
|
||||
|
||||
namespace Axivion::Internal {
|
||||
|
||||
@@ -98,6 +99,8 @@ AxivionOutputPane::AxivionOutputPane(QObject *parent)
|
||||
m_outputWidget = new QStackedWidget;
|
||||
DashboardWidget *dashboardWidget = new DashboardWidget(m_outputWidget);
|
||||
m_outputWidget->addWidget(dashboardWidget);
|
||||
QTextBrowser *browser = new QTextBrowser(m_outputWidget);
|
||||
m_outputWidget->addWidget(browser);
|
||||
}
|
||||
|
||||
AxivionOutputPane::~AxivionOutputPane()
|
||||
@@ -182,4 +185,15 @@ void AxivionOutputPane::updateDashboard()
|
||||
}
|
||||
}
|
||||
|
||||
void AxivionOutputPane::updateAndShowRule(const QString &ruleHtml)
|
||||
{
|
||||
if (auto browser = static_cast<QTextBrowser *>(m_outputWidget->widget(1))) {
|
||||
browser->setText(ruleHtml);
|
||||
if (!ruleHtml.isEmpty()) {
|
||||
m_outputWidget->setCurrentIndex(1);
|
||||
popup(Core::IOutputPane::NoModeSwitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // Axivion::Internal
|
||||
|
||||
@@ -34,6 +34,7 @@ public:
|
||||
void goToPrev() override;
|
||||
|
||||
void updateDashboard();
|
||||
void updateAndShowRule(const QString &ruleHtml);
|
||||
private:
|
||||
QStackedWidget *m_outputWidget = nullptr;
|
||||
};
|
||||
|
||||
@@ -24,11 +24,13 @@
|
||||
#include <texteditor/texteditor.h>
|
||||
#include <texteditor/textmark.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/utilsicons.h>
|
||||
|
||||
#ifdef LICENSECHECKER
|
||||
# include <licensechecker/licensecheckerplugin.h>
|
||||
#endif
|
||||
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
@@ -48,6 +50,7 @@ public:
|
||||
void onDocumentClosed(Core::IDocument * doc);
|
||||
void clearAllMarks();
|
||||
void handleIssuesForFile(const IssuesList &issues);
|
||||
void fetchRuleInfo(const QString &id);
|
||||
|
||||
AxivionSettings m_axivionSettings;
|
||||
AxivionSettingsPage m_axivionSettingsPage{&m_axivionSettings};
|
||||
@@ -78,6 +81,14 @@ AxivionTextMark::AxivionTextMark(const Utils::FilePath &filePath, const ShortIss
|
||||
setToolTip(issue.errorNumber + " " + markText);
|
||||
setPriority(TextEditor::TextMark::NormalPriority);
|
||||
setLineAnnotation(markText);
|
||||
setActionsProvider([this]{
|
||||
auto action = new QAction;
|
||||
action->setIcon(Utils::Icons::INFO.icon());
|
||||
action->setToolTip(Tr::tr("Show rule details"));
|
||||
QObject::connect(action, &QAction::triggered,
|
||||
dd, [this]{ dd->fetchRuleInfo(m_id); });
|
||||
return QList{action};
|
||||
});
|
||||
}
|
||||
|
||||
AxivionPlugin::AxivionPlugin()
|
||||
@@ -222,6 +233,26 @@ void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName)
|
||||
runner->start();
|
||||
}
|
||||
|
||||
void AxivionPluginPrivate::fetchRuleInfo(const QString &id)
|
||||
{
|
||||
if (m_runningQuery) {
|
||||
QTimer::singleShot(3000, [this, id]{ fetchRuleInfo(id); });
|
||||
return;
|
||||
}
|
||||
|
||||
const QStringList args = id.split(':');
|
||||
QTC_ASSERT(args.size() == 2, return);
|
||||
m_runningQuery = true;
|
||||
AxivionQuery query(AxivionQuery::RuleInfo, args);
|
||||
AxivionQueryRunner *runner = new AxivionQueryRunner(query, this);
|
||||
connect(runner, &AxivionQueryRunner::resultRetrieved, this, [this](const QByteArray &result){
|
||||
m_runningQuery = false;
|
||||
m_axivionOutputPane.updateAndShowRule(ResultParser::parseRuleInfo(result));
|
||||
});
|
||||
connect(runner, &AxivionQueryRunner::finished, [runner]{ runner->deleteLater(); });
|
||||
runner->start();
|
||||
}
|
||||
|
||||
void AxivionPluginPrivate::handleOpenedDocs(ProjectExplorer::Project *project)
|
||||
{
|
||||
if (project && ProjectExplorer::SessionManager::startupProject() != project)
|
||||
|
||||
@@ -23,7 +23,7 @@ AxivionQuery::AxivionQuery(QueryType type, const QStringList ¶meters)
|
||||
|
||||
QString AxivionQuery::toString() const
|
||||
{
|
||||
QString query = "/api"; // common for all
|
||||
QString query = "/api"; // common for all except RuleInfo
|
||||
switch (m_type) {
|
||||
case NoQuery:
|
||||
return {};
|
||||
@@ -40,6 +40,11 @@ QString AxivionQuery::toString() const
|
||||
+ "/issues?kind=" + m_parameters.at(1) + "&filter_path="
|
||||
+ QUrl::toPercentEncoding(m_parameters.at(2)) + "&format=csv";
|
||||
return query;
|
||||
case RuleInfo:
|
||||
QTC_ASSERT(m_parameters.size() == 2, return {});
|
||||
query = "/projects/" + QUrl::toPercentEncoding(m_parameters.first())
|
||||
+ "/issues/" + m_parameters.at(1) + "/rule";
|
||||
return query;
|
||||
}
|
||||
|
||||
return {};
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Axivion::Internal {
|
||||
class AxivionQuery
|
||||
{
|
||||
public:
|
||||
enum QueryType {NoQuery, DashboardInfo, ProjectInfo, IssuesForFileList};
|
||||
enum QueryType {NoQuery, DashboardInfo, ProjectInfo, IssuesForFileList, RuleInfo};
|
||||
explicit AxivionQuery(QueryType type, const QStringList ¶meters = {});
|
||||
|
||||
QString toString() const;
|
||||
|
||||
@@ -333,6 +333,15 @@ IssuesList parseIssuesList(const QByteArray &input)
|
||||
return result;
|
||||
}
|
||||
|
||||
QString parseRuleInfo(const QByteArray &input) // html result!
|
||||
{
|
||||
auto [header, body] = splitHeaderAndBody(input);
|
||||
BaseResult headerResult = prehandleHeader(header, body);
|
||||
if (!headerResult.error.isEmpty())
|
||||
return QString();
|
||||
return QString::fromLocal8Bit(body);
|
||||
}
|
||||
|
||||
} // ResultParser
|
||||
|
||||
} // Axivion::Internal
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace ResultParser {
|
||||
DashboardInfo parseDashboardInfo(const QByteArray &input);
|
||||
ProjectInfo parseProjectInfo(const QByteArray &input);
|
||||
IssuesList parseIssuesList(const QByteArray &input);
|
||||
QString parseRuleInfo(const QByteArray &input);
|
||||
|
||||
} // ResultParser
|
||||
|
||||
|
||||
Reference in New Issue
Block a user