Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 7c2e33b77c fix(project): keep Import Module from Existing Sources available after attaching a project
Attaching a second project turns the window into a multi-project one, and the action was
limited to single-project windows, so it greyed out after the first import. In a window
with several projects there is no single build to link into, so the chosen directory is
attached as another project, as Attach Project does; one already inside a project is
reported as such.

Fixes #7148
2026-12-01 15:37:21 +08:00
3 змінених файлів з 59 додано та 5 видалено

No files matched your search

+2 -2
Переглянути файл
@@ -317,10 +317,10 @@ export function activate(): () => void {
id: "maven.importExternal",
title: "Import Module from Existing Sources",
description:
"Choose a module directory. A pom.xml is linked as a Maven project and a Gradle settings or build script as a Gradle build; a folder with neither is attached as another root. The opened folder stays the project root, and no build file is edited.",
"Choose a module directory. A pom.xml is linked as a Maven project and a Gradle settings or build script as a Gradle build; a folder with neither is attached as another root. In a window with several projects, the directory is attached as another project. The opened folder stays the project root, and no build file is edited.",
category: "Maven",
icon: "plus",
when: "projectOpen && !workspaceOpen",
when: "projectOpen",
keywords: ["import", "module", "existing", "sources", "external", "maven", "pom", "gradle"],
run: () => importModuleFromExistingSources(),
},
+32
Переглянути файл
@@ -324,6 +324,38 @@ it("attaches a module directory without a build file outside the project, after
expect(mocks.link).not.toHaveBeenCalled();
});
it("keeps Import Module from Existing Sources in a window with attached projects and attaches the directory", async () => {
const attached = vi.fn();
const off = registerAction({ id: "project.attachFolder", title: "Attach", run: ({ arg }) => attached(arg) });
act(() =>
useProject.setState({
project: { root: "/p", workspace: { version: 1, name: "p", projects: ["/p", "/code/web"] } } as ProjectInfo,
}),
);
setContext("workspaceOpen", true);
try {
expect(isActionEnabled(allActions().find((a) => a.id === "maven.importExternal")!)).toBe(true);
mocks.open.mockResolvedValue("/code/admin");
await act(async () => {
await executeAction("maven.importExternal");
});
expect(mocks.open).toHaveBeenCalledWith(expect.objectContaining({ defaultPath: "/p" }));
expect(attached).toHaveBeenCalledWith("/code/admin");
expect(mocks.confirm).not.toHaveBeenCalled();
expect(mocks.set).not.toHaveBeenCalled();
expect(mocks.link).not.toHaveBeenCalled();
attached.mockClear();
mocks.open.mockResolvedValue("/code/web/src");
await act(async () => {
await executeAction("maven.importExternal");
});
expect(attached).not.toHaveBeenCalled();
} finally {
off();
}
});
it("doesn't offer to attach a folder where another root can't be attached (a remote window)", async () => {
const attached = vi.fn();
const off = registerAction({
+25 -3
Переглянути файл
@@ -489,14 +489,36 @@ export async function moduleImportKind(
* inside the project is already part of it.
*/
export async function importModuleFromExistingSources() {
const root = useProject.getState().project?.root;
if (!root || useProject.getState().project?.workspace || !isTauri()) return;
const project = useProject.getState().project;
const root = project?.root;
if (!root || !isTauri()) return;
const path = await choosePath({
title: tx`Import Module from Existing Sources`,
directory: true,
defaultPath: root,
defaultPath: project.workspace?.projects[0] ?? root,
});
if (!path) return;
// A window with several projects has no single build to link into: each attached root is a
// project with its own build, so the directory joins as another one, as Attach Project does.
if (project.workspace) {
const dir = lexicalPath(comparablePath(path)).replace(/\/$/, "");
const inside = project.workspace.projects
.map((p) => lexicalPath(comparablePath(p)).replace(/\/$/, ""))
.find((p) => dir === p || isInsideRoot(p, dir));
if (inside) {
const name = dir.split("/").pop() || dir;
notifications().notify({
group: "tools",
level: "info",
title: tx`Already in the project`,
body: tx`${name} is inside the opened project, so its sources are already part of it.`,
key: "module-import-inside",
});
return;
}
await executeAction("project.attachFolder", path);
return;
}
const found = await moduleImportKind(path);
if (!found) {
notifications().notify({