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); std::tuple<int, int, int, int> pos = _compiler.positionFromSourceLocation(_location);
QVariantMap startError; QVariantMap startError;
startError.insert("line", std::get<0>(pos) - 1); startError.insert("line", std::get<0>(pos) > 1 ? (std::get<0>(pos) - 1) : 1);
startError.insert("column", std::get<1>(pos) - 1); startError.insert("column", std::get<1>(pos) > 1 ? (std::get<1>(pos) - 1) : 1);
QVariantMap endError; QVariantMap endError;
endError.insert("line", std::get<2>(pos) - 1); endError.insert("line", std::get<2>(pos) > 1 ? (std::get<2>(pos) - 1) : 1);
endError.insert("column", std::get<3>(pos) - 1); endError.insert("column", std::get<3>(pos) > 1 ? (std::get<3>(pos) - 1) : 1);
QVariantMap error; QVariantMap error;
error.insert("start", startError); error.insert("start", startError);
error.insert("end", endError); error.insert("end", endError);

2
mix/qml/CodeEditorView.qml

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

1
mix/qml/StateListModel.qml

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

26
mix/qml/WebCodeEditor.qml

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

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

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

37
mix/qml/html/codeeditor.js

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

Loading…
Cancel
Save