Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions webview/src/components/MetaschemaChain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { useEffect, useRef, useState } from 'react';
import type { MetaschemaError, Position } from '../../../protocol/types';
import { goToPosition } from '../message';

const BOX_WIDTH = 260;
const GAP = 12;

interface Props {
errors: MetaschemaError[];
}

export function MetaschemaChain({ errors }: Props) {
const containerRef = useRef<HTMLDivElement>(null);
const [rows, setRows] = useState<MetaschemaError[][]>([]);
const [rowWidth, setRowWidth] = useState<number>(0);

useEffect(() => {
if (!containerRef.current) return;

const compute = () => {
const width = containerRef.current!.clientWidth;
if (width < BOX_WIDTH) {
setRows(errors.map(e => [e]));
setRowWidth(BOX_WIDTH);
return;
}

const perRow = Math.max(
1,
Math.floor((width + GAP) / (BOX_WIDTH + GAP))
);

const computedRowWidth = perRow * (BOX_WIDTH + GAP) - GAP;

const newRows: MetaschemaError[][] = [];
for (let i = 0; i < errors.length; i += perRow) {
newRows.push(errors.slice(i, i + perRow));
}

setRows(newRows);
setRowWidth(computedRowWidth);
};
compute();

const observer = new ResizeObserver(compute);
observer.observe(containerRef.current);

return () => observer.disconnect();
}, [errors]);

return (
<div ref={containerRef} className="flex justify-center overflow-x-auto">
<div className="flex flex-col gap-4">
{rows.map((row, rowIndex) => {
const isLTR = rowIndex % 2 === 0;
const items = isLTR ? row : [...row].reverse();

return (
<div key={rowIndex}>
{/* ROW */}
<div
className="flex items-center gap-3"
style={{
width: rowWidth,
justifyContent: isLTR ? 'flex-start' : 'flex-end'
}}
>
{items.map((error, index) => (
<div key={index} className="flex items-center gap-3">
<ErrorBox error={error} />

{/* Horizontal arrows */}
{index < items.length - 1 &&
(isLTR ? <ArrowRight /> : <ArrowLeft />)}
</div>
))}
</div>

{/* TURN ARROW */}
{rowIndex < rows.length - 1 && (
<div className="relative" style={{ width: rowWidth }}>
<div
className="absolute"
style={{
right: isLTR ? 0 :"auto",
left: isLTR ? "auto" : 0,
top: 0
}}
>
<ArrowDown />
</div>
</div>
)}
</div>
);
})}
</div>
</div>
);
}

function ErrorBox({ error }: { error: MetaschemaError }) {
return (
<div
className="bg-(--vscode-selection) border-l-[3px] rounded p-3 cursor-pointer transition-colors hover:bg-(--vscode-hover)"
style={{
width: BOX_WIDTH,
borderLeftColor: "var(--error)",
boxShadow: "0 0 0 1px rgba(255, 0, 0, 0.15)"
}}
onClick={() =>
error.instancePosition &&
goToPosition(error.instancePosition as Position)
}
>
<div className="text-[12px] font-semibold mb-1 text-(--vscode-fg)">
{error.error}
</div>

{error.instanceLocation && (
<div className="text-[11px] text-(--vscode-muted) break-all">
{error.instanceLocation || '(root)'}
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Redundant fallback - '(root)' will never be displayed. The outer condition error.instanceLocation && ensures the value is truthy, so the || '(root)' fallback inside is dead code. If you want to show '(root)' when instanceLocation is empty, remove the outer condition. Otherwise, remove the unused fallback.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At webview/src/components/MetaschemaChain.tsx, line 122:

<comment>Redundant fallback - `'(root)'` will never be displayed. The outer condition `error.instanceLocation &&` ensures the value is truthy, so the `|| '(root)'` fallback inside is dead code. If you want to show '(root)' when `instanceLocation` is empty, remove the outer condition. Otherwise, remove the unused fallback.</comment>

<file context>
@@ -0,0 +1,143 @@
+
+      {error.instanceLocation && (
+        <div className="text-[11px] text-(--vscode-muted) break-all">
+          {error.instanceLocation || '(root)'}
+        </div>
+      )}
</file context>
Fix with Cubic

</div>
)}
</div>
);
}

