Skip to content

Commit 4f0d6fe

Browse files
committed
updated debugger input handeling adding a feature for detecting when input is changed mid way through run
now user.js calls Debugger runnoTrace addedd error reporting in the editor
1 parent 96ac36d commit 4f0d6fe

File tree

8 files changed

+452
-84
lines changed

8 files changed

+452
-84
lines changed

.jshintrc

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,12 @@
2626
"expr": true,
2727
"maxerr": 100,
2828
"predef": [
29-
"require",
30-
"define",
31-
"afterEach",
32-
"beforeEach",
33-
"confirm",
34-
"context",
35-
"describe",
36-
"expect",
37-
"it",
38-
"jasmine",
39-
"JSHINT",
40-
"mostRecentAjaxRequest",
41-
"qq",
42-
"runs",
43-
"spyOn",
44-
"spyOnEvent",
45-
"waitsFor",
46-
"xdescribe"
29+
"__BRYTHON__",
4730
],
4831
"globals": {
4932
"$": true,
5033
"Modernizr": true,
5134
"jQuery": true
5235
},
53-
"indent": 2
36+
"indent": 4
5437
}

client/scripts/cm-lint-custom.js

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: http://codemirror.net/LICENSE
3+
4+
(function(mod) {
5+
if (typeof exports == "object" && typeof module == "object") // CommonJS
6+
mod(require("../../lib/codemirror"));
7+
else if (typeof define == "function" && define.amd) // AMD
8+
define(["../../lib/codemirror"], mod);
9+
else // Plain browser env
10+
mod(CodeMirror);
11+
})(function(CodeMirror) {
12+
"use strict";
13+
var GUTTER_ID = "CodeMirror-lint-markers";
14+
15+
function showTooltip(e, content) {
16+
var tt = document.createElement("div");
17+
tt.className = "CodeMirror-lint-tooltip";
18+
tt.appendChild(content.cloneNode(true));
19+
document.body.appendChild(tt);
20+
21+
function position(e) {
22+
if (!tt.parentNode) return CodeMirror.off(document, "mousemove", position);
23+
tt.style.top = Math.max(0, e.clientY - tt.offsetHeight - 5) + "px";
24+
tt.style.left = (e.clientX + 5) + "px";
25+
}
26+
CodeMirror.on(document, "mousemove", position);
27+
position(e);
28+
if (tt.style.opacity != null) tt.style.opacity = 1;
29+
return tt;
30+
}
31+
function rm(elt) {
32+
if (elt.parentNode) elt.parentNode.removeChild(elt);
33+
}
34+
function hideTooltip(tt) {
35+
if (!tt.parentNode) return;
36+
if (tt.style.opacity == null) rm(tt);
37+
tt.style.opacity = 0;
38+
setTimeout(function() { rm(tt); }, 600);
39+
}
40+
41+
function showTooltipFor(e, content, node) {
42+
var tooltip = showTooltip(e, content);
43+
function hide() {
44+
CodeMirror.off(node, "mouseout", hide);
45+
if (tooltip) { hideTooltip(tooltip); tooltip = null; }
46+
}
47+
var poll = setInterval(function() {
48+
if (tooltip) for (var n = node;; n = n.parentNode) {
49+
if (n == document.body) return;
50+
if (!n) { hide(); break; }
51+
}
52+
if (!tooltip) return clearInterval(poll);
53+
}, 400);
54+
CodeMirror.on(node, "mouseout", hide);
55+
}
56+
57+
function LintState(cm, options, hasGutter) {
58+
this.marked = [];
59+
this.options = options;
60+
this.timeout = null;
61+
this.hasGutter = hasGutter;
62+
this.onMouseOver = function(e) { onMouseOver(cm, e); };
63+
}
64+
65+
function parseOptions(cm, options) {
66+
if (options instanceof Function) return {getAnnotations: options};
67+
if (!options || options === true) options = {};
68+
if (!options.getAnnotations) options.getAnnotations = cm.getHelper(CodeMirror.Pos(0, 0), "lint");
69+
// if (!options.getAnnotations) throw new Error("Required option 'getAnnotations' missing (lint addon)");
70+
return options;
71+
}
72+
73+
function clearMarks(cm) {
74+
var state = cm.state.lint;
75+
if (state.hasGutter) cm.clearGutter(GUTTER_ID);
76+
for (var i = 0; i < state.marked.length; ++i)
77+
state.marked[i].clear();
78+
state.marked.length = 0;
79+
}
80+
81+
function makeMarker(labels, severity, multiple, tooltips) {
82+
var marker = document.createElement("div"), inner = marker;
83+
marker.className = "CodeMirror-lint-marker-" + severity;
84+
if (multiple) {
85+
inner = marker.appendChild(document.createElement("div"));
86+
inner.className = "CodeMirror-lint-marker-multiple";
87+
}
88+
89+
if (tooltips != false) CodeMirror.on(inner, "mouseover", function(e) {
90+
showTooltipFor(e, labels, inner);
91+
});
92+
93+
return marker;
94+
}
95+
96+
function getMaxSeverity(a, b) {
97+
if (a == "error") return a;
98+
else return b;
99+
}
100+
101+
function groupByLine(annotations) {
102+
var lines = [];
103+
for (var i = 0; i < annotations.length; ++i) {
104+
var ann = annotations[i], line = ann.from.line;
105+
(lines[line] || (lines[line] = [])).push(ann);
106+
}
107+
return lines;
108+
}
109+
110+
function annotationTooltip(ann) {
111+
var severity = ann.severity;
112+
if (!severity) severity = "error";
113+
var tip = document.createElement("div");
114+
tip.className = "CodeMirror-lint-message-" + severity;
115+
tip.appendChild(document.createTextNode(ann.message));
116+
return tip;
117+
}
118+
119+
function updateLinting(cm, annotationsNotSorted) {
120+
clearMarks(cm);
121+
var state = cm.state.lint, options = state.options;
122+
123+
var annotations = groupByLine(annotationsNotSorted);
124+
125+
for (var line = 0; line < annotations.length; ++line) {
126+
var anns = annotations[line];
127+
if (!anns) continue;
128+
129+
var maxSeverity = null;
130+
var tipLabel = state.hasGutter && document.createDocumentFragment();
131+
132+
for (var i = 0; i < anns.length; ++i) {
133+
var ann = anns[i];
134+
var severity = ann.severity;
135+
if (!severity) severity = "error";
136+
maxSeverity = getMaxSeverity(maxSeverity, severity);
137+
138+
if (options.formatAnnotation) ann = options.formatAnnotation(ann);
139+
if (state.hasGutter) tipLabel.appendChild(annotationTooltip(ann));
140+
141+
if (ann.to) state.marked.push(cm.markText(ann.from, ann.to, {
142+
className: "CodeMirror-lint-mark-" + severity,
143+
__annotation: ann
144+
}));
145+
}
146+
147+
if (state.hasGutter)
148+
cm.setGutterMarker(line, GUTTER_ID, makeMarker(tipLabel, maxSeverity, anns.length > 1,
149+
state.options.tooltips));
150+
}
151+
if (options.onUpdateLinting) options.onUpdateLinting(annotationsNotSorted, annotations, cm);
152+
}
153+
154+
function popupSpanTooltip(ann, e) {
155+
var target = e.target || e.srcElement;
156+
showTooltipFor(e, annotationTooltip(ann), target);
157+
}
158+
159+
// When the mouseover fires, the cursor might not actually be over
160+
// the character itself yet. These pairs of x,y offsets are used to
161+
// probe a few nearby points when no suitable marked range is found.
162+
var nearby = [0, 0, 0, 5, 0, -5, 5, 0, -5, 0];
163+
164+
function onMouseOver(cm, e) {
165+
if (!/\bCodeMirror-lint-mark-/.test((e.target || e.srcElement).className)) return;
166+
for (var i = 0; i < nearby.length; i += 2) {
167+
var spans = cm.findMarksAt(cm.coordsChar({left: e.clientX + nearby[i],
168+
top: e.clientY + nearby[i + 1]}, "client"));
169+
for (var j = 0; j < spans.length; ++j) {
170+
var span = spans[j], ann = span.__annotation;
171+
if (ann) return popupSpanTooltip(ann, e);
172+
}
173+
}
174+
}
175+
176+
CodeMirror.defineOption("lint", false, function(cm, val, old) {
177+
cm.updateLinting = function (annotationsNotSorted) {
178+
updateLinting(cm,annotationsNotSorted);
179+
};
180+
181+
if (old && old != CodeMirror.Init) {
182+
clearMarks(cm);
183+
CodeMirror.off(cm.getWrapperElement(), "mouseover", cm.state.lint.onMouseOver);
184+
delete cm.state.lint;
185+
}
186+
187+
if (val) {
188+
var gutters = cm.getOption("gutters"), hasLintGutter = false;
189+
for (var i = 0; i < gutters.length; ++i) if (gutters[i] == GUTTER_ID) hasLintGutter = true;
190+
var state = cm.state.lint = new LintState(cm, parseOptions(cm, val), hasLintGutter);
191+
if (state.options.tooltips != false)
192+
CodeMirror.on(cm.getWrapperElement(), "mouseover", state.onMouseOver);
193+
194+
}
195+
});
196+
});

