forked from qt-creator/qt-creator
ProjectExplorer: Allow extra compilers to post compile issues
If we have a text editor for the source document the errors will be highlighted in the editor then. Change-Id: I02ed24783e7079c3d2cb308d8111b399cd77adb1 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -30,12 +30,17 @@
|
|||||||
#include "buildconfiguration.h"
|
#include "buildconfiguration.h"
|
||||||
#include "kitinformation.h"
|
#include "kitinformation.h"
|
||||||
|
|
||||||
|
#include <texteditor/texteditor.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
#include <texteditor/fontsettings.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QTextBlock>
|
||||||
|
|
||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
|
|
||||||
@@ -48,6 +53,7 @@ public:
|
|||||||
Utils::FileName source;
|
Utils::FileName source;
|
||||||
Utils::FileNameList targets;
|
Utils::FileNameList targets;
|
||||||
QVector<QString> contents;
|
QVector<QString> contents;
|
||||||
|
QList<Task> issues;
|
||||||
QDateTime compileTime;
|
QDateTime compileTime;
|
||||||
Core::IEditor *lastEditor = 0;
|
Core::IEditor *lastEditor = 0;
|
||||||
QMetaObject::Connection activeBuildConfigConnection;
|
QMetaObject::Connection activeBuildConfigConnection;
|
||||||
@@ -55,6 +61,7 @@ public:
|
|||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
void updateIssues();
|
||||||
};
|
};
|
||||||
|
|
||||||
ExtraCompiler::ExtraCompiler(const Project *project, const Utils::FileName &source,
|
ExtraCompiler::ExtraCompiler(const Project *project, const Utils::FileName &source,
|
||||||
@@ -207,6 +214,7 @@ void ExtraCompiler::onEditorChanged(Core::IEditor *editor)
|
|||||||
|
|
||||||
if (editor && editor->document()->filePath() == d->source) {
|
if (editor && editor->document()->filePath() == d->source) {
|
||||||
d->lastEditor = editor;
|
d->lastEditor = editor;
|
||||||
|
d->updateIssues();
|
||||||
|
|
||||||
// Handle new editor
|
// Handle new editor
|
||||||
connect(d->lastEditor->document(), &Core::IDocument::contentsChanged,
|
connect(d->lastEditor->document(), &Core::IDocument::contentsChanged,
|
||||||
@@ -291,6 +299,41 @@ Utils::Environment ExtraCompiler::buildEnvironment() const
|
|||||||
return Utils::Environment::systemEnvironment();
|
return Utils::Environment::systemEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExtraCompiler::setCompileIssues(const QList<Task> &issues)
|
||||||
|
{
|
||||||
|
d->issues = issues;
|
||||||
|
d->updateIssues();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExtraCompilerPrivate::updateIssues()
|
||||||
|
{
|
||||||
|
if (!lastEditor)
|
||||||
|
return;
|
||||||
|
|
||||||
|
TextEditor::TextEditorWidget *widget =
|
||||||
|
qobject_cast<TextEditor::TextEditorWidget *>(lastEditor->widget());
|
||||||
|
if (!widget)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QList<QTextEdit::ExtraSelection> selections;
|
||||||
|
const QTextDocument *document = widget->document();
|
||||||
|
foreach (const Task &issue, issues) {
|
||||||
|
QTextEdit::ExtraSelection selection;
|
||||||
|
QTextCursor cursor(document->findBlockByNumber(issue.line - 1));
|
||||||
|
cursor.movePosition(QTextCursor::StartOfLine);
|
||||||
|
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
|
||||||
|
selection.cursor = cursor;
|
||||||
|
|
||||||
|
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||||
|
selection.format = fontSettings.toTextCharFormat(issue.type == Task::Warning ?
|
||||||
|
TextEditor::C_WARNING : TextEditor::C_ERROR);
|
||||||
|
selection.format.setToolTip(issue.description);
|
||||||
|
selections.append(selection);
|
||||||
|
}
|
||||||
|
|
||||||
|
widget->setExtraSelections(TextEditor::TextEditorWidget::CodeWarningsSelection, selections);
|
||||||
|
}
|
||||||
|
|
||||||
void ExtraCompiler::setContent(const Utils::FileName &file, const QString &contents)
|
void ExtraCompiler::setContent(const Utils::FileName &file, const QString &contents)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < d->targets.length(); ++i) {
|
for (int i = 0; i < d->targets.length(); ++i) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "projectnodes.h"
|
#include "projectnodes.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
#include "task.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
@@ -62,6 +63,7 @@ signals:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
Utils::Environment buildEnvironment() const;
|
Utils::Environment buildEnvironment() const;
|
||||||
|
void setCompileIssues(const QList<Task> &issues);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onTargetsBuilt(Project *project);
|
void onTargetsBuilt(Project *project);
|
||||||
|
|||||||
Reference in New Issue
Block a user