Skip to content
This repository has been archived by the owner on Jun 27, 2018. It is now read-only.

hyperlink compiler error line numbers #143

Closed
wants to merge 10 commits into from
Closed
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: 6 additions & 0 deletions static/web.css
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ button[disabled]:last-child::before {
border-bottom: 1px dashed rgba(0, 0, 0, 0.25);
}

a.linejump {
cursor: pointer;
color: #97248D;
border-bottom: thin #97248D dotted;
}

.ace_dark .rustc-output {
border-bottom-color: rgba(255, 255, 255, 0.25);
}
Expand Down
89 changes: 84 additions & 5 deletions static/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,34 @@
});
}

function jumpToLine(text, r1) {
return "<a onclick=\"javascript:editGo(" + r1 + ",1)\"" +
" onmouseover=\"javascript:editShowLine("+r1+")\"" +
" onmouseout=\"javascript:editRestore()\"" +
" class=\"linejump\">" + text + "</a>";
}

function jumpToRegion(text, r1,c1, r2,c2) {
return "<a onclick=\"javascript:editGo("+r1+","+c1+")\"" +
" onmouseover=\"javascript:editShowRegion("+r1+","+c1+", "+r2+","+c2+")\"" +
" onmouseout=\"javascript:editRestore()\"" +
" class=\"linejump\">" + text + "</a>";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some small docs to these functions to explain what they're doing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


function formatCompilerOutput(text) {
return ansi2html(text).replace(/\[(E\d\d\d\d)\]/g, function(text, code) {
return "[<a href=https://doc.rust-lang.org/error-index.html#" + code + ">" + code + "</a>]";
}).replace(/run `rustc --explain (E\d\d\d\d)` to see a detailed explanation/g, function(text, code) {
return "see the <a href=https://doc.rust-lang.org/error-index.html#" + code + ">detailed explanation for " + code + "</a>";
});
return ansi2html(text)
.replace(/\[(E\d\d\d\d)\]/g,
function(text, code) {
return "[<a href=https://doc.rust-lang.org/error-index.html#" + code + ">" + code + "</a>]";
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this formatting stay the same way that it was before?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done respeccing@60842c3
(I think)

.replace(/run `rustc --explain (E\d\d\d\d)` to see a detailed explanation/g,
function(text, code) {
return "see the <a href=https://doc.rust-lang.org/error-index.html#" + code +
">detailed explanation for " + code + "</a>";
})
.replace(/&lt;anon&gt;:(\d+)$/mg, jumpToLine) // panicked at 'foo', $&
.replace(/^&lt;anon&gt;:(\d+):(\d+):\s+(\d+):(\d+)/mg, jumpToRegion)
.replace(/^&lt;anon&gt;:(\d+)/mg, jumpToLine);
}

addEventListener("DOMContentLoaded", function() {
Expand All @@ -553,6 +575,8 @@
themes = document.getElementById("themes");
editor = ace.edit("editor");
set_result.editor = editor;
editor.$blockScrolling = Infinity;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's up with this variable? It looks like it may be a little fishy...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That var is also used here

It looks like it's needed to be set in order to avoid showing a warning when calling setValue() ajaxorg/ace#2499

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current rust-playpen actually gives the warning twice:
blockcursor

editor.setAnimatedScroll(true);
session = editor.getSession();
themelist = ace.require("ace/ext/themelist");

Expand Down Expand Up @@ -691,3 +715,58 @@

}, false);
}());


// called via javascript:fn events from formatCompilerOutput
var old_range;

function editorGet() {
return window.ace.edit("editor");
}

function editGo(r1,c1) {
var e = editorGet();
old_range = undefined;
e.focus();
e.selection.clearSelection();
e.scrollToLine(r1-1, true, true);
e.selection.moveCursorTo(r1-1, c1-1, false);
}

function editRestore() {
if (old_range) {
var e = editorGet();
e.selection.setSelectionRange(old_range, false);
var mid = (e.getFirstVisibleRow() + e.getLastVisibleRow()) / 2;
var intmid = Math.round(mid);
var extra = (intmid - mid)*2 + 2;
var up = e.getFirstVisibleRow() - old_range.start.row + extra;
var down = old_range.end.row - e.getLastVisibleRow() + extra;
if (up > 0) {
e.scrollToLine(mid - up, true, true);
} else if (down > 0) {
e.scrollToLine(mid + down, true, true);
} // else visible enough
}
}

function editShowRegion(r1,c1, r2,c2) {
var e = editorGet();
var es = e.selection;
old_range = es.getRange();
es.clearSelection();
e.scrollToLine(Math.round((r1 + r2) / 2), true, true);
es.setSelectionAnchor(r1-1, c1-1);
es.selectTo(r2-1, c2-1);
}

function editShowLine(r1) {
var e = editorGet();
var es = e.selection;
old_range = es.getRange();
es.clearSelection();
e.scrollToLine(r1, true, true);
es.moveCursorTo(r1-1, 0);
es.moveCursorLineEnd();
es.selectTo(r1-1, 0);
}