Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | 31x 31x 31x 31x 25x 21x 25x 25x 31x 21x 21x 31x 30x 2x 28x 13x 13x 13x 31x 28x 13x 13x 13x 31x 31x 25x 21x 21x 5x 31x 25x 21x 5x 31x 31x 31x 31x 1x 21x 25x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 8x 8x 8x 13x 13x 13x 13x 13x 1x 12x 12x 11x 13x 13x 8x 10x 8x 8x 1x 4x | import {
AlertCircle,
AlertTriangle,
Info,
X,
Plus,
Eye,
EyeOff,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import type { ParserMessage, IOPinRecord } from "@shared/schema";
import { clsx } from "clsx";
import { useState } from "react";
import * as React from "react";
interface ParserOutputProps {
messages: ParserMessage[];
ioRegistry?: IOPinRecord[];
onClear: () => void;
onGoToLine?: (line: number) => void;
onInsertSuggestion?: (suggestion: string, line?: number) => void;
hideHeader?: boolean;
defaultTab?: "messages" | "registry";
messagesContainerRef?: React.RefObject<HTMLDivElement>;
}
export function ParserOutput({
messages,
ioRegistry = [],
onClear,
onGoToLine,
onInsertSuggestion,
hideHeader = false,
defaultTab = "messages",
messagesContainerRef,
}: ParserOutputProps) {
const [activeTab, setActiveTab] = useState<"messages" | "registry">(
defaultTab,
);
const [showAllPins, setShowAllPins] = useState(false);
// PWM-capable pins on Arduino UNO
const PWM_PINS = [3, 5, 6, 9, 10, 11];
// Check for I/O registry problems is handled by the I/O Registry tab display
// Do NOT auto-switch tabs - let user control which tab they want to see
// Previously this auto-switched to registry when no messages, but that was confusing
// Group messages by category for better organization
const messagesByCategory = messages.reduce(
(acc, msg) => {
if (!acc[msg.category]) {
acc[msg.category] = [];
}
acc[msg.category].push(msg);
return acc;
},
{} as Record<string, ParserMessage[]>,
);
const getCategoryLabel = (category: string): string => {
const labels: Record<string, string> = {
serial: "Serial Configuration",
structure: "Code Structure",
hardware: "Hardware Compatibility",
pins: "Pin Conflicts",
performance: "Performance Issues",
};
return labels[category] || category;
};
// Filter pins: show only programmed pins by default, all pins if showAllPins is true
const filteredRegistry = React.useMemo(() => {
if (showAllPins) {
return ioRegistry;
}
// Only show pins that have operations or are defined
return ioRegistry.filter((record) => {
const hasOperations = record.usedAt && record.usedAt.length > 0;
const hasPinMode =
record.defined ||
(record.usedAt?.some((u) => u.operation.includes("pinMode")) ?? false);
return hasOperations || hasPinMode;
});
}, [ioRegistry, showAllPins]);
// Count of programmed pins (pins with any operation)
const totalProgrammedPins = React.useMemo(() => {
return ioRegistry.filter((record) => {
const hasOperations = record.usedAt && record.usedAt.length > 0;
const hasPinMode =
record.defined ||
(record.usedAt?.some((u) => u.operation.includes("pinMode")) ?? false);
return hasOperations || hasPinMode;
}).length;
}, [ioRegistry]);
// Inline CSS to hide scrollbars while keeping scrolling functional
const hideScrollbarStyle = `
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; width: 0; height: 0; }
`;
const getSeverityIcon = (severity: 1 | 2 | 3) => {
if (severity === 1) return <Info className="w-4 h-4 text-blue-400" />;
if (severity === 2)
return <AlertTriangle className="w-4 h-4 text-yellow-400" />;
return <AlertCircle className="w-4 h-4 text-red-400" />;
};
const getSeverityLabel = (severity: 1 | 2 | 3): string => {
if (severity === 1) return "Info";
if (severity === 2) return "Warning";
return "Error";
};
const totalErrors = messages.filter((m) => m.severity === 3).length;
const totalWarnings = messages.filter((m) => m.severity === 2).length;
const totalInfos = messages.filter((m) => m.severity === 1).length;
return (
<div className="h-full flex flex-col border-b border-border">
{/* Tabs wrapper for entire component */}
<Tabs
value={activeTab}
onValueChange={(v) => setActiveTab(v as "messages" | "registry")}
className="h-full flex flex-col"
>
{/* Header with integrated tabs */}
{!hideHeader && (
<div className="bg-muted px-4 border-b border-border flex items-center h-[var(--ui-header-height)] overflow-hidden">
<div className="flex items-center space-x-2 flex-shrink-0">
<AlertCircle
className="text-white opacity-95 h-5 w-5"
strokeWidth={1.67}
/>
<span className="text-ui-sm font-medium text-white opacity-95">
Parser Analysis
</span>
</div>
{/* Tabs integrated in header */}
<TabsList className="bg-transparent h-auto ml-4 p-0 gap-1">
<TabsTrigger
value="messages"
className="h-[var(--ui-header-height)] px-2 text-ui-xs data-[state=active]:bg-background/80 data-[state=inactive]:text-muted-foreground rounded"
>
Messages {messages.length > 0 && `(${messages.length})`}
</TabsTrigger>
<TabsTrigger
value="registry"
className="h-[var(--ui-header-height)] px-2 text-ui-xs data-[state=active]:bg-background/80 data-[state=inactive]:text-muted-foreground rounded"
>
I/O Registry{" "}
{(showAllPins ? ioRegistry.length : totalProgrammedPins) >
0 &&
`(${showAllPins ? ioRegistry.length : totalProgrammedPins})`}
</TabsTrigger>
</TabsList>
<div className="flex items-center gap-3 ml-4 text-ui-sm">
{totalErrors > 0 && (
<span className="flex items-center gap-1">
<AlertCircle className="w-3.5 h-3.5 text-red-400" />
<span className="text-red-400">{totalErrors}</span>
</span>
)}
{totalWarnings > 0 && (
<span className="flex items-center gap-1">
<AlertTriangle className="w-3.5 h-3.5 text-yellow-400" />
<span className="text-yellow-400">{totalWarnings}</span>
</span>
)}
{totalInfos > 0 && (
<span className="flex items-center gap-1">
<Info className="w-3.5 h-3.5 text-blue-400" />
<span className="text-blue-400">{totalInfos}</span>
</span>
)}
</div>
<div className="flex-1 min-w-0" />
<Button
variant="outline"
size="sm"
onClick={onClear}
className="h-[var(--ui-button-height)] w-[var(--ui-button-height)] p-0 flex items-center justify-center ml-2 border-2 border-red-500"
title="Close"
>
<X className="h-4 w-4" />
</Button>
</div>
)}
{/* Messages Tab */}
<TabsContent
value="messages"
className="flex-1 flex flex-col overflow-hidden m-0 data-[state=inactive]:hidden"
>
<style>{hideScrollbarStyle}</style>
{messages.length === 0 ? (
<div className="text-muted-foreground p-4 text-center text-ui-xs">
No parser messages
</div>
) : (
<div
className="p-3 text-ui-xs space-y-2 overflow-auto no-scrollbar flex-1"
ref={messagesContainerRef}
data-testid="parser-messages-container"
>
{Object.entries(messagesByCategory).map(
([category, categoryMessages]) => (
<div key={category} className="space-y-1">
{/* Category Header */}
<div className="text-muted-foreground font-semibold uppercase tracking-wide text-ui-xs mb-1.5">
{getCategoryLabel(category)}
</div>
{/* Category Messages */}
{categoryMessages.map((message) => (
<div
key={message.id}
className="p-2 bg-muted/50 rounded border-l-2 cursor-pointer hover:bg-muted/70 transition-colors"
style={{
borderLeftColor:
message.severity === 1
? "rgb(96 165 250)" // blue-400
: message.severity === 2
? "rgb(250 204 21)" // yellow-400
: "rgb(248 113 113)", // red-400
}}
onClick={() =>
message.line !== undefined &&
onGoToLine?.(message.line)
}
>
<div className="flex items-start gap-2">
{getSeverityIcon(message.severity)}
<div className="flex-1 min-w-0">
<div className="text-foreground font-medium mb-1">
{message.message}
</div>
<div className="text-muted-foreground text-ui-xs space-x-2">
{message.line !== undefined && (
<span>Line {message.line}</span>
)}
{message.column !== undefined &&
message.column > 0 && (
<span>• Col {message.column}</span>
)}
<span>
• {getSeverityLabel(message.severity)}
</span>
</div>
{message.suggestion && (
<div className="mt-1.5 p-2 border border-muted-foreground/30 rounded bg-muted/30 flex items-start gap-2">
<div className="flex-1 text-muted-foreground text-ui-xs">
<span className="font-semibold">
Suggestion:
</span>{" "}
{message.suggestion}
</div>
<Button
variant="outline"
size="sm"
onClick={(e) => {
e.stopPropagation();
onInsertSuggestion?.(
message.suggestion!,
message.line,
);
}}
className="h-[var(--ui-button-height)] w-[var(--ui-button-height)] p-0 flex items-center justify-center ml-3"
title="Insert suggestion"
>
<Plus className="h-3.5 w-3.5" />
</Button>
</div>
)}
</div>
</div>
</div>
))}
</div>
),
)}
</div>
)}
</TabsContent>
{/* I/O Registry Tab */}
<TabsContent
value="registry"
className="flex-1 overflow-auto custom-scrollbar m-0 flex flex-col data-[state=inactive]:hidden"
>
{/* Toggle Button for Pin Visibility */}
<div className="sticky top-0 bg-muted/50 border-b border-muted-foreground/30 px-3 h-[var(--ui-button-height)] flex items-center justify-between z-10">
<span className="text-ui-xs text-muted-foreground">
{showAllPins
? `All pins (${ioRegistry.length})`
: `Programmed pins (${totalProgrammedPins})`}
</span>
<Button
variant="outline"
size="sm"
onClick={() => setShowAllPins(!showAllPins)}
className="h-[var(--ui-button-height)] w-[var(--ui-button-height)] p-0 flex items-center justify-center ml-3"
title={showAllPins ? "Hide empty pins" : "Show all pins"}
>
{showAllPins ? (
<Eye className="h-3.5 w-3.5" />
) : (
<EyeOff className="h-3.5 w-3.5" />
)}
</Button>
</div>
<div className="flex-1 overflow-auto no-scrollbar">
<style>{hideScrollbarStyle}</style>
{filteredRegistry.length === 0 ? (
<div className="text-muted-foreground p-4 text-center text-ui-xs">
{showAllPins ? (
"No pins available"
) : (
<div className="space-y-2">
<p>No pins used in current sketch</p>
<Button
variant="link"
size="sm"
onClick={() => setShowAllPins(true)}
className="h-auto p-0 text-ui-xs text-blue-400"
>
Show all pins →
</Button>
</div>
)}
</div>
) : (
<div className="h-full overflow-auto">
<table className="w-full text-ui-xs border-collapse">
<thead>
<tr className="sticky top-0 z-40 border-b border-muted-foreground/30 bg-muted">
<th className="px-2 py-1 text-right font-semibold text-foreground">
Pin
</th>
<th className="px-2 py-1 text-center font-semibold text-foreground">
pinMode
</th>
<th className="px-2 py-1 text-center font-semibold text-foreground">
digitalRead
</th>
<th className="px-2 py-1 text-center font-semibold text-foreground">
digitalWrite
</th>
<th className="px-2 py-1 text-center font-semibold text-foreground">
analogRead
</th>
<th className="px-2 py-1 text-center font-semibold text-foreground">
analogWrite
</th>
</tr>
</thead>
<tbody>
{filteredRegistry.map((record, idx) => {
// Extract operations by type
const ops = record.usedAt || [];
const digitalReads = ops.filter((u) =>
u.operation.includes("digitalRead"),
);
const digitalWrites = ops.filter((u) =>
u.operation.includes("digitalWrite"),
);
const analogReads = ops.filter((u) =>
u.operation.includes("analogRead"),
);
const analogWrites = ops.filter((u) =>
u.operation.includes("analogWrite"),
);
const pinModes = ops
.filter((u) => u.operation.includes("pinMode"))
.map((u) => {
const match = u.operation.match(/pinMode:(\d+)/);
const mode = match ? parseInt(match[1]) : -1;
return mode === 0
? "INPUT"
: mode === 1
? "OUTPUT"
: mode === 2
? "INPUT_PULLUP"
: "UNKNOWN";
});
const uniqueModes = [...new Set(pinModes)];
const hasMultipleModes = uniqueModes.length > 1;
return (
<tr
key={record.pin}
className={`border-b border-muted-foreground/10 h-7 ${idx % 2 === 0 ? "bg-background" : "bg-muted/20"}`}
>
{/* Pin Column */}
<td className="px-2 py-1 text-right font-mono font-semibold text-cyan-400">
<div className="flex items-center justify-end gap-2">
{/* RX/TX prefix for pin 0/1 */}
{(() => {
const pinStr = String(record.pin);
if (pinStr === "0")
return (
<span className="text-blue-400 text-ui-xs font-semibold">
RX
</span>
);
if (pinStr === "1")
return (
<span className="text-red-400 text-ui-xs font-semibold">
TX
</span>
);
return null;
})()}
{/* PWM tilde prefix if numeric pin and PWM-capable */}
{(() => {
const n = parseInt(String(record.pin), 10);
return !Number.isNaN(n) &&
PWM_PINS.includes(n) ? (
<span className="text-yellow-400">~</span>
) : null;
})()}
<span>{record.pin}</span>
</div>
</td>
{/* pinMode Column */}
<td
className={clsx(
"px-2 py-1 text-center",
hasMultipleModes && "border-2 border-red-500",
)}
>
{pinModes.length > 0 ? (
<div className="space-y-0.5 text-center">
{uniqueModes.map((mode, i) => {
const count = pinModes.filter(
(m) => m === mode,
).length;
const modeColor =
mode === "INPUT"
? "text-blue-400"
: mode === "OUTPUT"
? "text-orange-400"
: "text-green-400";
return (
<div
key={i}
className="flex items-center justify-center gap-1"
>
<span className={modeColor}>{mode}</span>
{hasMultipleModes && (
<span className="text-red-400">?</span>
)}
{count > 1 && (
<span className="text-yellow-400 text-ui-xs">
x{count}
</span>
)}
</div>
);
})}
</div>
) : record.defined &&
record.pinMode !== undefined ? (
<div className="text-center">
<span
className={
record.pinMode === 0
? "text-blue-400"
: record.pinMode === 1
? "text-orange-400"
: "text-green-400"
}
>
{record.pinMode === 0
? "INPUT"
: record.pinMode === 1
? "OUTPUT"
: "INPUT_PULLUP"}
</span>
</div>
) : digitalReads.length > 0 ||
digitalWrites.length > 0 ? (
<div
className="flex items-center justify-center"
title="pinMode() missing"
>
<X className="w-4 h-4 text-red-500" />
</div>
) : (
<span className="text-gray-400">—</span>
)}
</td>
{/* digitalRead Column */}
<td className="px-2 py-1 text-center">
{digitalReads.length > 0 ? (
<div className="space-y-0.5 text-center">
{digitalReads.map((usage, i) => (
<div key={i} className="text-ui-xs">
{usage.line > 0 ? (
<span className="text-blue-400">
L{usage.line}
</span>
) : (
<span className="text-green-500 font-bold">
✓
</span>
)}
</div>
))}
</div>
) : (
<span className="text-gray-400">—</span>
)}
</td>
{/* digitalWrite Column */}
<td className="px-2 py-1 text-center">
{digitalWrites.length > 0 ? (
<div className="space-y-0.5 text-center">
{digitalWrites.map((usage, i) => (
<div key={i} className="text-ui-xs">
{usage.line > 0 ? (
<span className="text-blue-400">
L{usage.line}
</span>
) : (
<span className="text-green-500 font-bold">
✓
</span>
)}
</div>
))}
</div>
) : (
<span className="text-gray-400">—</span>
)}
</td>
{/* analogRead Column */}
<td className="px-2 py-1 text-center">
{analogReads.length > 0 ? (
<div className="space-y-0.5 text-center">
{analogReads.map((usage, i) => (
<div key={i} className="text-ui-xs">
{usage.line > 0 ? (
<span className="text-blue-400">
L{usage.line}
</span>
) : (
<span className="text-green-500 font-bold">
✓
</span>
)}
</div>
))}
</div>
) : (
<span className="text-gray-400">—</span>
)}
</td>
{/* analogWrite Column */}
<td className="px-2 py-1 text-center">
{analogWrites.length > 0 ? (
<div className="space-y-0.5 text-center">
{analogWrites.map((usage, i) => (
<div key={i} className="text-ui-xs">
{usage.line > 0 ? (
<span className="text-blue-400">
L{usage.line}
</span>
) : (
<span className="text-green-500 font-bold">
✓
</span>
)}
</div>
))}
</div>
) : (
<span className="text-gray-400">—</span>
)}
</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
</div>
</TabsContent>
</Tabs>
</div>
);
}
|