Файли
openidea/src/features/project-tree/packages.ts
T
Jaw 55836e1b49 chore: Format the codebase with oxfmt and check formatting in CI (#135)
Run oxfmt once over the whole repository (formatting only, no logic changes) and add `pnpm format:check` to the frontend CI job so unformatted code no longer builds up. `.oxfmtrc.json` now skips the generated theme docs, test fixtures and code blocks inside Markdown.

Co-authored-by: jaw52 <[email protected]>
2026-10-28 19:35:16 +08:00

34 рядки
1.3 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/** Which "New › Package" flavour a folder offers, from the project's roots. */
import { rootFor, type RootFolder } from "@/platform/languageSettings";
import type { PackageKind } from "./paths";
const JVM_BUILD = /(^|\/)(pom\.xml|build\.gradle(\.kts)?)$/;
const PY_BUILD = /(^|\/)(pyproject\.toml|setup\.py|setup\.cfg|Pipfile|requirements\.txt)$/;
const JVM_DIR = /(^|\/)(java|kotlin|scala|groovy)$/;
const moduleDir = (buildFile: string) =>
buildFile.includes("/") ? buildFile.slice(0, buildFile.lastIndexOf("/")) : "";
const within = (rel: string, dir: string) => !dir || rel === dir || rel.startsWith(`${dir}/`);
/**
* `jvm` inside a Java / Kotlin source or test root (IDEA shows "Package" there
* instead of "Directory"); `python` inside a Python module (PyCharm's "Python Package").
*/
export function packageKindAt(
rel: string,
roots: readonly RootFolder[],
detected: readonly RootFolder[] = [],
): PackageKind | null {
const root = rootFor(roots, rel);
if (root?.kind === "excluded") return null;
if (
(root?.kind === "source" || root?.kind === "test") &&
(JVM_BUILD.test(root.detectedFrom ?? "") || JVM_DIR.test(root.path))
)
return "jvm";
const python = [...roots, ...detected].some(
(r) => r.detectedFrom && PY_BUILD.test(r.detectedFrom) && within(rel, moduleDir(r.detectedFrom)),
);
return python ? "python" : null;
}