fixed line #s for errors

This commit is contained in:
Steven Hugg 2018-07-02 22:21:08 -06:00
parent 958fbe747f
commit 1176195149
3 changed files with 48 additions and 9 deletions

View File

@ -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;
}

View File

@ -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]
});

View File

@ -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