forked from qt-creator/qt-creator
GenericHighlighter: Display exceptions
Enables tracking of syntax/logic errors in highlighters. Change-Id: Ia9c314d0a314ab49ca2045327e2d34c9e9d275c3 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com> Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
b9597d402d
commit
dc86025879
@@ -35,6 +35,7 @@
|
|||||||
#include "itemdata.h"
|
#include "itemdata.h"
|
||||||
#include "reuse.h"
|
#include "reuse.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
@@ -45,11 +46,16 @@ namespace {
|
|||||||
template <class Element, class Container>
|
template <class Element, class Container>
|
||||||
QSharedPointer<Element> createHelper(const QString &name, Container &container)
|
QSharedPointer<Element> createHelper(const QString &name, Container &container)
|
||||||
{
|
{
|
||||||
if (name.isEmpty())
|
if (name.isEmpty()) {
|
||||||
throw HighlighterException();
|
throw HighlighterException(
|
||||||
|
QCoreApplication::translate("GenericHighlighter", "Element name is empty"));
|
||||||
|
}
|
||||||
|
|
||||||
if (container.contains(name))
|
if (container.contains(name)) {
|
||||||
throw HighlighterException();
|
throw HighlighterException(
|
||||||
|
QCoreApplication::translate("GenericHighlighter",
|
||||||
|
"Duplicate element name \"%1\"").arg(name));
|
||||||
|
}
|
||||||
|
|
||||||
return container.insert(name, QSharedPointer<Element>(new Element)).value();
|
return container.insert(name, QSharedPointer<Element>(new Element)).value();
|
||||||
}
|
}
|
||||||
@@ -59,8 +65,11 @@ QSharedPointer<Element>
|
|||||||
findHelper(const QString &name, const Container &container)
|
findHelper(const QString &name, const Container &container)
|
||||||
{
|
{
|
||||||
typename Container::const_iterator it = container.find(name);
|
typename Container::const_iterator it = container.find(name);
|
||||||
if (it == container.end())
|
if (it == container.end()) {
|
||||||
throw HighlighterException();
|
throw HighlighterException(
|
||||||
|
QCoreApplication::translate("GenericHighlighter",
|
||||||
|
"name \"%1\" not found").arg(name));
|
||||||
|
}
|
||||||
|
|
||||||
return it.value();
|
return it.value();
|
||||||
}
|
}
|
||||||
|
@@ -38,8 +38,9 @@
|
|||||||
#include "reuse.h"
|
#include "reuse.h"
|
||||||
#include "tabsettings.h"
|
#include "tabsettings.h"
|
||||||
|
|
||||||
#include <QLatin1String>
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <QLatin1Char>
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
using namespace Internal;
|
using namespace Internal;
|
||||||
@@ -205,7 +206,11 @@ void Highlighter::highlightBlock(const QString &text)
|
|||||||
}
|
}
|
||||||
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
|
TextDocumentLayout::setParentheses(currentBlock(), parentheses);
|
||||||
|
|
||||||
} catch (const HighlighterException &) {
|
} catch (const HighlighterException &e) {
|
||||||
|
Core::MessageManager::write(
|
||||||
|
QCoreApplication::translate("GenericHighlighter",
|
||||||
|
"Generic highlighter error: ") + e.message(),
|
||||||
|
Core::MessageManager::WithFocus);
|
||||||
m_isBroken = true;
|
m_isBroken = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,8 +393,10 @@ void Highlighter::changeContext(const QString &contextName,
|
|||||||
if (contextName.startsWith(kPop)) {
|
if (contextName.startsWith(kPop)) {
|
||||||
QStringList list = contextName.split(kHash, QString::SkipEmptyParts);
|
QStringList list = contextName.split(kHash, QString::SkipEmptyParts);
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
for (int i = 0; i < list.size(); ++i) {
|
||||||
if (m_contexts.isEmpty())
|
if (m_contexts.isEmpty()) {
|
||||||
throw HighlighterException();
|
throw HighlighterException(
|
||||||
|
QCoreApplication::translate("GenericHighlighter", "Reached empty context"));
|
||||||
|
}
|
||||||
m_contexts.pop_back();
|
m_contexts.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,8 +31,20 @@
|
|||||||
#ifndef HIGHLIGHTEREXCEPTION_H
|
#ifndef HIGHLIGHTEREXCEPTION_H
|
||||||
#define HIGHLIGHTEREXCEPTION_H
|
#define HIGHLIGHTEREXCEPTION_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
namespace Internal { class HighlighterException {}; }
|
namespace Internal {
|
||||||
|
class HighlighterException
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HighlighterException(const QString &msg) : m_message(msg) {}
|
||||||
|
QString message() const { return m_message; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_message;
|
||||||
|
};
|
||||||
|
}
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
#endif // HIGHLIGHTEREXCEPTION_H
|
#endif // HIGHLIGHTEREXCEPTION_H
|
||||||
|
@@ -39,14 +39,14 @@
|
|||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/QtConcurrentTools>
|
#include <utils/QtConcurrentTools>
|
||||||
#include <utils/networkaccessmanager.h>
|
#include <utils/networkaccessmanager.h>
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QLatin1Char>
|
|
||||||
#include <QLatin1String>
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -175,7 +175,11 @@ QSharedPointer<HighlightDefinition> Manager::definition(const QString &id)
|
|||||||
m_isBuildingDefinition.insert(id);
|
m_isBuildingDefinition.insert(id);
|
||||||
try {
|
try {
|
||||||
reader.parse(source);
|
reader.parse(source);
|
||||||
} catch (const HighlighterException &) {
|
} catch (const HighlighterException &e) {
|
||||||
|
Core::MessageManager::write(
|
||||||
|
QCoreApplication::translate("GenericHighlighter",
|
||||||
|
"Generic highlighter error: ") + e.message(),
|
||||||
|
Core::MessageManager::WithFocus);
|
||||||
definition.clear();
|
definition.clear();
|
||||||
}
|
}
|
||||||
m_isBuildingDefinition.remove(id);
|
m_isBuildingDefinition.remove(id);
|
||||||
|
Reference in New Issue
Block a user