summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor/generichighlighter/highlighter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/texteditor/generichighlighter/highlighter.cpp')
-rw-r--r--src/plugins/texteditor/generichighlighter/highlighter.cpp74
1 files changed, 51 insertions, 23 deletions
diff --git a/src/plugins/texteditor/generichighlighter/highlighter.cpp b/src/plugins/texteditor/generichighlighter/highlighter.cpp
index ca46a2d3d8..8c482693a6 100644
--- a/src/plugins/texteditor/generichighlighter/highlighter.cpp
+++ b/src/plugins/texteditor/generichighlighter/highlighter.cpp
@@ -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;
@@ -81,7 +82,7 @@ HighlighterCodeFormatterData *formatterData(const QTextBlock &block)
}
Highlighter::Highlighter(QTextDocument *parent) :
- TextEditor::SyntaxHighlighter(parent),
+ SyntaxHighlighter(parent),
m_regionDepth(0),
m_indentationBasedFolding(false),
m_tabSettings(0),
@@ -89,24 +90,24 @@ Highlighter::Highlighter(QTextDocument *parent) :
m_dynamicContextsCounter(0),
m_isBroken(false)
{
- static QVector<TextEditor::TextStyle> categories;
+ static QVector<TextStyle> categories;
if (categories.isEmpty()) {
- categories << TextEditor::C_TEXT
- << TextEditor::C_VISUAL_WHITESPACE
- << TextEditor::C_KEYWORD
- << TextEditor::C_TYPE
- << TextEditor::C_COMMENT
- << TextEditor::C_NUMBER
- << TextEditor::C_NUMBER
- << TextEditor::C_NUMBER
- << TextEditor::C_STRING
- << TextEditor::C_STRING
- << TextEditor::C_TEXT // TODO : add style for alert (eg. yellow background)
- << TextEditor::C_TEXT // TODO : add style for error (eg. red underline)
- << TextEditor::C_FUNCTION
- << TextEditor::C_TEXT
- << TextEditor::C_TEXT
- << TextEditor::C_LOCAL;
+ categories << C_TEXT
+ << C_VISUAL_WHITESPACE
+ << C_KEYWORD
+ << C_TYPE
+ << C_COMMENT
+ << C_NUMBER
+ << C_NUMBER
+ << C_NUMBER
+ << C_STRING
+ << C_STRING
+ << C_TEXT // TODO : add style for alert (eg. yellow background)
+ << C_TEXT // TODO : add style for error (eg. red underline)
+ << C_FUNCTION
+ << C_TEXT
+ << C_TEXT
+ << C_LOCAL;
}
setTextFormatCategories(categories);
@@ -155,6 +156,16 @@ void Highlighter::setTabSettings(const TabSettings &ts)
m_tabSettings = &ts;
}
+static bool isOpeningParenthesis(QChar c)
+{
+ return c == QLatin1Char('{') || c == QLatin1Char('[') || c == QLatin1Char('(');
+}
+
+static bool isClosingParenthesis(QChar c)
+{
+ return c == QLatin1Char('}') || c == QLatin1Char(']') || c == QLatin1Char(')');
+}
+
void Highlighter::highlightBlock(const QString &text)
{
if (!m_defaultContext.isNull() && !m_isBroken) {
@@ -184,7 +195,22 @@ void Highlighter::highlightBlock(const QString &text)
// In the case region depth has changed since the last time the state was set.
setCurrentBlockState(computeState(extractObservableState(currentBlockState())));
}
- } catch (const HighlighterException &) {
+
+ Parentheses parentheses;
+ for (int pos = 0; pos < length; ++pos) {
+ const QChar c = text.at(pos);
+ if (isOpeningParenthesis(c))
+ parentheses.push_back(Parenthesis(Parenthesis::Opened, c, pos));
+ else if (isClosingParenthesis(c))
+ parentheses.push_back(Parenthesis(Parenthesis::Closed, c, pos));
+ }
+ TextDocumentLayout::setParentheses(currentBlock(), parentheses);
+
+ } catch (const HighlighterException &e) {
+ Core::MessageManager::write(
+ QCoreApplication::translate("GenericHighlighter",
+ "Generic highlighter error: ") + e.message(),
+ Core::MessageManager::WithFocus);
m_isBroken = true;
}
}
@@ -367,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();
}