mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
The Project view only ever passed one file to code.reformatFile. A directory or a multi-selection now opens a Reformat Code dialog (Include subdirectories, Optimize imports, File mask with ! excludes, Only VCS changed text); Run reformats and saves every matching file as one cancellable background task, and a single file still reformats straight away. The batch reuses Code Cleanup's per-file step through a shared runOverFiles runner; formatDocument accepts ranges for changed text and reports noFormatter, including when the file's formatter tool is not installed, so skipped files are named in the summary. Ignored, excluded, hidden, symlinked and binary entries are skipped. Closes #3804 Co-authored-by: bertyhell <1710840+bertyhell@users.noreply.github.com>
131 lines
4.7 KiB
TypeScript
131 lines
4.7 KiB
TypeScript
/**
|
|
* Code analysis: Inspect Code (batch language-server diagnostics), Locate
|
|
* Duplicates and Search / Replace Structurally, and the Python inheritance
|
|
* inspections the IDE computes from its own graph.
|
|
*/
|
|
import { registerEditorContribution } from "@/editor/api";
|
|
import { registerActions } from "@/platform/actions";
|
|
import { useProject } from "@/platform/project";
|
|
import { registerOverlay, registerToolWindow } from "@/workbench/contributions";
|
|
import {
|
|
showCodeCleanupDialog,
|
|
showDuplicatesDialog,
|
|
showInspectCodeDialog,
|
|
showReformatCodeDialog,
|
|
showStructuralDialog,
|
|
} from "./AnalysisDialogs";
|
|
import { AnalysisDialogHost } from "./dialogs";
|
|
import { resetDuplicates } from "./duplicates";
|
|
import { DuplicatesHeaderActions, DuplicatesView } from "./DuplicatesView";
|
|
import { pythonInheritanceExtension } from "./inheritanceInspections";
|
|
import { installInspectionProfileSync, resetInspection, runInspection } from "./inspect";
|
|
import { defaultScope } from "./scope";
|
|
import { InspectionHeaderActions, InspectionView, useInspectionHeaderMenu } from "./InspectionView";
|
|
|
|
export function activate(): () => void {
|
|
const disposers = [
|
|
registerEditorContribution({ id: "analysis.python-inheritance", extensions: pythonInheritanceExtension }),
|
|
installInspectionProfileSync(),
|
|
useProject.subscribe((s, prev) => {
|
|
if (s.project?.root === prev.project?.root) return;
|
|
resetInspection();
|
|
resetDuplicates();
|
|
}),
|
|
registerOverlay({ id: "analysis.dialogs", component: AnalysisDialogHost }),
|
|
registerToolWindow({
|
|
id: "inspection",
|
|
title: "Inspection Results",
|
|
icon: "toolwindow-inspection",
|
|
anchor: "bottom",
|
|
stripe: "onUse",
|
|
order: 36,
|
|
component: InspectionView,
|
|
headerActions: InspectionHeaderActions,
|
|
headerMenu: useInspectionHeaderMenu,
|
|
}),
|
|
registerToolWindow({
|
|
id: "duplicates",
|
|
title: "Duplicates",
|
|
icon: "toolwindow-duplicates",
|
|
anchor: "bottom",
|
|
stripe: "onUse",
|
|
order: 37,
|
|
component: DuplicatesView,
|
|
headerActions: DuplicatesHeaderActions,
|
|
}),
|
|
registerActions([
|
|
{
|
|
id: "analyze.inspectCode",
|
|
title: "Inspect Code…",
|
|
category: "Code",
|
|
icon: "toolwindow-inspection",
|
|
when: "projectOpen",
|
|
keywords: ["inspection", "analyze", "diagnostics", "problems"],
|
|
run: () => void showInspectCodeDialog(),
|
|
},
|
|
{
|
|
// IDEA's "Inspect Code with Editor Settings": the current file, no scope dialog.
|
|
id: "analyze.inspectFile",
|
|
title: "Inspect Current File",
|
|
category: "Code",
|
|
icon: "toolwindow-inspection",
|
|
when: "projectOpen && textEditorActive",
|
|
keywords: ["inspect code with editor settings", "inspection", "analyze file"],
|
|
run: () => runInspection(defaultScope("file")),
|
|
},
|
|
{
|
|
id: "code.cleanup",
|
|
title: "Code Cleanup…",
|
|
category: "Code",
|
|
when: "projectOpen",
|
|
keywords: ["fix all", "cleanup", "organize imports", "reformat"],
|
|
run: () => void showCodeCleanupDialog(),
|
|
},
|
|
{
|
|
id: "code.reformatFiles",
|
|
title: "Reformat Code…",
|
|
description: "Reformat Code dialog for `{ files?, directories? }`, as for a project view selection.",
|
|
category: "Code",
|
|
hidden: true,
|
|
when: "projectOpen",
|
|
run: ({ arg }) => {
|
|
const a = (arg ?? {}) as { files?: unknown; directories?: unknown };
|
|
const paths = (v: unknown) => (Array.isArray(v) ? v.filter((p): p is string => typeof p === "string") : []);
|
|
const targets = [
|
|
...paths(a.directories).map((path) => ({ path, dir: true })),
|
|
...paths(a.files).map((path) => ({ path, dir: false })),
|
|
];
|
|
if (targets.length) showReformatCodeDialog(targets);
|
|
},
|
|
},
|
|
{
|
|
id: "analyze.locateDuplicates",
|
|
title: "Locate Duplicates…",
|
|
category: "Code",
|
|
when: "projectOpen",
|
|
keywords: ["duplicates", "clones", "copy paste", "cpd"],
|
|
run: () => void showDuplicatesDialog(),
|
|
},
|
|
{
|
|
id: "find.structural",
|
|
title: "Search Structurally…",
|
|
category: "Find",
|
|
icon: "search",
|
|
when: "projectOpen",
|
|
keywords: ["ssr", "structural search", "pattern", "ast"],
|
|
run: () => void showStructuralDialog(false),
|
|
},
|
|
{
|
|
id: "find.replaceStructural",
|
|
title: "Replace Structurally…",
|
|
category: "Find",
|
|
icon: "replace",
|
|
when: "projectOpen",
|
|
keywords: ["ssr", "structural replace", "pattern", "ast"],
|
|
run: () => void showStructuralDialog(true),
|
|
},
|
|
]),
|
|
];
|
|
return () => disposers.reverse().forEach((d) => d());
|
|
}
|