Browse Source

error highlighting

cl-refactor
arkpar 10 years ago
parent
commit
8d129924e3
  1. 9
      mix/CodeHighlighter.cpp
  2. 6
      mix/CodeHighlighter.h
  3. 1
      mix/CodeModel.cpp

9
mix/CodeHighlighter.cpp

@ -29,6 +29,7 @@
#include "libsolidity/ASTVisitor.h"
#include "libsolidity/AST.h"
#include "libsolidity/Scanner.h"
#include "libsolidity/Exceptions.h"
namespace dev
{
@ -40,11 +41,12 @@ CodeHighlighterSettings::CodeHighlighterSettings()
bg = QColor(0x00, 0x2b, 0x36);
fg = QColor (0xee, 0xe8, 0xd5);
formats[Keyword].setForeground(QColor(0x93, 0xa1, 0xa1));
//formats[Type].setForeground(Qt::darkCyan);
formats[Comment].setForeground(QColor(0x85, 0x99, 0x00));
formats[StringLiteral].setForeground(QColor(0xdc, 0x32, 0x2f));
formats[NumLiteral].setForeground(fg);
formats[Import].setForeground(QColor(0x6c, 0x71, 0xc4));
formats[CompilationError].setUnderlineColor(Qt::red);
formats[CompilationError].setUnderlineStyle(QTextCharFormat::SingleUnderline);
}
namespace
@ -101,6 +103,11 @@ void CodeHighlighter::processAST(solidity::ASTNode const& _ast)
std::sort(m_formats.begin(), m_formats.end());
}
void CodeHighlighter::processError(dev::Exception const& _exception)
{
Location const* location = boost::get_error_info<errinfo_sourceLocation>(_exception);
m_formats.push_back(FormatRange(CodeHighlighterSettings::CompilationError, *location));
}
void CodeHighlighter::processComments(std::string const& _source)
{

6
mix/CodeHighlighter.h

@ -31,6 +31,8 @@ class QTextDocument;
namespace dev
{
struct Exception;
namespace solidity
{
class ASTNode;
@ -50,6 +52,7 @@ public:
Comment,
StringLiteral,
NumLiteral,
CompilationError,
Size, //this must be kept last
};
@ -70,7 +73,7 @@ public:
{
FormatRange(CodeHighlighterSettings::Token _t, int _start, int _length): token(_t), start(_start), length(_length) {}
FormatRange(CodeHighlighterSettings::Token _t, solidity::Location const& _location);
bool operator<(FormatRange const& _other) { return start < _other.start || (start == _other.start && length < _other.length); }
bool operator<(FormatRange const& _other) const { return start < _other.start || (start == _other.start && length < _other.length); }
CodeHighlighterSettings::Token token;
int start;
@ -82,6 +85,7 @@ public:
/// Collect highligting information
void processSource(std::string const& _source);
void processAST(solidity::ASTNode const& _ast);
void processError(dev::Exception const& _exception);
void updateFormatting(QTextDocument* _document, CodeHighlighterSettings const& _settings);
private:

1
mix/CodeModel.cpp

@ -140,6 +140,7 @@ void CodeModel::runCompilationJob(int _jobId, QString const& _code)
std::ostringstream error;
solidity::SourceReferenceFormatter::printExceptionInformation(error, _exception, "Error", cs);
result.reset(new CompilationResult(*m_result, QString::fromStdString(error.str())));
codeHighlighter->processError(_exception);
qDebug() << QString(QApplication::tr("compilation failed:") + " " + result->compilerMessage());
}
result->m_codeHighlighter = codeHighlighter;

Loading…
Cancel
Save