From e37ddf8eac99eebcf8b48f446665418c0e3315f3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 20 May 2015 11:45:39 +0200 Subject: [PATCH] bug fix --- mix/CodeModel.cpp | 8 +++---- mix/qml/CodeEditorView.qml | 2 +- mix/qml/StateListModel.qml | 1 + mix/qml/WebCodeEditor.qml | 26 +++------------------ mix/qml/html/cm/errorannotation.js | 3 --- mix/qml/html/codeeditor.js | 37 +++++++++++++++--------------- 6 files changed, 27 insertions(+), 50 deletions(-) diff --git a/mix/CodeModel.cpp b/mix/CodeModel.cpp index 9875ee1aa..f10b33408 100644 --- a/mix/CodeModel.cpp +++ b/mix/CodeModel.cpp @@ -331,11 +331,11 @@ QVariantMap CodeModel::resolveCompilationErrorLocation(CompilerStack const& _com { std::tuple 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); diff --git a/mix/qml/CodeEditorView.qml b/mix/qml/CodeEditorView.qml index 1a5e3f0f8..4f5516264 100644 --- a/mix/qml/CodeEditorView.qml +++ b/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(); } diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index f21c93199..a94188a23 100644 --- a/mix/qml/StateListModel.qml +++ b/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); } diff --git a/mix/qml/WebCodeEditor.qml b/mix/qml/WebCodeEditor.qml index babb200e8..b188cacd6 100644 --- a/mix/qml/WebCodeEditor.qml +++ b/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 diff --git a/mix/qml/html/cm/errorannotation.js b/mix/qml/html/cm/errorannotation.js index a8cdb6fe6..33837ed37 100644 --- a/mix/qml/html/cm/errorannotation.js +++ b/mix/qml/html/cm/errorannotation.js @@ -44,6 +44,3 @@ ErrorAnnotation.prototype.destroy = function() if (this.errorMark) this.errorMark.clear(); } - - - diff --git a/mix/qml/html/codeeditor.js b/mix/qml/html/codeeditor.js index fd5d88df0..c85a87597 100644 --- a/mix/qml/html/codeeditor.js +++ b/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);