|
| 1 | +// @ts-check |
| 2 | +/** |
| 3 | + * @type {import("@hediet/debug-visualizer-data-extraction").LoadDataExtractorsFn} |
| 4 | + */ |
| 5 | + module.exports = (register, helpers) => { |
| 6 | + register({ |
| 7 | + id: "map", |
| 8 | + getExtractions(data, collector, context) { |
| 9 | + if (!(data instanceof Map)) { |
| 10 | + return; |
| 11 | + } |
| 12 | + |
| 13 | + collector.addExtraction({ |
| 14 | + priority: 1000, |
| 15 | + id: "map", |
| 16 | + name: "Map", |
| 17 | + extractData() { |
| 18 | + return helpers.asData({ |
| 19 | + kind: { table: true }, |
| 20 | + rows: [...data].map(([k, v]) => ({ key: k, value: v })) |
| 21 | + }); |
| 22 | + }, |
| 23 | + }); |
| 24 | + }, |
| 25 | + }); |
| 26 | + }; |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +/* |
| 32 | + register({ |
| 33 | + id: "binaryViewer", |
| 34 | + getExtractions(data, collector, context) { |
| 35 | + if (typeof data !== "number") { |
| 36 | + return; |
| 37 | + } |
| 38 | +
|
| 39 | + collector.addExtraction({ |
| 40 | + priority: 100, |
| 41 | + id: "binary", |
| 42 | + name: "Bits of Integer", |
| 43 | + extractData() { |
| 44 | + return helpers.asData({ |
| 45 | + kind: { text: true }, |
| 46 | + text: data.toString(2), |
| 47 | + }); |
| 48 | + }, |
| 49 | + }); |
| 50 | + }, |
| 51 | +}); |
| 52 | +
|
| 53 | +*/ |
| 54 | + |
| 55 | +(register, helpers) => { |
| 56 | + register({ |
| 57 | + id: "positionOrRangeInTextModel", |
| 58 | + getExtractions(data, collector, context) { |
| 59 | + collector.addExtraction({ |
| 60 | + priority: 100, |
| 61 | + id: "foo", |
| 62 | + name: "Foo", |
| 63 | + extractData() { |
| 64 | + return helpers.asData({ |
| 65 | + kind: { text: true }, |
| 66 | + text: Object.keys(context.variablesInScope).join(", "), |
| 67 | + }); |
| 68 | + }, |
| 69 | + }); |
| 70 | + }, |
| 71 | + }); |
| 72 | + |
| 73 | + register({ |
| 74 | + id: "positionOrRangeInTextModel", |
| 75 | + getExtractions(data, collector, context) { |
| 76 | + /** @type {{ start: { line: number; column: number; }; end: { line: number; column: number; }; }} */ |
| 77 | + let range; |
| 78 | + if (isRange(data)) { |
| 79 | + range = { |
| 80 | + start: { |
| 81 | + line: data.startLineNumber - 1, |
| 82 | + column: data.startColumn - 1, |
| 83 | + }, |
| 84 | + end: { |
| 85 | + line: data.endLineNumber - 1, |
| 86 | + column: data.endColumn - 1, |
| 87 | + }, |
| 88 | + }; |
| 89 | + } else if (isPosition(data)) { |
| 90 | + range = { |
| 91 | + start: { |
| 92 | + line: data.lineNumber - 1, |
| 93 | + column: data.column - 1, |
| 94 | + }, |
| 95 | + end: { line: data.lineNumber - 1, column: data.column - 1 }, |
| 96 | + }; |
| 97 | + } else { |
| 98 | + return; |
| 99 | + } |
| 100 | + |
| 101 | + if (!isRange(data) && !isPosition(data)) { |
| 102 | + return; |
| 103 | + } |
| 104 | + |
| 105 | + /** @type {any} */ |
| 106 | + const textModel = helpers.find( |
| 107 | + x => |
| 108 | + typeof x === "object" && |
| 109 | + !!x && |
| 110 | + "constructor" in x && |
| 111 | + x.constructor.name === "TextModel" |
| 112 | + ); |
| 113 | + |
| 114 | + collector.addExtraction({ |
| 115 | + id: "positionOrRangeInTextModel", |
| 116 | + name: "Position/Range In TextModel", |
| 117 | + extractData() { |
| 118 | + return helpers.asData({ |
| 119 | + kind: { text: true }, |
| 120 | + text: textModel.getValue(), |
| 121 | + decorations: [{ range }], |
| 122 | + }); |
| 123 | + }, |
| 124 | + priority: 1000, |
| 125 | + }); |
| 126 | + }, |
| 127 | + }); |
| 128 | +}; |
| 129 | + |
| 130 | +/** |
| 131 | + * @return {value is { startColumn: number; startLineNumber: number; endColumn: number; endLineNumber: number; }} |
| 132 | + */ |
| 133 | +function isRange(value) { |
| 134 | + return ( |
| 135 | + typeof value === "object" && |
| 136 | + !!value && |
| 137 | + "startColumn" in value && |
| 138 | + "startLineNumber" in value |
| 139 | + ); |
| 140 | +} |
| 141 | + |
| 142 | +/** |
| 143 | + * @return {value is { column: number; lineNumber: number }} |
| 144 | + */ |
| 145 | +function isPosition(value) { |
| 146 | + return ( |
| 147 | + typeof value === "object" && |
| 148 | + !!value && |
| 149 | + "column" in value && |
| 150 | + "lineNumber" in value |
| 151 | + ); |
| 152 | +} |
0 commit comments