function ArrowRight() {
return <span className="text-(--vscode-muted)">→</span>;
}

function ArrowLeft() {
return <span className="text-(--vscode-muted)">←</span>;
}

function ArrowDown() {
return (
<div className="text-(--vscode-muted) text-lg leading-none">
</div>
);
}
57 changes: 5 additions & 52 deletions webview/src/components/MetaschemaTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { MetaschemaResult, MetaschemaError, Position } from '../../../proto
import { goToPosition } from '../message';
import { RawOutput } from './RawOutput';
import { CheckCircle, AlertTriangle, FileQuestion } from 'lucide-react';
import { MetaschemaChain } from './MetaschemaChain';

export interface MetaschemaTabProps {
metaschemaResult: MetaschemaResult;
Expand Down Expand Up @@ -55,55 +56,7 @@ export function MetaschemaTab({ metaschemaResult, noFileSelected }: MetaschemaTa
return (
<div>
<div className="flex flex-col gap-3 mb-5">
{metaschemaErrors.map((error, index) => (
<div
key={index}
className="bg-(--vscode-selection) border-l-[3px] rounded p-3 cursor-pointer transition-colors hover:bg-(--vscode-hover)"
style={{
cursor: error.instancePosition ? 'pointer' : 'default',
borderLeftColor: 'var(--error)'
}}
onClick={() => error.instancePosition && handleGoToPosition(error.instancePosition)}
>
<div className="mb-2">
<div className="text-(--vscode-fg) text-[13px] font-semibold">
{error.error}
</div>
</div>
<div className="flex flex-col gap-1 text-[11px]">
{error.instancePosition && (
<div className="flex gap-1.5">
<span className="text-(--vscode-muted) font-semibold min-w-20">
Location:
</span>
<span className="text-(--vscode-fg) font-(--vscode-editor-font)">
Line {error.instancePosition[0]}, Col {error.instancePosition[1]}
</span>
</div>
)}
{error.instanceLocation && (
<div className="flex gap-1.5">
<span className="text-(--vscode-muted) font-semibold min-w-20">
Path:
</span>
<span className="text-(--vscode-fg) font-(--vscode-editor-font) break-all">
{error.instanceLocation || '(root)'}
</span>
</div>
)}
{error.keywordLocation && (
<div className="flex gap-1.5">
<span className="text-(--vscode-muted) font-semibold min-w-20">
Schema:
</span>
<span className="text-(--vscode-fg) font-(--vscode-editor-font) break-all">
{error.keywordLocation}
</span>
</div>
)}
</div>
</div>
))}
<MetaschemaChain errors={metaschemaErrors}/>
</div>
<RawOutput output={metaschemaResult.output} />
</div>
Expand All @@ -128,12 +81,12 @@ export function MetaschemaTab({ metaschemaResult, noFileSelected }: MetaschemaTa
error && 'instancePosition' in error && error.instancePosition
? error.instancePosition
: null;

return (
<>
<div
<div
className="bg-(--vscode-selection) border-l-[3px] rounded p-4 mb-5 transition-colors"
style={{
style={{
borderLeftColor: 'var(--fatal)',
cursor: errorPosition ? 'pointer' : 'default'
}}
Expand Down
18 changes: 18 additions & 0 deletions webview/src/utils/splitIntoRows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function splitIntoRows<T>(
items: T[],
containerWidth: number,
itemWidth: number,
gap: number
): T[][] {
const itemsPerRow = Math.max(
1,
Math.floor((containerWidth + gap) / (itemWidth + gap))
);

const rows: T[][] = [];
for (let i = 0; i < items.length; i += itemsPerRow) {
rows.push(items.slice(i, i + itemsPerRow));
}
return rows;
}