дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-08 19:02:17 +02:00
feat(java): add the "Serializable class without 'serialVersionUID'" inspection (#1401)
Settings › Editor › Inspections › Java gets the inspection, off by default. When on, jdtls's compiler reports the missing field and offers the add default/generated ID quick fixes. Built-in inspections can now be off by default, the backend resolves the profile in effect, the compiler-defaults file is named after the variant so jdtls restarts with it, and saving inspection settings reconfigures language servers. Fixes #1199
Цей коміт міститься в:
1 джерело
8a884b6362
коміт
11fd64f399
9 files changed
+156
-15
No files matched your search
@@ -15,7 +15,7 @@ import {
|
||||
type InspectionNode,
|
||||
} from "../pages/editor/inspectionsModel";
|
||||
import { splitPageTarget } from "../model/staging";
|
||||
import { validateInspections } from "@/platform/inspections";
|
||||
import { JAVA_SERIAL_VERSION_INSPECTION, validateInspections } from "@/platform/inspections";
|
||||
import { NATURAL_LANGUAGES_PAGE, SPELLING_PAGE } from "../pages/editor/spelling";
|
||||
import { INSPECTIONS_PAGE } from "../pages/editor/inspections";
|
||||
import { EDITOR_PAGES } from "../pages/editor";
|
||||
@@ -69,6 +69,7 @@ describe("inspections tree", () => {
|
||||
expect(tree.map((g) => g.name)).toEqual([
|
||||
"Cargo",
|
||||
"General",
|
||||
"Java",
|
||||
"JavaScript",
|
||||
"Other",
|
||||
"Proofreading",
|
||||
@@ -109,6 +110,19 @@ describe("inspections tree", () => {
|
||||
expect(checkState(o, python)).toBe("on");
|
||||
});
|
||||
|
||||
it("keeps an inspection that is off by default off until turned on", () => {
|
||||
const serial = find(tree, `Java/${JAVA_SERIAL_VERSION_INSPECTION}`)!;
|
||||
expect(checkState({}, serial)).toBe("off");
|
||||
let o = setEnabled({}, serial, true);
|
||||
expect(o).toEqual({ [JAVA_SERIAL_VERSION_INSPECTION]: { enabled: true } });
|
||||
expect(checkState(o, serial)).toBe("on");
|
||||
o = setEnabled(o, serial, false);
|
||||
expect(o).toEqual({});
|
||||
// Turning a whole group on or off only records what differs from each default.
|
||||
const java = find(tree, "group:Java")!;
|
||||
expect(setEnabled({}, java, true)).toEqual({ [JAVA_SERIAL_VERSION_INSPECTION]: { enabled: true } });
|
||||
});
|
||||
|
||||
it("keeps severity and enabled overrides independent", () => {
|
||||
let o = setLevel({}, "lsp:ruff", "error");
|
||||
o = setEnabled(o, find(tree, "Python/lsp:ruff")!, false);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
INSPECTION_LEVELS,
|
||||
codeInspectionId,
|
||||
customProfileId,
|
||||
enabledByDefault,
|
||||
newProfileKey,
|
||||
overridesOf,
|
||||
producerInspectionId,
|
||||
@@ -159,7 +160,7 @@ export function inspectionIds(node: InspectionNode): string[] {
|
||||
return [...(node.id ? [node.id] : []), ...node.children.flatMap(inspectionIds)];
|
||||
}
|
||||
|
||||
export const isEnabled = (o: ProfileOverrides, id: string) => o[id]?.enabled !== false;
|
||||
export const isEnabled = (o: ProfileOverrides, id: string) => o[id]?.enabled ?? enabledByDefault(id);
|
||||
|
||||
export type CheckState = "on" | "off" | "mixed";
|
||||
|
||||
@@ -181,9 +182,12 @@ function withOverride(o: ProfileOverrides, id: string, patch: Partial<Inspection
|
||||
return next;
|
||||
}
|
||||
|
||||
/** Turns a node and all its descendants on or off (on is the default, so it removes the override). */
|
||||
/** Turns a node and all its descendants on or off; an inspection back at its default drops the override. */
|
||||
export function setEnabled(o: ProfileOverrides, node: InspectionNode, enabled: boolean): ProfileOverrides {
|
||||
return inspectionIds(node).reduce((acc, id) => withOverride(acc, id, { enabled: enabled ? undefined : false }), o);
|
||||
return inspectionIds(node).reduce(
|
||||
(acc, id) => withOverride(acc, id, { enabled: enabled === enabledByDefault(id) ? undefined : enabled }),
|
||||
o,
|
||||
);
|
||||
}
|
||||
|
||||
/** `undefined` restores the default ("As reported"). */
|
||||
|
||||
@@ -216,9 +216,14 @@ export interface BuiltinInspection {
|
||||
description: string;
|
||||
/** Highlighting level when the profile sets none (else as reported). */
|
||||
defaultLevel?: InspectionLevel;
|
||||
/** `false`: off until a profile turns it on. */
|
||||
defaultEnabled?: boolean;
|
||||
options?: readonly InspectionOptionSpec[];
|
||||
}
|
||||
|
||||
/** Turned on, the Java language server's compiler reports it (`ide-sdk` `SERIAL_VERSION_INSPECTION`). */
|
||||
export const JAVA_SERIAL_VERSION_INSPECTION = "java:missing-serial-version";
|
||||
|
||||
/** Producer key of the Typo inspection's diagnostics. */
|
||||
export const SPELLING_PRODUCER = "spelling";
|
||||
export const SPELLING_INSPECTION = "builtin:spelling";
|
||||
@@ -283,6 +288,16 @@ export const BUILTIN_INSPECTIONS: readonly BuiltinInspection[] = [
|
||||
group: "General",
|
||||
description: "Compiler errors and warnings of the last Build Project, shown at their source positions.",
|
||||
},
|
||||
{
|
||||
id: JAVA_SERIAL_VERSION_INSPECTION,
|
||||
producer: "jdt-serial-version",
|
||||
name: "Serializable class without 'serialVersionUID'",
|
||||
group: "Java",
|
||||
description:
|
||||
"Reports classes that implement Serializable but declare no serialVersionUID field. Alt+Enter on the class name adds a default or a generated ID. The Java language server checks it, and restarts when this is changed.",
|
||||
defaultLevel: "warning",
|
||||
defaultEnabled: false,
|
||||
},
|
||||
{
|
||||
id: "builtin:sql",
|
||||
producer: "sql-inspections",
|
||||
@@ -310,6 +325,11 @@ export const BUILTIN_INSPECTIONS: readonly BuiltinInspection[] = [
|
||||
const BUILTIN_BY_PRODUCER = new Map(BUILTIN_INSPECTIONS.map((b) => [b.producer, b]));
|
||||
const BUILTIN_BY_ID = new Map(BUILTIN_INSPECTIONS.map((b) => [b.id, b]));
|
||||
|
||||
/** Whether inspection `id` is on when a profile doesn't say. */
|
||||
export function enabledByDefault(id: string): boolean {
|
||||
return BUILTIN_BY_ID.get(id)?.defaultEnabled ?? true;
|
||||
}
|
||||
|
||||
/** Option `key` of inspection `id` under `profile` (its default when unset). */
|
||||
export function inspectionOption(profile: ProfileOverrides, id: string, key: string): boolean {
|
||||
const value = profile[id]?.options?.[key];
|
||||
@@ -363,7 +383,7 @@ export function applyProfile<D extends Diagnostic>(
|
||||
): readonly D[] {
|
||||
const base = producerInspectionId(producer);
|
||||
const own = profile[base];
|
||||
if (own?.enabled === false) return [];
|
||||
if (!(own?.enabled ?? enabledByDefault(base))) return [];
|
||||
const fallback = BUILTIN_BY_PRODUCER.get(producer)?.defaultLevel;
|
||||
let changed = false;
|
||||
const out: D[] = [];
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
"Not found": "未找到",
|
||||
"Not found on PATH": "未在 PATH 中找到",
|
||||
"Reports newer crate versions that Cargo.toml requirements do not already allow.": "报告 Cargo.toml 版本要求尚未允许的较新 crate 版本。",
|
||||
"Serializable class without 'serialVersionUID'": "没有 'serialVersionUID' 的可序列化类",
|
||||
"Reports classes that implement Serializable but declare no serialVersionUID field. Alt+Enter on the class name adds a default or a generated ID. The Java language server checks it, and restarts when this is changed.": "报告实现了 Serializable 但没有声明 serialVersionUID 字段的类。在类名上按 Alt+Enter 可添加默认 ID 或生成的 ID。此检查由 Java 语言服务器执行,更改后语言服务器会重启。",
|
||||
"Run `auggie login` in a terminal.": "在终端中运行 `auggie login`。",
|
||||
"Run `claude` in a terminal and sign in.": "在终端中运行 `claude` 并登录。",
|
||||
"Run `codex login` in a terminal.": "在终端中运行 `codex login`。",
|
||||
|
||||
Reference in new issue
Заблокувати користувача