дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
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
Цей коміт міститься в:
1 джерело
dd8de05013
коміт
7c2e33b77c
3 files changed
+59
-5
No files matched your search
@@ -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(),
|
||||
},
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in new issue
Заблокувати користувача