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 "reuse.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
using namespace TextEditor;
|
||||
@@ -45,11 +46,16 @@ namespace {
|
||||
template <class Element, class Container>
|
||||
QSharedPointer<Element> createHelper(const QString &name, Container &container)
|
||||
{
|
||||
if (name.isEmpty())
|
||||
throw HighlighterException();
|
||||
if (name.isEmpty()) {
|
||||
throw HighlighterException(
|
||||
QCoreApplication::translate("GenericHighlighter", "Element name is empty"));
|
||||
}
|
||||
|
||||
if (container.contains(name))
|
||||
throw HighlighterException();
|
||||
if (container.contains(name)) {
|
||||
throw HighlighterException(
|
||||
QCoreApplication::translate("GenericHighlighter",
|
||||
"Duplicate element name \"%1\"").arg(name));
|
||||
}
|
||||
|
||||
return container.insert(name, QSharedPointer<Element>(new Element)).value();
|
||||
}
|
||||
@@ -59,8 +65,11 @@ QSharedPointer<Element>
|
||||
findHelper(const QString &name, const Container &container)
|
||||
{
|
||||
typename Container::const_iterator it = container.find(name);
|
||||
if (it == container.end())
|
||||
throw HighlighterException();
|
||||
if (it == container.end()) {
|
||||
throw HighlighterException(
|
||||
QCoreApplication::translate("GenericHighlighter",
|
||||
"name \"%1\" not found").arg(name));
|
||||
}
|
||||
|
||||
return it.value();
|
||||
}
|
||||
|
@@ -38,8 +38,9 @@
|
||||
#include "reuse.h"
|
||||
#include "tabsettings.h"
|
||||
|
||||
#include <QLatin1String>
|
||||
#include <QLatin1Char>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
using namespace TextEditor;
|
||||
using namespace Internal;
|
||||
@@ -205,7 +206,11 @@ void Highlighter::highlightBlock(const QString &text)
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -388,8 +393,10 @@ void Highlighter::changeContext(const QString &contextName,
|
||||
if (contextName.startsWith(kPop)) {
|
||||
QStringList list = contextName.split(kHash, QString::SkipEmptyParts);
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
if (m_contexts.isEmpty())
|
||||
throw HighlighterException();
|
||||
if (m_contexts.isEmpty()) {
|
||||
throw HighlighterException(
|
||||
QCoreApplication::translate("GenericHighlighter", "Reached empty context"));
|
||||
}
|
||||
m_contexts.pop_back();
|
||||
}
|
||||
|
||||
|
@@ -31,8 +31,20 @@
|
||||
#ifndef HIGHLIGHTEREXCEPTION_H
|
||||
#define HIGHLIGHTEREXCEPTION_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
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
|
||||
|
||||
#endif // HIGHLIGHTEREXCEPTION_H
|
||||
|
@@ -39,14 +39,14 @@
|
||||
#include <texteditor/texteditorsettings.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/messagemanager.h>
|
||||
#include <coreplugin/progressmanager/progressmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/QtConcurrentTools>
|
||||
#include <utils/networkaccessmanager.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
#include <QLatin1Char>
|
||||
#include <QLatin1String>
|
||||
#include <QStringList>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
@@ -175,7 +175,11 @@ QSharedPointer<HighlightDefinition> Manager::definition(const QString &id)
|
||||
m_isBuildingDefinition.insert(id);
|
||||
try {
|
||||
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();
|
||||
}
|
||||
m_isBuildingDefinition.remove(id);
|
||||
|
Reference in New Issue
Block a user