Browse Source

bug fix

cl-refactor
yann300 10 years ago
parent
commit
e37ddf8eac
  1. 8
      mix/CodeModel.cpp
  2. 2
      mix/qml/CodeEditorView.qml
  3. 1
      mix/qml/StateListModel.qml
  4. 26
      mix/qml/WebCodeEditor.qml
  5. 3
      mix/qml/html/cm/errorannotation.js
  6. 37
      mix/qml/html/codeeditor.js

8
mix/CodeModel.cpp

@ -331,11 +331,11 @@ QVariantMap CodeModel::resolveCompilationErrorLocation(CompilerStack const& _com
{
std::tuple<int, int, int, int> pos = _compiler.positionFromSourceLocation(_location);
QVariantMap startError;
startError.insert("line", std::get<0>(pos) - 1);
startError.insert("column", std::get<1>(pos) - 1);
startError.insert("line", std::get<0>(pos) > 1 ? (std::get<0>(pos) - 1) : 1);
startError.insert("column", std::get<1>(pos) > 1 ? (std::get<1>(pos) - 1) : 1);
QVariantMap endError;
endError.insert("line", std::get<2>(pos) - 1);
endError.insert("column", std::get<3>(pos) - 1);
endError.insert("line", std::get<2>(pos) > 1 ? (std::get<2>(pos) - 1) : 1);
endError.insert("column", std::get<3>(pos) > 1 ? (std::get<3>(pos) - 1) : 1);
QVariantMap error;
error.insert("start", startError);
error.insert("end", endError);

2
mix/qml/CodeEditorView.qml

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

1
mix/qml/StateListModel.qml

@ -225,6 +225,7 @@ Item {
var ctorTr = defaultTransactionItem();
ctorTr.functionId = c;
ctorTr.contractId = c;
ctorTr.label = qsTr("Deploy") + " " + ctorTr.contractId;
ctorTr.sender = item.accounts[0].secret;
item.transactions.push(ctorTr);
}

26
mix/qml/WebCodeEditor.qml

@ -83,13 +83,6 @@ Item {
editorBrowser.runJavaScript("setFontSize(" + size + ")", function(result) {});
}
function setSourceName(_sourceName)
{
sourceName = _sourceName;
if (initialized && editorBrowser)
editorBrowser.runJavaScript("setSourceName('" + sourceName + "')", function(result) {});
}
Clipboard
{
id: clipboard
@ -148,29 +141,16 @@ Item {
{
if (!editorBrowser || !error)
return;
var lineError = firstLocation.start.line + 1;
var errorOrigin = "source error in " + firstLocation.contractName + " line " + lineError
var secondErrorDetail = " Secondary sources: ";
for (var k in secondLocations)
{
lineError = secondLocations[k].start.line + 1;
secondErrorDetail += secondLocations[k].contractName + " line " + lineError + " - ";
displayErrorAnnotations(secondLocations[k], errorOrigin, "second");
}
var detail = error.split('\n')[0];
var reg = detail.match(/:\d+:\d+:/g);
if (reg !== null)
detail = detail.replace(reg[0], "");
if (secondLocations.length > 0)
detail += secondErrorDetail;
displayErrorAnnotations(firstLocation, detail, "first");
displayErrorAnnotations(detail, firstLocation, secondLocations);
}
function displayErrorAnnotations(location, detail, type)
function displayErrorAnnotations(detail, location, secondaryErrors)
{
if (location.source === parent.sourceName)
editorBrowser.runJavaScript("compilationError('" + JSON.stringify(location) + "', '" + detail + "', '" + type + "')", function(result){});
editorBrowser.runJavaScript("compilationError('" + sourceName + "', '" + JSON.stringify(location) + "', '" + detail + "', '" + JSON.stringify(secondaryErrors) + "')", function(result){});
}
Timer

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

@ -44,6 +44,3 @@ ErrorAnnotation.prototype.destroy = function()
if (this.errorMark)
this.errorMark.clear();
}

37
mix/qml/html/codeeditor.js

@ -8,7 +8,6 @@ var editor = CodeMirror(document.body, {
styleSelectedText: true
});
var ternServer;
var sourceName = "";
editor.setOption("theme", "inkpot");
editor.setOption("indentUnit", 4);
@ -160,35 +159,40 @@ showWarning = function(content)
var annotations = [];
var compilationCompleteBool = true;
compilationError = function(location, error, type)
compilationError = function(currentSourceName, location, error, secondaryErrors)
{
compilationCompleteBool = false;
if (compilationCompleteBool)
return;
clearAnnotations();
location = JSON.parse(location);
if (location.start.line)
ensureAnnotation(location, error, type);
if (location.source === currentSourceName)
ensureAnnotation(location, error, "first");
var lineError = location.start.line + 1;
var errorOrigin = "Source " + location.contractName + " line " + lineError;
secondaryErrors = JSON.parse(secondaryErrors);
for(var i in secondaryErrors)
{
if (secondaryErrors[i].source === currentSourceName)
ensureAnnotation(secondaryErrors[i], errorOrigin, "second");
}
}
ensureAnnotation = function(location, error, type)
{
for (var k in annotations)
{
if (annotations[k].annotation.location.start.line === location.start.line)
{
annotations[k].annotation.destroy();
annotations.splice(k, 1);
break;
}
}
annotations.push({ "type": type, "annotation": new ErrorAnnotation(editor, location, error)});
}
compilationComplete = function()
clearAnnotations = function()
{
for (var k in annotations)
annotations[k].annotation.destroy();
annotations.length = 0;
}
compilationComplete = function()
{
clearAnnotations();
compilationCompleteBool = true;
}
@ -204,10 +208,5 @@ setFontSize = function(size)
editor.refresh();
}
setSourceName = function(_sourceName)
{
sourceName = _sourceName;
}
editor.setOption("extraKeys", extraKeys);

Loading…
Cancel
Save