дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
In a project with a root Python build file and a nested JavaScript app (frontend/package.json), New inside frontend/src offered Python Package: any folder under a Python build file counted as Python, even inside a root a deeper non-Python build file detected. The innermost claim now wins; folders outside those roots, and roots a Python build file claimed first, keep Python Package. Co-authored-by: audichuang <[email protected]>
36 рядки
1.5 KiB
TypeScript
36 рядки
1.5 KiB
TypeScript
/** Which "New › Package" flavour a folder offers, from the project's roots. */
|
||
import { rootFor, type RootFolder } from "@/platform/languageSettings";
|
||
import { isJvmSourcePackage } from "@/ui/folderPresentation";
|
||
import type { PackageKind } from "./paths";
|
||
|
||
const PY_BUILD = /(^|\/)(pyproject\.toml|setup\.py|setup\.cfg|Pipfile|requirements\.txt)$/;
|
||
|
||
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 {
|
||
if (rootFor(roots, rel)?.kind === "excluded") return null;
|
||
if (isJvmSourcePackage(rel, roots)) return "jvm";
|
||
// A root `pyproject.toml` must not claim `frontend/src`, a root that
|
||
// `frontend/package.json` detected, unless a deeper Python module holds the folder.
|
||
let python = -1;
|
||
let other = -1;
|
||
for (const r of [...roots, ...detected]) {
|
||
if (!r.detectedFrom) continue;
|
||
if (PY_BUILD.test(r.detectedFrom)) {
|
||
const dir = moduleDir(r.detectedFrom);
|
||
if (within(rel, dir)) python = Math.max(python, dir.length);
|
||
} else if (within(rel, r.path)) other = Math.max(other, r.path.length);
|
||
}
|
||
return python >= 0 && python >= other ? "python" : null;
|
||
}
|