Skip to content

Commit

Permalink
Extend the source code location information to also have an end posit…
Browse files Browse the repository at this point in the history
…ion, use that information to make error messages easier to understand by highlighting source code location of errors, improve control of backtrace format
  • Loading branch information
feeley committed Oct 18, 2023
1 parent 5a3d7c2 commit 556a884
Show file tree
Hide file tree
Showing 29 changed files with 2,077 additions and 1,272 deletions.
27 changes: 12 additions & 15 deletions contrib/try/UI.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// File: "UI.js"

// Copyright (c) 2020-2022 by Marc Feeley, All Rights Reserved.
// Copyright (c) 2020-2023 by Marc Feeley, All Rights Reserved.

//=============================================================================

Expand Down Expand Up @@ -1423,7 +1423,7 @@ UI.prototype.clear_highlighting = function () {
ui.editor_mux.clear_highlighting();
};

UI.prototype.pinpoint = function (container_scm, line0, col0) {
UI.prototype.pinpoint = function (container_scm, start_line0, start_col0, end_line0, end_col0) {

var ui = this;

Expand All @@ -1442,7 +1442,7 @@ UI.prototype.pinpoint = function (container_scm, line0, col0) {

if (ui.file_exists(path)) {
var editor = ui.edit_file(path, true);
return editor.pinpoint(line0, col0);
return editor.pinpoint(start_line0, start_col0, end_line0, end_col0);
}

} else if (container_scm instanceof _ScmSymbol) {
Expand All @@ -1458,7 +1458,7 @@ UI.prototype.pinpoint = function (container_scm, line0, col0) {

if (index >= 0) {
var dev = channels[index];
return dev.pinpoint(line0, col0);
return dev.pinpoint(start_line0, start_col0, end_line0, end_col0);
}

}
Expand Down Expand Up @@ -2473,17 +2473,14 @@ Device_console.prototype.clear_highlighting = function () {
dev.cons.cm.clear_highlighting();
};

Device_console.prototype.pinpoint = function (line0, col0) {
Device_console.prototype.pinpoint = function (start_line0, start_col0, end_line0, end_col0) {

var dev = this;

var start = dev.cons.convert_position(CodeMirror.Pos(line0, col0));
var start = dev.cons.convert_position(CodeMirror.Pos(start_line0, start_col0));
var end = dev.cons.convert_position(CodeMirror.Pos(end_line0, end_col0));

if (start === null) return false;

var end = dev.cons.cm.forward_sexpr(start);

if (!end) return false;
if (!start || !end) return false;

return dev.cons.cm.set_highlighting(start, end);
};
Expand Down Expand Up @@ -3379,14 +3376,14 @@ Editor.prototype.clear_highlighting = function () {
editor.cm.clear_highlighting();
};

Editor.prototype.pinpoint = function (line0, col0) {
Editor.prototype.pinpoint = function (start_line0, start_col0, end_line0, end_col0) {

var editor = this;

var start = CodeMirror.Pos(line0, col0);
var end = editor.cm.forward_sexpr(start);
var start = CodeMirror.Pos(start_line0, start_col0);
var end = CodeMirror.Pos(end_line0, end_col0);

if (!end) return false;
if (!start || !end) return false;

editor.cm.setSelection(end);

Expand Down
55 changes: 38 additions & 17 deletions contrib/try/VM.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

;;; File: "VM.scm"

;;; Copyright (c) 2020-2022 by Marc Feeley, All Rights Reserved.
;;; Copyright (c) 2020-2023 by Marc Feeley, All Rights Reserved.

;;;============================================================================

Expand Down Expand Up @@ -137,11 +137,11 @@ VM.prototype.completions = function (thread_scm, input, cursor) {
return completions;
};

VM.prototype.pinpoint = function (container, line0, col0) {
VM.prototype.pinpoint = function (container, start_line0, start_col0, end_line0, end_col0) {

var vm = this;

if (vm.ui) vm.ui.pinpoint(container, line0, col0);
return vm.ui && vm.ui.pinpoint(container, start_line0, start_col0, end_line0, end_col0);
};

main_vm = new VM();
Expand Down Expand Up @@ -236,29 +236,50 @@ EOF

(##pinpoint-locat-hook-set!
(lambda (locat)
(let* ((container (##locat-container locat))
(filepos (##position->filepos (##locat-position locat)))
(line0 (##filepos-line filepos))
(col0 (##filepos-col filepos)))
(##os-pinpoint container line0 col0))))

(define (##os-pinpoint container line0 col0)
(let* ((container
(##locat-container locat))
(start-filepos
(##position->filepos
(##locat-start-position locat)))
(end-filepos
(##position->filepos
(or (##locat-end-position locat)
(let ((line (##filepos-line start-filepos))
(col (##filepos-col start-filepos)))
(##filepos->position
(##make-filepos line (##fx+ col 1) 0))))))
(start-line0
(##filepos-line start-filepos))
(start-col0
(##filepos-col start-filepos))
(end-line0
(##filepos-line end-filepos))
(end-col0
(##filepos-col end-filepos)))
(or (##os-pinpoint container start-line0 start-col0 end-line0 end-col0)
(##default-pinpoint-locat locat)))))

(define (##os-pinpoint container start-line0 start-col0 end-line0 end-col0)
(##inline-host-declaration "
@os_pinpoint@ = function (vm, container_scm, line0_scm, col0_scm) {
@os_pinpoint@ = function (vm, container_scm, start_line0_scm, start_col0_scm, end_line0_scm, end_col0_scm) {
var line0 = @scm2host@(line0_scm);
var col0 = @scm2host@(col0_scm);
var start_line0 = @scm2host@(start_line0_scm);
var start_col0 = @scm2host@(start_col0_scm);
var end_line0 = @scm2host@(end_line0_scm);
var end_col0 = @scm2host@(end_col0_scm);
return @host2foreign@(vm.pinpoint(container_scm, line0, col0));
return @host2foreign@(vm.pinpoint(container_scm, start_line0, start_col0, end_line0, end_col0));
};
")
(##inline-host-expression
"@os_pinpoint@(main_vm,@1@,@2@,@3@)"
"@os_pinpoint@(main_vm,@1@,@2@,@3@,@4@,@5@)"
container
line0
col0))
start-line0
start-col0
end-line0
end-col0))

;; Enable web console.

Expand Down

0 comments on commit 556a884

Please sign in to comment.