From eb7b665536c04fdc071530b7d00f80de29ef9723 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Thu, 20 Aug 2020 11:41:58 -0500 Subject: [PATCH] if error line position is available, underline --- css/ui.css | 3 +++ src/common/basic/compiler.ts | 3 ++- src/ide/views.ts | 30 +++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/css/ui.css b/css/ui.css index 3012b5d0..396b60d5 100644 --- a/css/ui.css +++ b/css/ui.css @@ -28,6 +28,9 @@ .currentpc-marker-blocked { color: #ffee33; } +.mark-error { + text-decoration: underline wavy 1px #ff6666; +} .tooltipbox { position: relative; display: inline-block; diff --git a/src/common/basic/compiler.ts b/src/common/basic/compiler.ts index 362ac39f..b1c95b37 100644 --- a/src/common/basic/compiler.ts +++ b/src/common/basic/compiler.ts @@ -353,7 +353,8 @@ export class BASICParser { this.scopestack = []; } addError(msg: string, loc?: SourceLocation) { - if (!loc) loc = this.peekToken().$loc; + var tok = this.lasttoken || this.peekToken(); + if (!loc) loc = tok.$loc; this.errors.push({path:loc.path, line:loc.line, label:this.curlabel, start:loc.start, end:loc.end, msg:msg}); } compileError(msg: string, loc?: SourceLocation) { diff --git a/src/ide/views.ts b/src/ide/views.ts index 1b2a38ec..7ff7c52d 100644 --- a/src/ide/views.ts +++ b/src/ide/views.ts @@ -92,6 +92,7 @@ export class SourceEditor implements ProjectView { markCurrentPC; // TextMarker errormsgs = []; errorwidgets = []; + errormarks = []; inspectWidget; createDiv(parent:HTMLElement) { @@ -210,6 +211,23 @@ export class SourceEditor implements ProjectView { getPath() : string { return this.path; } + addError(info: WorkerError) { + // only mark errors with this filename, or without any filename + if (!info.path || this.path.endsWith(info.path)) { + var numLines = this.editor.lineCount(); + var line = info.line-1; + if (line < 0 || line >= numLines) line = 0; + this.addErrorMarker(line, info.msg); + if (info.start != null) { + var markOpts = {className:"mark-error", inclusiveLeft:true}; + var start = {line:line, ch:info.end?info.start:info.start-1}; + var end = {line:line, ch:info.end?info.end:info.start}; + var mark = this.editor.markText(start, end, markOpts); + this.errormarks.push(mark); + } + } + } + addErrorMarker(line:number, msg:string) { var div = document.createElement("div"); div.setAttribute("class", "tooltipbox tooltiperror"); @@ -237,15 +255,9 @@ export class SourceEditor implements ProjectView { markErrors(errors:WorkerError[]) { // TODO: move cursor to error line if offscreen? this.clearErrors(); - var numLines = this.editor.lineCount(); errors = errors.slice(0, MAX_ERRORS); for (var info of errors) { - // only mark errors with this filename, or without any filename - if (!info.path || this.path.endsWith(info.path)) { - var line = info.line-1; - if (line < 0 || line >= numLines) line = 0; - this.addErrorMarker(line, info.msg); - } + this.addError(info); } } @@ -255,8 +267,8 @@ export class SourceEditor implements ProjectView { this.dirtylisting = true; // clear line widgets this.errormsgs = []; - while (this.errorwidgets.length) - this.errorwidgets.shift().clear(); + while (this.errorwidgets.length) this.errorwidgets.shift().clear(); + while (this.errormarks.length) this.errormarks.shift().clear(); } getSourceFile() : SourceFile { return this.sourcefile; }