mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-04-28 20:38:09 +00:00
project now resends build msg, not editor; line #s for errors
This commit is contained in:
parent
8edadf142f
commit
ffe373489e
src
@ -27,18 +27,17 @@ function SourceFile(lines, text) {
|
||||
this.lineCount = function() { return lines.length; }
|
||||
}
|
||||
|
||||
function CodeProject(worker, platform_id, platform, store) {
|
||||
function CodeProject(worker, platform_id, platform, store, mainpath) {
|
||||
var self = this;
|
||||
|
||||
var filedata = {};
|
||||
var listings;
|
||||
|
||||
self.callbackResendFiles = function() { }; // TODO?
|
||||
self.callbackBuildResult = function(result) { };
|
||||
self.callbackBuildStatus = function(busy) { };
|
||||
|
||||
var pendingWorkerMessages = 0;
|
||||
|
||||
|
||||
var tools_preloaded = {};
|
||||
function preloadWorker(path) {
|
||||
var tool = platform.getToolForFilename(path);
|
||||
@ -47,6 +46,10 @@ function CodeProject(worker, platform_id, platform, store) {
|
||||
tools_preloaded[tool] = true;
|
||||
}
|
||||
}
|
||||
|
||||
self.setMainPath = function(path) {
|
||||
mainpath = path;
|
||||
}
|
||||
|
||||
// TODO: get local file as well as presets?
|
||||
self.loadFiles = function(paths, callback) {
|
||||
@ -128,15 +131,18 @@ function CodeProject(worker, platform_id, platform, store) {
|
||||
}
|
||||
|
||||
// TODO: test duplicate files, local paths mixed with presets
|
||||
function buildWorkerMessage(mainpath, maintext, depends) {
|
||||
function buildWorkerMessage(depends) {
|
||||
preloadWorker(mainpath);
|
||||
var msg = {updates:[], buildsteps:[]};
|
||||
// TODO: add preproc directive for __MAINFILE__
|
||||
var mainfilename = getFilenameForPath(mainpath);
|
||||
var maintext = self.getFile(mainpath);
|
||||
msg.updates.push({path:mainfilename, data:maintext});
|
||||
msg.buildsteps.push({path:mainfilename, platform:platform_id, tool:platform.getToolForFilename(mainpath), mainfile:true});
|
||||
for (var i=0; i<depends.length; i++) {
|
||||
var dep = depends[i];
|
||||
if (dep.data) {
|
||||
preloadWorker(dep.filename);
|
||||
msg.updates.push({path:dep.filename, data:dep.data});
|
||||
msg.buildsteps.push({path:dep.filename, platform:platform_id, tool:platform.getToolForFilename(dep.path)});
|
||||
}
|
||||
@ -154,29 +160,23 @@ function CodeProject(worker, platform_id, platform, store) {
|
||||
}
|
||||
}
|
||||
|
||||
self.sendBuild = function() {
|
||||
var text = self.getFile(mainpath);
|
||||
loadFileDependencies(text, function(err, depends) {
|
||||
if (err) {
|
||||
console.log(err); // TODO?
|
||||
}
|
||||
var workermsg = buildWorkerMessage(depends);
|
||||
worker.postMessage(workermsg);
|
||||
});
|
||||
}
|
||||
|
||||
self.updateFile = function(path, text, isBinary) {
|
||||
updateFileInStore(path, text); // TODO: isBinary
|
||||
filedata[path] = text;
|
||||
if (okToSend()) {
|
||||
self.callbackBuildStatus(true);
|
||||
preloadWorker(path);
|
||||
loadFileDependencies(text, function(err, depends) {
|
||||
if (err) {
|
||||
console.log(err); // TODO?
|
||||
}
|
||||
if (platform_id != 'verilog') {
|
||||
var workermsg = buildWorkerMessage(path, text, depends);
|
||||
worker.postMessage(workermsg);
|
||||
} else {
|
||||
// TODO: should get rid of this msg format
|
||||
worker.postMessage({
|
||||
code:text,
|
||||
dependencies:depends,
|
||||
platform:platform_id,
|
||||
tool:platform.getToolForFilename(path)
|
||||
});
|
||||
}
|
||||
});
|
||||
self.sendBuild();
|
||||
}
|
||||
};
|
||||
|
||||
@ -200,7 +200,7 @@ function CodeProject(worker, platform_id, platform, store) {
|
||||
|
||||
worker.onmessage = function(e) {
|
||||
if (pendingWorkerMessages > 1) {
|
||||
self.callbackResendFiles(); // TODO: we should handle this internally
|
||||
self.sendBuild();
|
||||
pendingWorkerMessages = 0;
|
||||
} else {
|
||||
pendingWorkerMessages = 0;
|
||||
|
32
src/ui.js
32
src/ui.js
@ -61,7 +61,7 @@ var userPaused;
|
||||
var active_editor;
|
||||
var current_output;
|
||||
var current_preset_entry;
|
||||
var current_file_id;
|
||||
var main_file_id;
|
||||
var assemblyfile;
|
||||
var sourcefile;
|
||||
var symbolmap;
|
||||
@ -97,10 +97,6 @@ function setLastPreset(id) {
|
||||
|
||||
function initProject() {
|
||||
current_project = new CodeProject(newWorker(), platform_id, platform, store);
|
||||
current_project.callbackResendFiles = function() {
|
||||
current_project.updateFile(getActiveEditor().getPath(), getActiveEditor().getValue(), false);
|
||||
// TODO: let CodeProject handle this
|
||||
};
|
||||
current_project.callbackBuildResult = function(result) {
|
||||
setCompileOutput(result);
|
||||
refreshWindowList();
|
||||
@ -111,7 +107,7 @@ function initProject() {
|
||||
} else {
|
||||
toolbar.removeClass("is-busy");
|
||||
toolbar.removeClass("has-errors"); // may be added in next callback
|
||||
getActiveEditor().clearErrors(); // TODO: add current line marker
|
||||
getActiveEditor().clearErrors(); // TODO: remove?
|
||||
}
|
||||
$('#compile_spinner').css('visibility', busy ? 'visible' : 'hidden');
|
||||
};
|
||||
@ -198,7 +194,7 @@ function SourceEditor(path, mode) {
|
||||
var numLines = editor.lineCount();
|
||||
for (var info of errors) {
|
||||
var line = info.line-1;
|
||||
if (line < 0 || line >= numLines) line = numLines-1;
|
||||
if (line < 0 || line >= numLines) line = 0;
|
||||
self.addErrorMarker(line, info.msg);
|
||||
}
|
||||
}
|
||||
@ -691,13 +687,13 @@ function refreshWindowList() {
|
||||
}
|
||||
|
||||
// add main file editor
|
||||
var id = current_file_id;
|
||||
var id = main_file_id;
|
||||
addWindowItem(id, getFilenameForPath(id), loadEditor);
|
||||
|
||||
// add other files
|
||||
separate = true;
|
||||
current_project.iterateFiles(function(id, text) {
|
||||
if (id != current_file_id)
|
||||
if (id != main_file_id)
|
||||
addWindowItem(id, getFilenameForPath(id), loadEditor);
|
||||
});
|
||||
|
||||
@ -729,15 +725,17 @@ function loadProject(preset_id) {
|
||||
preset_id = current_preset_entry.id;
|
||||
}
|
||||
// set current file ID
|
||||
current_file_id = preset_id;
|
||||
main_file_id = preset_id;
|
||||
setLastPreset(preset_id);
|
||||
current_project.setMainPath(preset_id);
|
||||
// load files from storage or web URLs
|
||||
current_project.loadFiles([preset_id], function(err, result) {
|
||||
if (err) {
|
||||
alert(err);
|
||||
} else if (result && result.length) {
|
||||
// we need this to build create functions for the editor (TODO?)
|
||||
refreshWindowList();
|
||||
// show main file (need create window list first)
|
||||
// show main file
|
||||
active_editor = projectWindows.createOrShow(preset_id);
|
||||
}
|
||||
});
|
||||
@ -816,7 +814,7 @@ function handleFileUpload(files) {
|
||||
}
|
||||
|
||||
function getCurrentFilename() {
|
||||
var toks = current_file_id.split("/");
|
||||
var toks = main_file_id.split("/");
|
||||
return toks[toks.length-1];
|
||||
}
|
||||
|
||||
@ -874,7 +872,7 @@ function populateExamples(sel) {
|
||||
for (var i=0; i<PRESETS.length; i++) {
|
||||
var preset = PRESETS[i];
|
||||
var name = preset.chapter ? (preset.chapter + ". " + preset.name) : preset.name;
|
||||
sel.append($("<option />").val(preset.id).text(name).attr('selected',preset.id==current_file_id));
|
||||
sel.append($("<option />").val(preset.id).text(name).attr('selected',preset.id==main_file_id));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -890,12 +888,12 @@ function populateFiles(sel, category, prefix) {
|
||||
if (numFound++ == 0)
|
||||
sel.append($("<option />").text("------- " + category + " -------").attr('disabled',true));
|
||||
var name = key.substring(prefix.length);
|
||||
sel.append($("<option />").val(key).text(name).attr('selected',key==current_file_id));
|
||||
if (key == current_file_id) foundSelected = true;
|
||||
sel.append($("<option />").val(key).text(name).attr('selected',key==main_file_id));
|
||||
if (key == main_file_id) foundSelected = true;
|
||||
}
|
||||
}
|
||||
if (!foundSelected && current_file_id && current_file_id.startsWith(prefix)) {
|
||||
var name = current_file_id.slice(prefix.length);
|
||||
if (!foundSelected && main_file_id && main_file_id.startsWith(prefix)) {
|
||||
var name = main_file_id.slice(prefix.length);
|
||||
var key = prefix + name;
|
||||
sel.append($("<option />").val(key).text(name).attr('selected',true));
|
||||
}
|
||||
|
@ -805,7 +805,7 @@ function linkSDLDZ80(step)
|
||||
var matches = match_aslink_re.exec(s);
|
||||
if (matches) {
|
||||
errors.push({
|
||||
line:1,
|
||||
line:0,
|
||||
msg:matches[2]
|
||||
});
|
||||
}
|
||||
@ -976,7 +976,7 @@ function preprocessMCPP(code, platform, toolname) {
|
||||
// //main.c:2: error: Can't open include file "stdiosd.h"
|
||||
var errors = extractErrors(/[^:]+:(\d+): (.+)/, errout.split("\n"));
|
||||
if (errors.length == 0) {
|
||||
errors = [{line:1, msg:errout}];
|
||||
errors = [{line:0, msg:errout}];
|
||||
}
|
||||
return {errors: errors};
|
||||
}
|
||||
@ -1234,6 +1234,14 @@ var TOOL_PRELOADFS = {
|
||||
'sccz80': 'sccz80',
|
||||
}
|
||||
|
||||
function applyDefaultErrorPath(errors, path) {
|
||||
if (!path) return;
|
||||
for (var i=0; i<errors.length; i++) {
|
||||
var err = errors[i];
|
||||
if (!err.path && err.line) err.path = path;
|
||||
}
|
||||
}
|
||||
|
||||
function executeBuildSteps() {
|
||||
buildstartseq = workerseq;
|
||||
while (buildsteps.length) {
|
||||
@ -1248,11 +1256,12 @@ function executeBuildSteps() {
|
||||
step.result = toolfn(step);
|
||||
} catch (e) {
|
||||
console.log("EXCEPTION", e.stack);
|
||||
return {errors:[{line:1, msg:e+""}]}; // TODO: catch errors already generated?
|
||||
return {errors:[{line:0, msg:e+""}]}; // TODO: catch errors already generated?
|
||||
}
|
||||
if (step.result) {
|
||||
// errors? return them
|
||||
if (step.result.errors) {
|
||||
applyDefaultErrorPath(step.result.errors, step.path);
|
||||
return step.result;
|
||||
}
|
||||
// if we got some output, return it immediately
|
||||
|
Loading…
x
Reference in New Issue
Block a user