Skip to content

Commit 8296196

Browse files
committed
fix JSON formatting
1 parent c563205 commit 8296196

4 files changed

Lines changed: 19 additions & 21 deletions

File tree

src/components/code-block.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const CodeBlock = (props: CodeBlockProps) => {
7676

7777
<pre
7878
className={cn(
79-
"flex-1 overflow-auto rounded-md !bg-background/95 p-3 text-sm leading-normal",
79+
"flex-1 rounded-md !bg-background/95 p-3 text-sm leading-normal",
8080
isWrapped && "whitespace-pre-wrap break-words"
8181
)}
8282
tabIndex={0}

src/components/request-table/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,7 @@ const TableBody_ = (props: TableBodyProps) => {
295295

296296
return (
297297
<div className="flex-1 overflow-hidden">
298-
<CustomScrollbar
299-
className="h-full"
300-
ref={tableRef}
301-
tabIndex={0}
302-
onKeyDown={onKeyDown}
303-
>
298+
<CustomScrollbar className="h-full" ref={tableRef} tabIndex={0} onKeyDown={onKeyDown}>
304299
<div className="min-w-max">
305300
<Table>
306301
<TableBody>

src/components/ui/custom-scrollbar.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export const CustomScrollbar = forwardRef<HTMLDivElement, CustomScrollbarProps>(
5050
scrollState.scrollHeight > 0
5151
? Math.max(
5252
30,
53-
(scrollState.clientHeight / scrollState.scrollHeight) * scrollState.clientHeight
53+
(scrollState.clientHeight / scrollState.scrollHeight) *
54+
scrollState.clientHeight
5455
)
5556
: 0;
5657
const thumbTop =
@@ -101,7 +102,7 @@ export const CustomScrollbar = forwardRef<HTMLDivElement, CustomScrollbarProps>(
101102
return (
102103
<div className={cn("flex h-full", className)}>
103104
<div
104-
className="flex-1 overflow-y-scroll overflow-x-hidden scrollbar-hide"
105+
className="scrollbar-hide flex-1 overflow-x-hidden overflow-y-scroll"
105106
ref={containerRef as React.RefObject<HTMLDivElement>}
106107
tabIndex={tabIndex}
107108
onKeyDown={onKeyDown}
@@ -111,12 +112,12 @@ export const CustomScrollbar = forwardRef<HTMLDivElement, CustomScrollbarProps>(
111112
{/* Custom scrollbar track */}
112113
<div
113114
ref={trackRef}
114-
className="w-3 bg-muted border-l border-border flex-shrink-0 relative cursor-pointer"
115+
className="relative w-3 flex-shrink-0 cursor-pointer border-l border-border bg-muted"
115116
onMouseDown={handleTrackMouseDown}
116117
>
117118
{showScrollbar && (
118119
<div
119-
className="absolute left-0 right-0 bg-foreground/30 hover:bg-foreground/50 rounded-full mx-0.5 cursor-grab active:cursor-grabbing transition-colors"
120+
className="absolute left-0 right-0 mx-0.5 cursor-grab rounded-full bg-foreground/30 transition-colors hover:bg-foreground/50 active:cursor-grabbing"
120121
style={{
121122
height: thumbHeight,
122123
top: thumbTop,

src/lib/code-formatting.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,9 @@ const formatNdjson = async (str: string): Promise<string | null> => {
114114
const prefix = line.trim().slice(0, line.trim().length - jsonPart.length);
115115

116116
try {
117-
JSON.parse(jsonPart);
118-
119-
const formatted = await prettier.format(jsonPart, {
120-
parser: "json",
121-
plugins: [babelPlugin, estreePlugin],
122-
tabWidth: 4,
123-
printWidth: 100,
124-
});
125-
126-
formattedLines.push(prefix + formatted.trim());
117+
const parsed = JSON.parse(jsonPart);
118+
const formatted = JSON.stringify(parsed, null, 4);
119+
formattedLines.push(prefix + formatted);
127120
hasFormattedAny = true;
128121
} catch {
129122
formattedLines.push(line.trim());
@@ -142,6 +135,15 @@ export const formatCode = async (str: string, format: string): Promise<string> =
142135
return str;
143136
}
144137

138+
if (format === "json") {
139+
try {
140+
const parsed = JSON.parse(str);
141+
return JSON.stringify(parsed, null, 4);
142+
} catch {
143+
// If JSON parsing fails, fall through to prettier
144+
}
145+
}
146+
145147
const parserMap: Record<string, string> = {
146148
json: "json",
147149
javascript: "babel",

0 commit comments

Comments
 (0)