MCPcopy Index your code
hub / github.com/midrender/revideo / getSourceCodeFrame

Function getSourceCodeFrame

packages/ui/src/utils/sourceMaps.ts:144–169  ·  view source on GitHub ↗
(entry: StackTraceEntry)

Source from the content-addressed store, hash-verified

142}
143
144export function getSourceCodeFrame(entry: StackTraceEntry): string | null {
145 if (!entry.source || !entry.sourceMap) {
146 return null;
147 }
148 const source = entry.sourceMap.sourceContentFor(entry.source, true);
149 if (!source) {
150 return null;
151 }
152
153 const {line, column} = entry;
154 const lastLine = line + 2;
155 const spacing = lastLine.toString().length;
156 const language = getExtension(entry.source) ?? 'ts';
157
158 const code = highlight
159 .highlight(source, {language})
160 .value.split('\n')
161 .slice(line - 1, lastLine);
162
163 const formatted = code.map(
164 (text, index) =>
165 `${(line + index).toString().padStart(spacing, ' ')} | ${text}`,
166 );
167 formatted.splice(1, 0, `${' '.repeat(spacing)} | ${' '.repeat(column)}^`);
168 return formatted.join('\n');
169}
170
171export async function findAndOpenFirstUserFile(stack: string) {
172 const entry = await resolveStackTrace(stack, true);

Callers 1

SourceCodeFrameFunction · 0.90

Calls 4

getExtensionFunction · 0.85
highlightMethod · 0.65
toStringMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected