-
Notifications
You must be signed in to change notification settings - Fork 81
hyperlink compiler error line numbers #143
Changes from all commits
613445a
ab0feb9
e8748c8
7bf3e94
f318eb6
68bb54b
ffa093a
856ac95
55524ef
ad45b11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>"; | ||
} | ||
|
||
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>]"; | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this formatting stay the same way that it was before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done respeccing@60842c3 |
||
.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(/<anon>:(\d+)$/mg, jumpToLine) // panicked at 'foo', $& | ||
.replace(/^<anon>:(\d+):(\d+):\s+(\d+):(\d+)/mg, jumpToRegion) | ||
.replace(/^<anon>:(\d+)/mg, jumpToLine); | ||
} | ||
|
||
addEventListener("DOMContentLoaded", function() { | ||
|
@@ -553,6 +575,8 @@ | |
themes = document.getElementById("themes"); | ||
editor = ace.edit("editor"); | ||
set_result.editor = editor; | ||
editor.$blockScrolling = Infinity; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current rust-playpen actually gives the warning twice: |
||
editor.setAnimatedScroll(true); | ||
session = editor.getSession(); | ||
themelist = ace.require("ace/ext/themelist"); | ||
|
||
|
@@ -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); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried: respeccing@9eb7803