(line: string)
| 10 | import { InVirtualListContext } from '../messageActions.js'; |
| 11 | import { useExpandShellOutput } from './ExpandShellOutputContext.js'; |
| 12 | export function tryFormatJson(line: string): string { |
| 13 | try { |
| 14 | const parsed = jsonParse(line); |
| 15 | const stringified = jsonStringify(parsed); |
| 16 | |
| 17 | // Check if precision was lost during JSON round-trip |
| 18 | // This happens when large integers exceed Number.MAX_SAFE_INTEGER |
| 19 | // We normalize both strings by removing whitespace and unnecessary |
| 20 | // escapes (\/ is valid but optional in JSON) for comparison |
| 21 | const normalizedOriginal = line.replace(/\\\//g, '/').replace(/\s+/g, ''); |
| 22 | const normalizedStringified = stringified.replace(/\s+/g, ''); |
| 23 | if (normalizedOriginal !== normalizedStringified) { |
| 24 | // Precision loss detected - return original line unformatted |
| 25 | return line; |
| 26 | } |
| 27 | return jsonStringify(parsed, null, 2); |
| 28 | } catch { |
| 29 | return line; |
| 30 | } |
| 31 | } |
| 32 | const MAX_JSON_FORMAT_LENGTH = 10_000; |
| 33 | export function tryJsonFormatContent(content: string): string { |
| 34 | if (content.length > MAX_JSON_FORMAT_LENGTH) { |
nothing calls this directly
no test coverage detected