Browse Source

add list of second errorannotation instead of single item.

cl-refactor
yann300 10 years ago
parent
commit
352ec11536
  1. 9
      mix/CodeModel.cpp
  2. 2
      mix/CodeModel.h
  3. 2
      mix/qml/CodeEditorView.qml
  4. 38
      mix/qml/WebCodeEditor.qml
  5. 2
      mix/qml/html/cm/errorannotation.js
  6. 75
      mix/qml/html/codeeditor.js
  7. 2
      test/libethereum/stateOriginal.cpp

9
mix/CodeModel.cpp

@ -313,12 +313,15 @@ void CodeModel::runCompilationJob(int _jobId)
solidity::SourceReferenceFormatter::printExceptionInformation(error, _exception, "Error", cs);
QString message = QString::fromStdString(error.str());
QVariantMap firstLocation;
QVariantMap secondLocation;
QVariantList secondLocations;
if (SourceLocation const* first = boost::get_error_info<solidity::errinfo_sourceLocation>(_exception))
firstLocation = resolveCompilationErrorLocation(cs, *first);
if (SecondarySourceLocation const* second = boost::get_error_info<solidity::errinfo_secondarySourceLocation>(_exception))
secondLocation = resolveCompilationErrorLocation(cs, second->infos.front().second);
compilationError(message, firstLocation, secondLocation);
{
for (auto const& c: second->infos)
secondLocations.push_back(resolveCompilationErrorLocation(cs, c.second));
}
compilationError(message, firstLocation, secondLocations);
}
m_compiling = false;
emit stateChanged();

2
mix/CodeModel.h

@ -175,7 +175,7 @@ signals:
/// Emitted on compilation complete
void compilationComplete();
/// Emitted on compilation error
void compilationError(QString _error, QVariantMap _firstErrorLoc, QVariantMap _secondErrorLoc);
void compilationError(QString _error, QVariantMap _firstErrorLoc, QVariantList _secondErrorLoc);
/// Internal signal used to transfer compilation job to background thread
void scheduleCompilationJob(int _jobId);
/// Emitted if there are any changes in the code model

2
mix/qml/CodeEditorView.qml

@ -74,7 +74,7 @@ Item {
});
}
editor.document = document;
editor.sourceName = document.documentId;
editor.setSourceName(document.documentId);
editor.setFontSize(editorSettings.fontSize);
editor.setText(data, document.syntaxMode);
editor.changeGeneration();

38
mix/qml/WebCodeEditor.qml

