From ffe373489ed9e9696a21dfb56eea381cb3cf20cb Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Mon, 2 Jul 2018 21:45:08 -0600 Subject: [PATCH] project now resends build msg, not editor; line #s for errors --- src/project.js | 46 ++++++++++++++++++++-------------------- src/ui.js | 32 +++++++++++++--------------- src/worker/workermain.js | 15 ++++++++++--- 3 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/project.js b/src/project.js index ac413f95..f46043bb 100644 --- a/src/project.js +++ b/src/project.js @@ -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 1) { - self.callbackResendFiles(); // TODO: we should handle this internally + self.sendBuild(); pendingWorkerMessages = 0; } else { pendingWorkerMessages = 0; diff --git a/src/ui.js b/src/ui.js index 2dc143e6..8821d644 100644 --- a/src/ui.js +++ b/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").val(preset.id).text(name).attr('selected',preset.id==current_file_id)); + sel.append($("