From 11761951493406a0b97183fd83bf65c4f16eea3f Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Mon, 2 Jul 2018 22:21:08 -0600 Subject: [PATCH] fixed line #s for errors --- src/ui.js | 33 +++++++++++++++++++++++++++------ src/worker/workermain.js | 2 +- test/cli/testworker.js | 22 ++++++++++++++++++++-- 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/src/ui.js b/src/ui.js index 8821d644..7b49a65d 100644 --- a/src/ui.js +++ b/src/ui.js @@ -107,7 +107,7 @@ function initProject() { } else { toolbar.removeClass("is-busy"); toolbar.removeClass("has-errors"); // may be added in next callback - getActiveEditor().clearErrors(); // TODO: remove? + projectWindows.setErrors(null); } $('#compile_spinner').css('visibility', busy ? 'visible' : 'hidden'); }; @@ -190,12 +190,14 @@ function SourceEditor(path, mode) { self.markErrors = function(errors) { // TODO: move cursor to error line if offscreen? self.clearErrors(); - toolbar.addClass("has-errors"); var numLines = editor.lineCount(); for (var info of errors) { - var line = info.line-1; - if (line < 0 || line >= numLines) line = 0; - self.addErrorMarker(line, info.msg); + // only mark errors with this filename, or without any filename + if (!info.path || path.endsWith(info.path)) { + var line = info.line-1; + if (line < 0 || line >= numLines) line = 0; + self.addErrorMarker(line, info.msg); + } } } @@ -595,11 +597,13 @@ function MemoryView() { ///// function ProjectWindows(containerdiv) { + var self = this; var id2window = {}; var id2createfn = {}; var id2div = {}; var activewnd; var activediv; + var lasterrors; this.setCreateFunc = function(id, createfn) { id2createfn[id] = createfn; @@ -621,6 +625,7 @@ function ProjectWindows(containerdiv) { activewnd = wnd; $(div).show(); this.refresh(); + this.refreshErrors(); } return wnd; } @@ -647,6 +652,20 @@ function ProjectWindows(containerdiv) { if (activewnd && activewnd.tick) activewnd.tick(); } + + this.setErrors = function(errors) { + lasterrors = errors; + this.refreshErrors(); + } + + this.refreshErrors = function() { + if (activewnd && activewnd.markErrors) { + if (lasterrors && lasterrors.length) + activewnd.markErrors(lasterrors); + else + activewnd.clearErrors(); + } + } }; var projectWindows = new ProjectWindows($("#workspace")[0]); @@ -918,7 +937,8 @@ function setCompileOutput(data) { var sed = getActiveEditor(); // errors? mark them in editor if (data.errors && data.errors.length > 0) { - sed.markErrors(data.errors); + projectWindows.setErrors(data.errors); + toolbar.addClass("has-errors"); } else { // choose first listing (TODO:support multiple source files) sourcefile = null; @@ -1108,6 +1128,7 @@ function jumpToLine(ed, i) { } function getVisibleSourceFile() { +// TODO var div = $("#disassembly"); return div.is(':visible') ? assemblyfile : sourcefile; } diff --git a/src/worker/workermain.js b/src/worker/workermain.js index 71e70e54..52c1d08a 100644 --- a/src/worker/workermain.js +++ b/src/worker/workermain.js @@ -319,7 +319,7 @@ function msvcErrorMatcher(errors) { var errline = parseInt(matches[2]); errors.push({ line:errline, - path:matches[1], + //path:matches[1], type:matches[3], msg:matches[4] }); diff --git a/test/cli/testworker.js b/test/cli/testworker.js index 020dc27e..3b54046e 100644 --- a/test/cli/testworker.js +++ b/test/cli/testworker.js @@ -191,7 +191,7 @@ describe('Worker', function() { ]; doBuild(msgs, done, 8192, [1,1], 0); }); - // TODO: doesn't fail + // TODO: tests don't fail if too many compile steps it('should not build unchanged files with CC65', function(done) { var m = { "updates":[ @@ -238,9 +238,27 @@ describe('Worker', function() { var msgs = [m, m, m2]; doBuild(msgs, done, 8192, [1,1], 0); }); + it('should include filename in compile errors', function(done) { + var m = { + "updates":[ + {"path":"main.c", "data":"extern int mul2(int x);\n int main() { return mul2(2); }\n"}, + {"path":"fn.c", "data":"void int mul2(int x) { return x*x; }\n"} + ], + "buildsteps":[ + {"path":"main.c", "platform":"mw8080bw", "tool":"sdcc"}, + {"path":"fn.c", "platform":"mw8080bw", "tool":"sdcc"} + ] + }; + var msgs = [m]; + doBuild(msgs, function(err, result) { + for (var msg of result.errors) + assert.equal(msg.path, "fn.c"); + done(); + }, 8192, [1,1], 2); // TODO: check error file + }); it('should compile vicdual skeleton', function(done) { var files = ['skeleton.sdcc', 'cp437.c']; - compileFiles('sdcc', files, 'vicdual', done, 16416, [0,45], 0); + compileFiles('sdcc', files, 'vicdual', done, 16416, [0,45], 0); // TODO? }); // TODO: test if compile, errors, then compile same file