refactor: 品牌重命名 + maxTokens 支持 + 设置面板简化

- CodeGuard → Code Purifier / 净码特工(displayName、命令、配置标题)
- 新增 ai.maxTokens 配置项,所有 Provider 及 fixer 传入 maxTokens
- AI 引擎增强:repairJsonEscapes + JSON 解析 fallback + 详细错误信息
- 设置面板规则管理改为文件级(list/delete .yaml),addRule 改为 AI 从 Markdown 生成 YAML
- yaml-parser 简化:移除 config.yaml 的 enable/disable 过滤逻辑
- 审查报告面板:errorBanner 优先显示具体错误、lint 诊断显示 suggestion、移除 translatedDiagnostics 独立渲染
- merger 中 translatedDiagnostics 覆盖原始 lint 诊断 message/suggestion
- HTML linter 配置项、测试用例重写、typescript-eslint 移入 dependencies
This commit is contained in:
范智鹏
2026-07-20 20:24:40 +08:00
parent 805737fcfc
commit a734cdf009
31 changed files with 462 additions and 293 deletions
+27 -14
View File
@@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import * as path from 'path';
import { existsSync } from 'fs';
import { execSync, spawn } from 'child_process';
import type { LinterAdapter, LinterDiagnostic, AdapterResult } from '../types';
import { getPMDRulesetPath } from '../config';
@@ -7,24 +8,36 @@ import { getPMDRulesetPath } from '../config';
export class PmdAdapter implements LinterAdapter {
id = 'pmd';
supportedLanguages = ['java'];
private pmdDir: string | null = null;
private resolvePmdDir(): string {
if (this.pmdDir) { return this.pmdDir; }
const candidates: string[] = [];
try {
const ext = vscode.extensions.getExtension?.('vscode-code-reviewer');
if (ext?.extensionPath) {
candidates.push(path.join(ext.extensionPath, 'jars', 'pmd'));
candidates.push(path.join(ext.extensionPath, 'out', 'jars', 'pmd'));
}
} catch { /* ignore */ }
candidates.push(path.join(path.resolve(__dirname, '..'), 'jars', 'pmd'));
candidates.push(path.join(path.resolve(__dirname, '..', '..'), 'jars', 'pmd'));
for (const dir of candidates) {
if (existsSync(path.join(dir, 'PmdRunner.class'))) {
this.pmdDir = dir;
return dir;
}
}
this.pmdDir = candidates[0];
return this.pmdDir;
}
private getPmdLibClasspath(): string {
const extRoot = this.getExtensionRoot();
const pmdLib = path.join(extRoot, 'jars', 'pmd', 'lib');
return path.join(pmdLib, '*');
return path.join(this.resolvePmdDir(), 'lib', '*');
}
private getPmdRunnerClasspath(): string {
const extRoot = this.getExtensionRoot();
return path.join(extRoot, 'jars', 'pmd');
}
private getExtensionRoot(): string {
try {
const extPath = vscode.extensions.getExtension?.('vscode-code-reviewer')?.extensionPath;
if (extPath) { return extPath; }
} catch { /* extension not available */ }
return path.join(__dirname, '..', '..');
return this.resolvePmdDir();
}
async check(document: vscode.TextDocument, workingDir: string): Promise<AdapterResult> {
@@ -43,7 +56,7 @@ export class PmdAdapter implements LinterAdapter {
return { diagnostics, status: 'ok' };
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
if (message.includes('ENOENT') || message.includes('java')) {
if (message.includes('ENOENT') || message.includes('java not found') || message.includes('Cannot find')) {
return { diagnostics: [], status: 'tool-unavailable', errorMessage: 'Java 11+ 未安装或不在 PATH 中' };
}
return { diagnostics: [], status: 'execution-failed', errorMessage: message };