MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / sourceViewer

Function sourceViewer

libatomic/src/review/viewer.js:252–302  ·  view source on GitHub ↗
(region)

Source from the content-addressed store, hash-verified

250 }
251
252 function sourceViewer(region) {
253 const host = el('section');
254 const toolbar = el('div', 'source-toolbar'), body = el('div'), caption = el('p', 'source-caption');
255 let side = region.side, full = false;
256 const before = button('Before', () => { side = 'before'; full = false; update(); });
257 const after = button('After', () => { side = 'after'; full = false; update(); });
258 const diff = button('Recorded change diff', () => { side = 'diff'; update(); });
259 const expand = button('Show full file', () => { full = !full; update(); });
260 if (viewSnapshot) { before.hidden = true; diff.hidden = true; after.textContent = 'View snapshot'; side = 'after'; }
261 if (viewComparison) { diff.hidden=true;before.textContent='Before: '+comparisonBefore.view;after.textContent='After: '+comparisonAfter.view; }
262 toolbar.append(before, after, diff, expand);
263 host.append(toolbar, body, caption);
264 function update() {
265 before.setAttribute('aria-pressed', String(side === 'before'));
266 after.setAttribute('aria-pressed', String(side === 'after'));
267 diff.setAttribute('aria-pressed', String(side === 'diff'));
268 body.replaceChildren();
269 expand.hidden = side === 'diff';
270 if (side === 'diff') {
271 const change = changes.get(region.change);
272 body.append(el('pre', 'source-code', change?.diff ? change.diff.replace(/\x1b\[[0-9;]*m/g, '') : 'Recorded diff unavailable: ' + (change?.diff_status || 'not supplied')));
273 caption.textContent = 'Entire selected change diff, not limited to this region. Unchanged caller context may have no hunk.';
274 return;
275 }
276 const snapshot = snapshots.get(region.change + '\0' + region.path);
277 const source = snapshot?.[side];
278 if (!source || source.status !== 'present') {
279 body.append(el('p', 'empty', source?.status === 'absent' ? 'This file is absent in this recorded revision.' : source?.reason || 'Recorded source was not exported. No working-copy bytes are substituted.'));
280 expand.hidden = true;
281 caption.textContent = viewComparison ? `${side==='before'?'Before':'After'} view ${(side==='before'?comparisonBefore:comparisonAfter).view}` : viewSnapshot ? `Recorded view ${viewSnapshot.view} @ ${viewSnapshot.state}` : `${side} snapshot · change ${region.change}`;
282 return;
283 }
284 const range = counterpart(region, side);
285 const lines = source.text.split('\n');
286 const start = full || !range.start ? 1 : Math.max(1, range.start - 6);
287 const end = full ? lines.length : Math.min(lines.length, Math.max(start + 30, Math.min((range.end || start) + 6, start + 399)));
288 const code = el('div', 'source-code');
289 code.setAttribute('aria-label', `${side} recorded source, lines ${start} through ${end}`);
290 for (let i = start; i <= end; i++) {
291 const line = el('div', 'source-line' + (range.start && i >= range.start && i <= range.end ? ' highlight' : ''));
292 const number = el('span', 'line-number', i); number.setAttribute('aria-hidden', 'true');
293 line.append(number, el('span', 'line-text', lines[i - 1] || ' ')); code.append(line);
294 }
295 body.append(code);
296 expand.textContent = full ? 'Show region context' : 'Show full file';
297 const compared=comparedFiles.get(region.change), pin=side==='before'?comparisonBefore:comparisonAfter;
298 caption.textContent = viewComparison ? `${side==='before'?'Before':'After'} ${pin.view}: ${compared?.[side+'_path'] || region.path}, lines ${start}–${end} of ${lines.length}. State ${pin.state}. ${range.note}.` : viewSnapshot ? `Recorded view ${viewSnapshot.view}: lines ${start}–${end} of ${lines.length}. State ${viewSnapshot.state}. No working-copy bytes or before revision.` : `Recorded ${side}: lines ${start}–${end} of ${lines.length}. ${range.note}. ${snapshot.reviewed_root ? 'Selected source file.' : 'Caller context only, not an additional reviewed root.'}`;
299 }
300 update();
301 return host;
302 }
303
304 function impactEvidence(region) {
305 const host = el('section');

Callers 2

selectionFunction · 0.85
renderCriteriaFunction · 0.85

Calls 4

elFunction · 0.85
buttonFunction · 0.85
updateFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected