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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import * as vscode from 'vscode';
import { MergedReport } from '../merger/merger';
import { t, onLanguageChange, getLanguage } from '../i18n/messages';
import type { FixSessionManager } from '../fix/fixSession';
import { computeLineDiff } from '../utils/diff';
interface PanelMessage {
type: 'navigate' | 'rerun' | 'export' | 'fix' | 'fixAll' | 'undo' | 'applyFix' | 'cancelFix' | 'applyAll' | 'cancelAll';
line?: number;
ruleId?: string;
source?: 'linter' | 'custom' | 'ai';
origin?: 'hover' | 'panel';
}
function esc(str: string): string {
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '"').replace(/"/g, '"');
}
function svgIcon(): string {
return `<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="#61AFEF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"/><rect x="9" y="3" width="6" height="4" rx="1"/><path d="M9 14l2 2 4-4"/></svg>`;
}
const SVG_HEADER_ICON = svgIcon();
const BADGE_CLASS: Record<string, string> = { linter: 'badge-linter', custom: 'badge-custom', ai: 'badge-ai' };
interface FixedEntryView {
ruleId: string;
line: number;
key: string;
source: 'linter' | 'custom' | 'ai';
}
function badgeHtml(source: string): string {
let label: string;
switch (source) {
case 'linter': label = t('report.sourceLinter'); break;
case 'custom': label = t('report.sourceCustom'); break;
case 'ai': label = t('report.sourceAI'); break;
default: label = source;
}
return `<span class="item-badge ${BADGE_CLASS[source] || 'badge-linter'}">${label}</span>`;
}
function severityClass(severity: string): string {
switch (severity) {
case 'error': return 'severity-error';
case 'warning': return 'severity-warning';
case 'info': return 'severity-info';
default: return 'severity-info';
}
}
export class ReviewPanel {
public static currentPanel: ReviewPanel | undefined;
private readonly panel: vscode.WebviewPanel;
private disposables: vscode.Disposable[] = [];
private currentReport: MergedReport | null = null;
private fixSession: FixSessionManager | null = null;
private readonly scriptUri: vscode.Uri;
private constructor(
private readonly extensionUri: vscode.Uri,
column: vscode.ViewColumn
) {
this.panel = vscode.window.createWebviewPanel(
'codeReviewer.reviewPanel',
t('report.panelTitle'),
column,
{
enableScripts: true,
retainContextWhenHidden: true,
localResourceRoots: [this.extensionUri],
}
);
this.scriptUri = this.panel.webview.asWebviewUri(
vscode.Uri.joinPath(this.extensionUri, 'out', 'webview', 'reviewPanel.js')
);
this.panel.onDidDispose(() => this.dispose(), null, this.disposables);
this.panel.webview.onDidReceiveMessage(
(message: PanelMessage) => this.handleMessage(message),
null,
this.disposables
);
this.disposables.push(
onLanguageChange(() => {
this.panel.title = t('report.panelTitle');
if (this.currentReport) {
this.panel.webview.html = this.buildHtml(this.currentReport);
}
})
);
}
static createOrShow(extensionUri: vscode.Uri, column?: vscode.ViewColumn): ReviewPanel {
if (ReviewPanel.currentPanel) {
ReviewPanel.currentPanel.panel.reveal(column);
return ReviewPanel.currentPanel;
}
ReviewPanel.currentPanel = new ReviewPanel(extensionUri, column ?? vscode.ViewColumn.Two);
return ReviewPanel.currentPanel;
}
update(report: MergedReport): void {
this.currentReport = report;
this.panel.webview.html = this.buildHtml(report);
}
setFixSession(session: FixSessionManager): void {
this.fixSession = session;
if (this.currentReport) {
this.panel.webview.html = this.buildHtml(this.currentReport);
}
}
postMessage(message: unknown): void {
this.panel.webview.postMessage(message);
}
private buildHtml(report: MergedReport): string {
const fileName = report.filePath.split(/[/\\]/).pop() ?? '';
const linterErrors = report.linterDiagnostics.filter(d => d.severity === 'error').length;
const linterWarnings = report.linterDiagnostics.filter(d => d.severity === 'warning').length;
const linterInfos = report.linterDiagnostics.filter(d => d.severity === 'info').length;
const customErrors = report.customRuleDiagnostics.filter(d => d.severity === 'error').length;
const customWarnings = report.customRuleDiagnostics.filter(d => d.severity === 'warning').length;
const customInfos = report.customRuleDiagnostics.filter(d => d.severity === 'info').length;
const aiErrors = report.aiFindings.filter(f => f.severity === 'error').length;
const aiWarnings = report.aiFindings.filter(f => f.severity === 'warning').length;
const aiInfos = report.aiFindings.filter(f => f.severity === 'info').length;
const total = report.linterCount + report.customRuleCount + report.aiCount;
const totalErrors = linterErrors + customErrors + aiErrors;
const totalWarnings = linterWarnings + customWarnings + aiWarnings;
const totalInfos = linterInfos + customInfos + aiInfos;
const errorBox = report.errors.length > 0
? `<div class="errors-box"><div class="errors-box-title">✖ ${t('report.executionErrors')}</div>${report.errors.map(e => `<div class="errors-box-item">${esc(e)}</div>`).join('')}</div>`
: '';
const banner = report.errors.length > 0
? `<div class="banner banner-error">⚠ ${t('report.degradedBanner')}</div>`
: report.degraded
? `<div class="banner banner-warning">⚠ ${t('report.degradedBanner')}</div>`
: '';
const fixableLinterSet = new Set(report.fixableLinterIndices);
const aiFixableLinterSet = new Set(report.aiFixableLinterIndices);
const fixableCustomSet = new Set(report.fixableCustomIndices);
const fixedEntries = this.fixSession?.getEntries(vscode.Uri.file(report.filePath)) ?? [];
const tabCount = (e: number, w: number, i: number) => {
const pts: string[] = [];
if (e > 0) { pts.push(`<span class="tab-count tab-count-error">${e}</span>`); }
if (w > 0) { pts.push(`<span class="tab-count tab-count-warning">${w}</span>`); }
if (i > 0) { pts.push(`<span class="tab-count tab-count-info">${i}</span>`); }
return pts.join(' ');
};
const linterToolName = report.adapterNames.length > 0 ? report.adapterNames.join(' + ') : t('report.sourceLinter');
const customFilterInfo = report.customRuleFilterInfo;
const customFilterLabel = customFilterInfo
? t('report.injectedCount', { 0: customFilterInfo.injected, 1: customFilterInfo.totalActive })
: '';
return `<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${t('report.title')}</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--vscode-font-family); font-size: var(--vscode-font-size); color: var(--vscode-foreground); background: var(--vscode-editor-background); }
.header { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px; border-bottom: 1px solid var(--vscode-panel-border); }
.header h2 { font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 8px; color: var(--vscode-foreground); }
.header .meta { color: var(--vscode-descriptionForeground); font-size: 12px; margin-top: 2px; }
.banner { margin: 12px 16px 0; padding: 8px 12px; border-radius: 6px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.banner-warning { background: rgba(200,160,0,0.15); border: 1px solid rgba(200,160,0,0.35); color: #cca700; }
.banner-error { background: rgba(248,81,73,0.15); border: 1px solid rgba(248,81,73,0.35); color: #f48771; }
.errors-box { margin: 12px 16px 0; padding: 10px 12px; background: rgba(248,81,73,0.1); border: 1px solid rgba(248,81,73,0.3); border-radius: 6px; }
.errors-box-title { font-weight: 600; color: #f48771; font-size: 12px; margin-bottom: 4px; }
.errors-box-item { font-size: 12px; color: #f48771; padding: 2px 0; }
.summary { display: flex; gap: 8px; padding: 12px 16px 0; flex-wrap: wrap; }
.stat-card { flex: 1; min-width: 100px; padding: 10px 12px; border: 1px solid var(--vscode-panel-border); border-radius: 8px; background: var(--vscode-sideBar-background); text-align: center; }
.stat-card .num { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-card .label { font-size: 11px; color: var(--vscode-descriptionForeground); margin-top: 1px; }
.stat-error .num { color: #E06C75; }
.stat-warning .num { color: #D19A66; }
.stat-info .num { color: #61AFEF; }
.stat-total .num { color: var(--vscode-foreground); }
.tab-bar { display: flex; align-items: stretch; margin: 16px 16px 0; border-bottom: 1px solid var(--vscode-panel-border); }
.tab { position: relative; display: flex; align-items: center; gap: 6px; padding: 8px 16px; font-size: 13px; font-weight: 500; color: var(--vscode-descriptionForeground); cursor: pointer; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s; user-select: none; white-space: nowrap; background: none; border-top: none; border-left: none; border-right: none; font-family: var(--vscode-font-family); }
.tab:hover { color: var(--vscode-foreground); }
.tab.active { color: var(--vscode-foreground); border-bottom-color: #7C3AED; }
.tab-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; font-weight: 500; line-height: 1; }
.tab-count-error { background: rgba(224,108,117,0.2); color: #E06C75; }
.tab-count-warning { background: rgba(209,154,102,0.2); color: #D19A66; }
.tab-count-info { background: rgba(97,175,239,0.2); color: #61AFEF; }
.tab-content { display: none; padding: 8px 16px 20px; }
.tab-content.active { display: block; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; padding-top: 12px; }
.section-header:first-child { padding-top: 0; }
.section-header-title { font-size: 12px; font-weight: 600; color: var(--vscode-descriptionForeground); text-transform: uppercase; letter-spacing: .03em; }
.item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; margin-top: 6px; border: 1px solid var(--vscode-panel-border); border-radius: 8px; background: var(--vscode-sideBar-background); cursor: pointer; transition: border-color .15s, background .15s; }
.item:first-child { margin-top: 0; }
.item:hover { border-color: var(--vscode-focusBorder); background: var(--vscode-list-hoverBackground); }
.item.expanded { border-color: var(--vscode-focusBorder); }
.item-severity { flex-shrink: 0; width: 5px; align-self: stretch; border-radius: 3px; margin: -10px 0 -10px -12px; border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
.item-severity-error { background: #E06C75; }
.item-severity-warning { background: #D19A66; }
.item-severity-info { background: #61AFEF; }
.item-body { flex: 1; min-width: 0; }
.item-row1 { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.item-icon { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.icon-error { background: #E06C75; }
.icon-warning { background: #D19A66; }
.icon-info { background: #61AFEF; }
.item-badge { display: inline-flex; align-items: center; padding: 0 7px; height: 20px; border-radius: 5px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; flex-shrink: 0; line-height: 1; }
.badge-linter { background: rgba(139,148,158,0.15); color: var(--vscode-descriptionForeground); }
.badge-custom { background: rgba(191,133,255,0.15); color: #ce93d8; }
.badge-ai { background: rgba(79,195,247,0.15); color: #4dd0e1; }
.item-message { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--vscode-foreground); font-size: 14px; }
.item-line { flex-shrink: 0; font-size: 11px; font-weight: 600; color: var(--vscode-descriptionForeground); font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace; background: rgba(139,148,158,0.08); padding: 1px 6px; border-radius: 4px; line-height: 20px; cursor: pointer; }
.item-line:hover { background: rgba(139,148,158,0.2); }
.item-rule { flex-shrink: 0; font-size: 12px; color: var(--vscode-descriptionForeground); font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-fix { flex-shrink: 0; padding: 2px 8px; border: 1px solid var(--vscode-panel-border); background: var(--vscode-button-secondaryBackground); color: var(--vscode-button-secondaryForeground); border-radius: 4px; cursor: pointer; font-size: 11px; transition: background .15s; line-height: 18px; }
.item-fix:hover { background: var(--vscode-button-secondaryHoverBackground); }
.item-fix:disabled { opacity: .4; cursor: not-allowed; }
.item-fixed { border-color: rgba(87,171,90,0.4); background: rgba(87,171,90,0.08); }
.item-fixed:hover { border-color: rgba(87,171,90,0.6); }
.item-severity-fixed { background: #57ab5a; }
.icon-fixed { background: #57ab5a; }
.item-undo { flex-shrink: 0; padding: 2px 8px; border: 1px solid rgba(87,171,90,0.5); background: rgba(87,171,90,0.15); color: #57ab5a; border-radius: 4px; cursor: pointer; font-size: 11px; line-height: 18px; }
.item-undo:hover { background: rgba(87,171,90,0.25); }
.item-detail { display: none; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--vscode-panel-border); }
.item.expanded .item-detail { display: block; animation: fadeSlideIn .2s ease; }
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.detail-text { color: var(--vscode-descriptionForeground); font-size: 13px; line-height: 1.7; }
.detail-text code { font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 13px; }
.detail-suggestion { margin-top: 8px; padding: 8px 12px; background: rgba(97,175,239,0.08); border: 1px solid rgba(97,175,239,0.2); border-radius: 6px; font-size: 13px; color: #79c0ff; }
.detail-no-fix { margin-top: 4px; padding: 8px 12px; background: rgba(139,148,158,0.08); border: 1px dashed var(--vscode-panel-border); border-radius: 6px; font-size: 12px; color: var(--vscode-descriptionForeground); }
.detail-original { margin-top: 6px; font-size: 12px; color: var(--vscode-descriptionForeground); font-style: italic; }
.detail-category { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; background: rgba(139,148,158,0.1); color: var(--vscode-descriptionForeground); margin-top: 6px; }
.detail-fix-title { margin: 8px 0 4px; font-size: 11px; font-weight: 600; color: var(--vscode-descriptionForeground); text-transform: uppercase; letter-spacing: .03em; }
.fix-diff { margin-top: 4px; border: 1px solid var(--vscode-panel-border); border-radius: 6px; overflow: hidden; }
.diff-line { display: flex; align-items: flex-start; font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 12px; line-height: 1.6; padding: 1px 8px; white-space: pre-wrap; word-break: break-all; }
.diff-marker { flex-shrink: 0; width: 16px; color: var(--vscode-descriptionForeground); user-select: none; }
.diff-text { flex: 1; min-width: 0; }
.diff-same { color: var(--vscode-foreground); }
.diff-del { background: rgba(224,108,117,0.15); color: #E06C75; }
.diff-add { background: rgba(87,171,90,0.15); color: #57ab5a; }
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 20px; color: var(--vscode-descriptionForeground); text-align: center; font-style: italic; font-size: 13px; }
.actions { display: flex; gap: 8px; padding: 16px 16px 20px; border-top: 1px solid var(--vscode-panel-border); }
.btn { display: inline-flex; align-items: center; gap: 4px; padding: 5px 12px; border: 1px solid var(--vscode-panel-border); background: var(--vscode-button-secondaryBackground); color: var(--vscode-button-secondaryForeground); border-radius: 6px; cursor: pointer; font-size: 12px; transition: background .15s, border-color .15s; font-family: var(--vscode-font-family); }
.btn:hover { background: var(--vscode-button-secondaryHoverBackground); }
.btn-primary { background: #7C3AED; color: #fff; border-color: #7C3AED; }
.btn-primary:hover { background: #6D28D9; }
</style>
</head>
<body>
<div class="header">
<div>
<h2>${SVG_HEADER_ICON} ${t('report.panelTitle')}</h2>
<div class="meta">${esc(fileName)} · ${esc(report.language)} · ${(report.duration / 1000).toFixed(1)}s</div>
</div>
</div>
${banner}
${errorBox}
<div class="summary">
<div class="stat-card stat-total"><div class="num">${total}</div><div class="label">${t('report.totalIssues')}</div></div>
<div class="stat-card stat-error"><div class="num">${totalErrors}</div><div class="label">${t('report.errors')}</div></div>
<div class="stat-card stat-warning"><div class="num">${totalWarnings}</div><div class="label">${t('report.warnings')}</div></div>
<div class="stat-card stat-info"><div class="num">${totalInfos}</div><div class="label">${t('report.info')}</div></div>
</div>
<div class="tab-bar">
<button class="tab active" data-tab="linter" onclick="switchTab('linter')">🔧 ${report.adapterNames.length > 0 ? report.adapterNames.join(' + ') : t('report.sourceLinter')} ${tabCount(linterErrors, linterWarnings, linterInfos)}</button>
<button class="tab" data-tab="custom" onclick="switchTab('custom')">📋 ${t('report.sourceCustom')} ${tabCount(customErrors, customWarnings, customInfos)} <span style="font-size:11px;color:var(--vscode-descriptionForeground);">${customFilterLabel}</span></button>
<button class="tab" data-tab="ai" onclick="switchTab('ai')">🤖 ${t('report.sourceAI')} ${tabCount(aiErrors, aiWarnings, aiInfos)}</button>
</div>
<div class="tab-content active" id="tab-linter">
${this.buildLinterList(report, fixableLinterSet, aiFixableLinterSet, fixedEntries)}
</div>
<div class="tab-content" id="tab-custom">
${this.buildCustomList(report, fixedEntries)}
</div>
<div class="tab-content" id="tab-ai">
${this.buildAIList(report, fixedEntries)}
</div>
<div class="actions">
<button class="btn btn-primary" onclick="send('rerun')">🔄 ${t('report.rerun')}</button>
<button class="btn" onclick="send('export')">📄 ${t('report.export')}</button>
</div>
</div>
<script src="${this.scriptUri}"></script>
</body>
</html>`;
}
private buildLinterList(report: MergedReport, fixableSet: Set<number>, aiFixableSet: Set<number>, fixedEntries: FixedEntryView[]): string {
if (report.linterDiagnostics.length === 0 && fixedEntries.length === 0) {
return `<div class="empty">${t('report.noIssues')}</div>`;
}
const toolName = report.adapterNames.length > 0 ? report.adapterNames.join(' + ') : t('report.sourceLinter');
const hasFixable = fixableSet.size > 0 || aiFixableSet.size > 0;
const fixAllBtn = hasFixable
? `<button class="btn" data-fix-all-btn onclick="send('fixAll')">${t('report.fixAll')}</button>`
+ `<button class="btn btn-apply-all" data-fix-all-btn style="display:none" onclick="send('applyAll')">✅ ${t('report.fixAllApply')}</button>`
+ `<button class="btn btn-cancel-all" data-fix-all-btn style="display:none" onclick="send('cancelAll')">✖ ${t('fix.cancel')}</button>`
: '';
let html = `<div class="section-header"><span class="section-header-title">${esc(toolName)} · ${t('report.issuesCount', { 0: report.linterCount })}</span>${fixAllBtn}</div>`;
if (report.linterDiagnostics.length === 0) {
html += `<div class="empty">${t('report.noIssues')}</div>`;
} else {
html += report.linterDiagnostics.map((d, i) => this.buildIssueItem(d.severity, d.ruleId, d.message, d.range.start.line, 'linter', d.suggestion, fixableSet.has(i), aiFixableSet.has(i), undefined, true, this.buildFixDiffHtml(d.aiFix?.originalText ?? d.fix?.originalText, d.aiFix?.newText ?? d.fix?.text))).join('');
}
const linterFixed = fixedEntries.filter(f => f.source === 'linter');
if (linterFixed.length > 0) {
html += `<div class="section-header" style="padding-top:16px"><span class="section-header-title">✅ ${t('report.fixedIssues')} · ${t('report.issuesCount', { 0: linterFixed.length })}</span></div>`;
html += linterFixed.map(f => this.buildFixedItem(f.ruleId, f.line, f.key, 'linter')).join('');
}
return html;
}
private buildFixedItem(ruleId: string, line: number, key: string, source: 'linter' | 'custom' | 'ai'): string {
return `<div class="item item-fixed">
<div class="item-severity item-severity-fixed"></div>
<div class="item-body">
<div class="item-row1">
<span class="item-icon icon-fixed"></span>
${badgeHtml(source)}
<span class="item-rule">${esc(ruleId)}</span>
<span class="item-message">${t('report.fixedLabel')}</span>
<button class="item-undo" onclick="event.stopPropagation();send('undo', ${line}, '${esc(ruleId)}', '${source}')">↩ ${t('report.undoFix')}</button>
</div>
</div>
</div>`;
}
private buildCustomList(report: MergedReport, fixedEntries: FixedEntryView[]): string {
const filterInfo = report.customRuleFilterInfo;
if (filterInfo?.skippedRequestA) {
return `<div class="empty">${t('report.skipCustomRules')}</div>`;
}
const customFixed = fixedEntries.filter(f => f.source === 'custom');
const fixedKeys = new Set(customFixed.map(f => `${f.ruleId}@${f.line}`));
const remaining = report.customRuleDiagnostics.filter(d => !fixedKeys.has(`${d.ruleId}@${d.range.start.line}`));
if (remaining.length === 0 && customFixed.length === 0) {
return `<div class="empty">${t('report.noRuleViolations')}</div>`;
}
const filterLabel = filterInfo
? t('report.injectedRules', { 0: filterInfo.injected, 1: filterInfo.totalActive })
: '';
const hasFixable = remaining.length > 0;
const fixAllBtn = hasFixable
? `<button class="btn" data-fix-all-btn onclick="send('fixAll', undefined, undefined, 'custom')">${t('report.fixAll')}</button>`
+ `<button class="btn btn-apply-all" data-fix-all-btn style="display:none" onclick="send('applyAll')">✅ ${t('report.fixAllApply')}</button>`
+ `<button class="btn btn-cancel-all" data-fix-all-btn style="display:none" onclick="send('cancelAll')">✖ ${t('fix.cancel')}</button>`
: '';
let html = `<div class="section-header"><span class="section-header-title">${t('report.sourceCustom')} · ${t('report.issuesCount', { 0: remaining.length })}${filterLabel}</span>${fixAllBtn}</div>`;
if (remaining.length === 0) {
html += `<div class="empty">${t('report.noRuleViolations')}</div>`;
} else {
html += remaining.map((d, i) => this.buildIssueItem(d.severity, d.ruleId, d.message, d.range.start.line, 'custom', d.suggestion, false, true, undefined, true, this.buildFixDiffHtml(d.aiFix?.originalText, d.aiFix?.newText))).join('');
}
if (customFixed.length > 0) {
html += `<div class="section-header" style="padding-top:16px"><span class="section-header-title">✅ ${t('report.fixedIssues')} · ${t('report.issuesCount', { 0: customFixed.length })}</span></div>`;
html += customFixed.map(f => this.buildFixedItem(f.ruleId, f.line, f.key, 'custom')).join('');
}
return html;
}
private buildAIList(report: MergedReport, fixedEntries: FixedEntryView[]): string {
const aiFixed = fixedEntries.filter(f => f.source === 'ai');
const fixedKeys = new Set(aiFixed.map(f => `${f.ruleId}@${f.line}`));
const remaining = report.aiFindings.filter(f => !fixedKeys.has(`${f.ruleId}@${f.line}`));
if (remaining.length === 0 && aiFixed.length === 0) {
return `<div class="empty">${t('report.noAIFindings')}</div>`;
}
const hasFixable = remaining.length > 0;
const fixAllBtn = hasFixable
? `<button class="btn" data-fix-all-btn onclick="send('fixAll', undefined, undefined, 'ai')">${t('report.fixAll')}</button>`
+ `<button class="btn btn-apply-all" data-fix-all-btn style="display:none" onclick="send('applyAll')">✅ ${t('report.fixAllApply')}</button>`
+ `<button class="btn btn-cancel-all" data-fix-all-btn style="display:none" onclick="send('cancelAll')">✖ ${t('fix.cancel')}</button>`
: '';
const parts: string[] = [`<div class="section-header"><span class="section-header-title">${t('report.sourceAI')} · ${t('report.itemsCount', { 0: remaining.length })}</span>${fixAllBtn}</div>`];
if (remaining.length === 0) {
parts.push(`<div class="empty">${t('report.noAIFindings')}</div>`);
} else {
for (const f of remaining) {
const details: string[] = [];
const path = (f as { path?: string }).path;
if (path) {
details.push(`<div class="detail-text">🔗 ${esc(path)}</div>`);
}
details.push(`<div class="detail-text">${esc(f.description)}</div>`);
if (f.category) {
details.push(`<span class="detail-category">🎯 ${esc(f.category)}</span>`);
}
if (f.suggestion) {
details.push(`<div class="detail-suggestion">💡 ${esc(f.suggestion)}</div>`);
}
parts.push(this.buildIssueItem(f.severity, f.ruleId, f.title, f.line, 'ai', f.suggestion, false, true, details.join(''), true, this.buildFixDiffHtml(f.fix?.originalText, f.fix?.newText)));
}
}
if (aiFixed.length > 0) {
parts.push(`<div class="section-header" style="padding-top:16px"><span class="section-header-title">✅ ${t('report.fixedIssues')} · ${t('report.issuesCount', { 0: aiFixed.length })}</span></div>`);
parts.push(aiFixed.map(f => this.buildFixedItem(f.ruleId, f.line, f.key, 'ai')).join(''));
}
return parts.join('');
}
private buildIssueItem(
severity: string,
ruleId: string,
message: string,
line: number,
source: string,
suggestion?: string,
fixable?: boolean,
aiFixable?: boolean,
detailHtml?: string,
expandable: boolean = true,
fixDiffHtml: string = ''
): string {
const sevCls = severityClass(severity);
const lineNum = Number.isFinite(line) ? line + 1 : '?';
const parts: string[] = [];
parts.push(`<div class="item"${expandable ? ' onclick="toggleItem(this)"' : ''}>`);
parts.push(`<div class="item-severity item-severity-${sevCls.replace('severity-', '')}"></div>`);
parts.push('<div class="item-body">');
parts.push('<div class="item-row1">');
parts.push(`<span class="item-icon icon-${sevCls.replace('severity-', '')}"></span>`);
parts.push(badgeHtml(source));
parts.push(`<span class="item-rule">${esc(ruleId)}</span>`);
parts.push(`<span class="item-message">${esc(message)}</span>`);
parts.push(`<span class="item-line" onclick="event.stopPropagation();send('navigate', ${line}, '${esc(ruleId)}', '${source}')">L${lineNum}</span>`);
if (fixable) {
parts.push(`<button class="item-fix" data-fix-key="${esc(ruleId)}@${line}" data-label="🔧 ${esc(t('report.fixLabel'))}" onclick="event.stopPropagation(); this.disabled=true; this.textContent='⏳...';send('fix', ${line}, '${esc(ruleId)}', '${source}')">🔧 ${t('report.fixLabel')}</button>`);
parts.push(`<button class="item-fix btn-apply" data-fix-key="${esc(ruleId)}@${line}" style="display:none" onclick="event.stopPropagation();send('applyFix', ${line}, '${esc(ruleId)}', '${source}')">✅ ${t('fix.apply')}</button>`);
parts.push(`<button class="item-fix btn-cancel" data-fix-key="${esc(ruleId)}@${line}" style="display:none" onclick="event.stopPropagation();send('cancelFix', ${line}, '${esc(ruleId)}', '${source}')">✖ ${t('fix.cancel')}</button>`);
} else if (aiFixable) {
parts.push(`<button class="item-fix" data-fix-key="${esc(ruleId)}@${line}" data-label="🤖 ${esc(t('report.fixAILabel'))}" onclick="event.stopPropagation(); this.disabled=true; this.textContent='⏳...';send('fix', ${line}, '${esc(ruleId)}', '${source}')">🤖 ${t('report.fixAILabel')}</button>`);
parts.push(`<button class="item-fix btn-apply" data-fix-key="${esc(ruleId)}@${line}" style="display:none" onclick="event.stopPropagation();send('applyFix', ${line}, '${esc(ruleId)}', '${source}')">✅ ${t('fix.apply')}</button>`);
parts.push(`<button class="item-fix btn-cancel" data-fix-key="${esc(ruleId)}@${line}" style="display:none" onclick="event.stopPropagation();send('cancelFix', ${line}, '${esc(ruleId)}', '${source}')">✖ ${t('fix.cancel')}</button>`);
}
parts.push('</div>');
const fixPlaceholder = (fixable || aiFixable) && !fixDiffHtml
? `<div class="detail-no-fix">${esc(t('report.fixUnavailable'))}</div>`
: '';
if (expandable && (detailHtml || (suggestion && suggestion !== message) || fixDiffHtml || fixPlaceholder)) {
parts.push('<div class="item-detail">');
if (fixDiffHtml) {
parts.push(`<div class="detail-fix-title">${t('report.fixPreview')}</div>`);
parts.push(fixDiffHtml);
} else if (fixPlaceholder) {
parts.push(`<div class="detail-fix-title">${t('report.fixPreview')}</div>`);
parts.push(fixPlaceholder);
}
if (detailHtml) {
parts.push(detailHtml);
} else if (suggestion && suggestion !== message) {
parts.push(`<div class="detail-suggestion">💡 ${esc(suggestion)}</div>`);
}
parts.push('</div>');
}
parts.push('</div>');
parts.push('</div>');
return parts.join('');
}
private buildFixDiffHtml(originalText?: string, newText?: string): string {
if (!originalText || !newText || originalText === newText) { return ''; }
const lines = computeLineDiff(originalText, newText);
return `<div class="fix-diff">${lines.map(l =>
`<div class="diff-line diff-${l.type}"><span class="diff-marker">${l.type === 'del' ? '-' : l.type === 'add' ? '+' : ' '}</span><span class="diff-text">${esc(l.text) || ' '}</span></div>`
).join('')}</div>`;
}
private async handleMessage(message: PanelMessage): Promise<void> {
switch (message.type) {
case 'navigate':
if (message.line !== undefined && this.currentReport) {
const report = this.currentReport;
const uri = vscode.Uri.file(report.filePath);
const existing = vscode.window.visibleTextEditors.find(
e => e.document.uri.fsPath === report.filePath
);
const showOptions: vscode.TextDocumentShowOptions =
existing && existing.viewColumn !== undefined
? { viewColumn: existing.viewColumn }
: { preview: true };
const editor = await vscode.window.showTextDocument(uri, showOptions);
const line = Math.max(0, message.line);
const range = new vscode.Range(line, 0, line, 0);
editor.selection = new vscode.Selection(range.start, range.end);
editor.revealRange(range, vscode.TextEditorRevealType.InCenter);
}
break;
case 'rerun':
vscode.commands.executeCommand('codeReviewer.review');
break;
case 'export':
vscode.commands.executeCommand('codeReviewer.exportReport');
break;
case 'fix':
vscode.commands.executeCommand('codeReviewer.fixIssue', { ...message, origin: 'panel' });
break;
case 'fixAll':
vscode.commands.executeCommand('codeReviewer.fixAll', { source: message.source ?? 'linter' });
break;
case 'undo':
vscode.commands.executeCommand('codeReviewer.undoFix', message);
break;
case 'applyFix':
vscode.commands.executeCommand('codeReviewer.applyFixPreview', message);
break;
case 'cancelFix':
vscode.commands.executeCommand('codeReviewer.cancelFixPreview', message);
break;
case 'applyAll':
vscode.commands.executeCommand('codeReviewer.applyAllPreview');
break;
case 'cancelAll':
vscode.commands.executeCommand('codeReviewer.cancelAllPreview');
break;
}
}
dispose(): void {
ReviewPanel.currentPanel = undefined;
this.panel.dispose();
for (const d of this.disposables) { d.dispose(); }
this.disposables = [];
}
}
|