Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,17 @@ func (job compilerJob) Run() error {
env := []string{"GOPROXY=off"} // don't download dependencies
switch job.Compiler {
case "go":
cmd = exec.Command("go", "build", "-trimpath", "-ldflags", "-s -w", "-o", tmpfile, infile.Name())
cmd = exec.Command("go", "build", "-json", "-trimpath", "-ldflags", "-s -w", "-o", tmpfile, infile.Name())
env = append(env, "GOOS=wasip1", "GOARCH=wasm")
case "tinygo":
switch job.Format {
case "wasm", "wasi":
// simulate
tag := strings.Replace(job.Target, "-", "_", -1) // '-' not allowed in tags, use '_' instead
cmd = exec.Command("tinygo", "build", "-o", tmpfile, "-target", job.Format, "-tags", tag, "-no-debug", infile.Name())
cmd = exec.Command("tinygo", "build", "-json", "-o", tmpfile, "-target", job.Format, "-tags", tag, "-no-debug", infile.Name())
default:
// build firmware
cmd = exec.Command("tinygo", "build", "-o", tmpfile, "-target", job.Target, infile.Name())
cmd = exec.Command("tinygo", "build", "-json", "-o", tmpfile, "-target", job.Target, infile.Name())
}
}
buf := &bytes.Buffer{}
Expand Down
3 changes: 3 additions & 0 deletions editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ export class Editor {
if (diag.col <= 0) {
from = index;
to = index + line.length;
} else if (diag.col2 > 0) {
// There is a separate end position for this diagnostic.
to = index + diag.col2 - 1;
}
result.push({
from: from,
Expand Down
2 changes: 1 addition & 1 deletion resources/editor.bundle.min.js

Large diffs are not rendered by default.

51 changes: 44 additions & 7 deletions simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,11 @@ class Simulator {
} else if (msg.type == 'error') {
// There was an error. Terminate the worker, it has no more work to do.
this.#stopWorker();
this.terminal.appendError(msg.message);
let [output, diagnostics] = parseCompilerErrors(msg.message);
this.terminal.appendError(output);
if (msg.source === 'compiler') {
if (this.editor) {
this.editor.setDiagnostics(parseCompilerErrors(msg.message));
this.editor.setDiagnostics(diagnostics);
}
}
} else if (msg.type === 'stdout') {
Expand Down Expand Up @@ -2006,22 +2007,58 @@ function parseUnitMM(value) {
// Parse compiler errors from the Go (or TinyGo) compiler and convert them to an
// array of diagnostics ready to give to the editor.
function parseCompilerErrors(message) {
let output = '';
let diagnostics = [];
let re = new RegExp("^main\.go:([0-9]+)(:([0-9]+))?: (.*)$")
let messageRegExp = new RegExp("^main\.go:([0-9]+)(:([0-9]+))?: (.*)\n$")
let posRegExp = new RegExp("^main\.go:([0-9]+)(:([0-9]+))?$")
let lines = message.split('\n');
for (let line of lines) {
let result = re.exec(line);
if (line === '') continue;

// Parse JSON build output.
if (!line.startsWith('{')) {
console.warn('non-JSON compiler error:', line);
output += line + '\n';
continue;
}
let data;
try {
data = JSON.parse(line);
} catch (e) {
console.warn('failed to parse JSON compiler error:', line);
output += line + '\n';
continue;
}
if (data.Action !== 'build-output') {
continue;
}

// Parse error message.
output += data.Output;
let result = messageRegExp.exec(data.Output);
if (result === null) {
continue;
}
diagnostics.push({

// Create the diagnostic to be sent to the editor.
let diagnostic = {
line: parseInt(result[1]),
col: result[3] ? parseInt(result[3]) : 0,
severity: 'error',
message: result[4],
})
};
diagnostics.push(diagnostic)

// Check whether there is an end position, for slightly better (IDE-like)
// inline error messages.
let endPosParsed = posRegExp.exec(data.EndPos);
if (endPosParsed !== null) {
if (parseInt(endPosParsed[1]) === diagnostic.line) {
diagnostic.col2 = parseInt(endPosParsed[3]);
}
}
}
return diagnostics;
return [output, diagnostics];
}

// Upgrade state object if the configuration is of an older type.
Expand Down