client/scripts/cm-lint-result.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(function(mod) {
2+
if (typeof exports == "object" && typeof module == "object") // CommonJS
3+
mod(require("../../lib/codemirror"));
4+
else if (typeof define == "function" && define.amd) // AMD
5+
define(["../../lib/codemirror"], mod);
6+
else // Plain browser env
7+
mod(CodeMirror);
8+
})(function(CodeMirror) {
9+
"use strict";
10+
CodeMirror.lintResult = function (error_list) {
11+
var found = [];
12+
13+
error_list.forEach(function (error)
14+
{
15+
16+
var start_line = error.line_no;
17+
18+
var start_char;
19+
if(typeof(error.column_no_start) !== "undefined")
20+
start_char = error.column_no_start;
21+
else
22+
start_char = error.column_no;
23+
24+
var end_char;
25+
if(typeof(error.column_no_stop) !== "undefined")
26+
end_char = error.column_no_stop;
27+
else
28+
end_char = error.column_no;
29+
30+
var end_line = error.line_no;
31+
var message = error.message;
32+
33+
var severity;
34+
if(typeof(error.severity) !== "undefined")
35+
severity = error.severity;
36+
else
37+
severity = 'error';
38+
39+
found.push({
40+
from: CodeMirror.Pos(start_line - 1, start_char),
41+
to: CodeMirror.Pos(end_line - 1, end_char),
42+
message: message,
43+
severity: severity // "error", "warning"
44+
});
45+
});
46+
47+
return found;
48+
};
49+
});
50+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
CodeMirror.remoteValidator = function(cm, updateLinting, options) {
2+
var text = cm.getValue();
3+
4+
if(text.trim() == "")
5+
{
6+
updateLinting(cm, []);
7+
return;
8+
}
9+
10+
function result_cb(error_list)
11+
{
12+
var found = [];
13+
14+
error_list.forEach(function (error)
15+
{
16+
17+
var start_line = error.line_no;
18+
19+
var start_char;
20+
if(typeof(error.column_no_start) != "undefined")
21+
start_char = error.column_no_start;
22+
else
23+
start_char = error.column_no;
24+
25+
var end_char;
26+
if(typeof(error.column_no_stop) != "undefined")
27+
end_char = error.column_no_stop;
28+
else
29+
end_char = error.column_no;
30+
31+
var end_line = error.line_no;
32+
var message = error.message;
33+
34+
var severity;
35+
if(typeof(error.severity) != "undefined")
36+
severity = error.severity;
37+
else
38+
severity = 'error';
39+
40+
found.push({
41+
from: CodeMirror.Pos(start_line - 1, start_char),
42+
to: CodeMirror.Pos(end_line - 1, end_char),
43+
message: message,
44+
severity: severity // "error", "warning"
45+
});
46+
});
47+
48+
updateLinting(cm, found);
49+
}
50+
51+
options.check_cb(text, result_cb)
52+
}
53+

0 commit comments

Comments
 (0)