@ -83,6 +83,13 @@ Item {
editorBrowser.runJavaScript("setFontSize(" + size + ")", function(result) {});
}
function setSourceName(sourceName)
{
sourceName = sourceName;
if (initialized && editorBrowser)
editorBrowser.runJavaScript("setSourceName('" + sourceName + "')", function(result) {});
}
Clipboard
{
id: clipboard
@ -137,28 +144,23 @@ Item {
editorBrowser.runJavaScript("compilationComplete()", function(result) { });
}
function compilationError(error, firstLocation, secondLocation)
function compilationError(error, firstLocation, secondLocations)
{
console.log("current " + parent.sourceName);
console.log("source " + firstLocation.source);
if (firstLocation.source !== parent.sourceName && secondLocation.source !== parent.sourceName)
return;
if (!editorBrowser || !error)
return;
if (firstLocation.start.line)
{
var detail = error.split('\n')[0];
var reg = detail.match(/:\d+:\d+:/g);
if (reg !== null)
detail = detail.replace(reg[0], "");
editorBrowser.runJavaScript("compilationError('" + JSON.stringify(firstLocation) + "', '" + JSON.stringify(secondLocation) + "', '" + detail + "')", function(result){});
}
else
{
console.log("e d qml");
editorBrowser.runJavaScript("compilationComplete()", function(result) { });
}
var detail = error.split('\n')[0];
var reg = detail.match(/:\d+:\d+:/g);
if (reg !== null)
detail = detail.replace(reg[0], "");
displayErrorAnnotations(firstLocation, detail, "first");
for (var k in secondLocations)
displayErrorAnnotations(secondLocations[k], detail, "second");
}
function displayErrorAnnotations(location, detail, type)
{
//if (location.source === parent.sourceName)
editorBrowser.runJavaScript("compilationError('" + JSON.stringify(location) + "', '" + detail + "', '" + type + "')", function(result){});
}
Timer

2
mix/qml/html/cm/errorannotation.js

@ -1,6 +1,6 @@
function ErrorAnnotation(editor, location, content)
{
this.location = JSON.parse(location);
this.location = location;
this.opened = false;
this.rawContent = content;
this.content = content.replace("Contract Error:", "");

75
mix/qml/html/codeeditor.js

@ -8,6 +8,7 @@ var editor = CodeMirror(document.body, {
styleSelectedText: true
});
var ternServer;
var sourceName = "";
editor.setOption("theme", "inkpot");
editor.setOption("indentUnit", 4);
@ -157,65 +158,46 @@ showWarning = function(content)
debugWarning = editor.addLineWidget(0, node, { coverGutter: false, above: true });
}
var annotation = null;
var secondaryAnnotation = null;
var annotations = [];
var compilationCompleteBool = true;
compilationError = function(location, secondLocation, error)
compilationError = function(location, error, type)
{
compilationCompleteBool = false;
window.setTimeout(function(){
if (compilationCompleteBool)
return;
var loc = JSON.parse(location);
if (annotation == null)
{
annotation = new ErrorAnnotation(editor, location, error);
if (secondLocation.start)
secondaryAnnotation = new ErrorAnnotation(editor, secondLocation, "");
}
else if (annotation.location.start.line !== loc.start.line || annotation.location.start.column !== loc.start.column || annotation.rawContent !== error)
{
annotation.destroy();
annotation = new ErrorAnnotation(editor, location, error);
if (secondaryAnnotation)
secondaryAnnotation.destroy();
secondaryAnnotation = new ErrorAnnotation(editor, secondLocation, "");
}
}, 500)
if (compilationCompleteBool)
return;
location = JSON.parse(location);
if (location.start.line)
ensureAnnotation(location, error, type);
}
formatSource = function(line, column)
ensureAnnotation = function(location, error, type)
{
line = parseInt(line);
column = parseInt(column);
if (line > 0)
line = line - 1;
if (column > 0)
column = column - 1;
for (var k in annotations)
{
if (annotations[k].annotation.location.start.line === location.start.line)
{
annotations[k].annotation.destroy();
annotations.splice(k, 1);
break;
}
}
if (type === "second")
error = "";
annotations.push({ "type": type, "annotation": new ErrorAnnotation(editor, location, error)});
}
compilationComplete = function()
{
if (annotation !== null)
{
annotation.destroy();
annotation = null;
}
if (secondaryAnnotation !== null)
{
secondaryAnnotation.destroy();
secondaryAnnotation = null;
}
for (var k in annotations)
annotations[k].annotation.destroy();
annotations.length = 0;
compilationCompleteBool = true;
console.log("end");
}
goToCompilationError = function()
{
editor.setCursor(annotation.start.line, annotation.start.column)
if (annotations.length > 0)
editor.setCursor(annotations[0].annotation.location.start.line, annotations[0].annotation.location.start.column)
}
setFontSize = function(size)
@ -224,5 +206,10 @@ setFontSize = function(size)
editor.refresh();
}
setSourceName = function(_sourceName)
{
sourceName = _sourceName;
}
editor.setOption("extraKeys", extraKeys);

2
test/libethereum/stateOriginal.cpp

@ -25,7 +25,7 @@
#include <secp256k1/secp256k1.h>
#include <libethereum/CanonBlockChain.h>
#include <libethereum/State.h>
#include <libethereum/Farm.h>
//#include <libethereum/Farm.h>
#include <libethereum/Defaults.h>
#include "../TestHelper.h"
using namespace std;

Loading…
Cancel
Save