@readable-js/react-codemirror
Version:
React component for ReadableJS
46 lines • 2.17 kB
JavaScript
import { Decoration } from "@codemirror/view";
import { ReadableWidget } from './readable-widget';
export function readableMessages(view, getCallStack, currentStep, skipEvaluation) {
let widgets = [];
let calls = getCallStack(view, skipEvaluation);
// one call at time, we don't display all of them, because their can be multiple calls
// for the same line
if (calls && calls.length > 0) {
// const lineStart = calls[currentStep].loc.start.line;
// const rangeEnd = calls[currentStep].range[1];
const decoColor = Decoration.line({
attributes: { class: 'cm-readable-js-highlight' }
});
for (let i = 0; i < calls[currentStep].messages.length; i++) {
const [lineStart, lineEnd, message] = calls[currentStep].messages[i];
for (let j = lineStart; j <= lineEnd; j++) {
widgets.push(decoColor.range(view.state.doc.line(j).from));
}
let decoText = Decoration.widget({
widget: new ReadableWidget(message),
side: 1
});
widgets.push(decoText.range(view.state.doc.line(lineEnd).to));
}
// decoLine need the range starting from the start of the line (no indentation or other)
// let lineRangeStart = view.state.doc.lineAt(calls[currentStep].range[0]);
// let lineRangeEnd = view.state.doc.lineAt(calls[currentStep].range[1]);
// if one instruction take multiple line, we want all the line to be colored
// otherwise we could just do decoColor.range(lineRangeStart.from)
// for (let i = lineRangeStart.number; i <= lineRangeEnd.number; i++) {
// widgets.push(
// decoColor.range(view.state.doc.line(i).from)
// );
// }
// let decoText = Decoration.widget({
// widget: new ReadableWidget(calls[currentStep].message),
// side: 1
// });
//
// widgets.push(
// decoText.range(lineRangeEnd.to)
// );
}
return Decoration.set(widgets);
}
//# sourceMappingURL=readableMessages.js.map