Skip to content

Commit 5c86ae3

Browse files
committed
Make source map fetching async and non-blocking for list_console_messages
1 parent 8d765c0 commit 5c86ae3

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/formatters/ConsoleFormatter.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ export class ConsoleFormatter {
314314
}
315315

316316
toJSONDetailed(): object {
317+
const location = this.#getTopFrameLocation();
318+
317319
return {
318320
id: this.#id,
319321
type: this.#type,
@@ -322,6 +324,43 @@ export class ConsoleFormatter {
322324
typeof arg === 'object' ? arg : String(arg),
323325
),
324326
stackTrace: this.#stack,
327+
...(location ? { location } : {}),
325328
};
326329
}
330+
331+
#getTopFrameLocation():
332+
| { url: string; lineNumber: number; columnNumber: number }
333+
| undefined {
334+
335+
if (!this.#stack) {
336+
return undefined;
337+
}
338+
339+
const frame = this.#stack.syncFragment.frames.find(
340+
f => !this.#isIgnored(f),
341+
);
342+
343+
if (!frame) {
344+
return undefined;
345+
}
346+
347+
if (frame.uiSourceCode) {
348+
const location = frame.uiSourceCode.uiLocation(frame.line, frame.column);
349+
return {
350+
url: location.uiSourceCode.url(),
351+
lineNumber: location.lineNumber + 1,
352+
columnNumber: location.columnNumber! + 1,
353+
};
354+
}
355+
356+
if (frame.url) {
357+
return {
358+
url: frame.url,
359+
lineNumber: frame.line,
360+
columnNumber: frame.column,
361+
};
362+
}
363+
364+
return undefined;
365+
}
327366
}

0 commit comments

Comments
 (0)