Skip to content

The IDE you know, rebuilt in Rust. IntelliJ IDEA–style keymap, tool windows and search-everywhere in a fast native app: editor, code insight, debugger, Git, terminal, database and HTTP clients for 60+ languages.

fix(project-tree): keep remote paths away from the local file manager (#2340)

ntbang090116ba1ba3f5f7
diff --git a/src/editor/core/controller.test.ts b/src/editor/core/controller.test.ts
index 8485406ae..06c685eaa 100644
--- a/src/editor/core/controller.test.ts
+++ b/src/editor/core/controller.test.ts
@@ -7,6 +7,7 @@ import { resetDistractionFree, setDistractionFree } from "@/workbench/distractio
import { registerTextEditorWrapper } from "@/workbench/contributions";
import { registerActions } from "@/platform/actions";
import { useProject } from "@/platform/project";
+import { useRemote } from "@/platform/remote";
import { resolveMenuItems } from "@/ui";
import { getContext } from "@/platform/context";
import { installKeyboardDispatcher } from "@/platform/keymap";
@@ -329,6 +330,15 @@ describe("EditorController", () => {
const items = resolveMenuItems(ctrl.tabMenu(pane.id, pane.tabs[0]!));
expect(items.find((i) => i.label === "Close Tabs to the Left")?.disabled).toBe(true);
expect(items.find((i) => i.label === "Close Tabs to the Right")?.disabled).toBe(false);
+ const tabMenu = () => ctrl!.tabMenu(pane.id, pane.tabs[0]!);
+ const openIn = () => resolveMenuItems(resolveMenuItems(tabMenu()).find((i) => i.label === "Open In")!.submenu!);
+ const reveal = "project.revealInFinder|/p/a.ts";
+ expect(openIn().map((i) => i.key)).toContain(reveal);
+ useRemote.setState({
+ session: { target: { kind: "ssh", config: "box" }, root: "/p", host: "box", os: "linux", commands: [] },
+ });
+ expect(openIn().map((i) => i.key)).not.toContain(reveal);
+ useRemote.setState({ session: null });
dispose();
useProject.setState({ project: null, settings: null });
});
diff --git a/src/editor/core/controller.ts b/src/editor/core/controller.ts
index d5618cb2e..f103e11e7 100644
--- a/src/editor/core/controller.ts
+++ b/src/editor/core/controller.ts
@@ -41,7 +41,7 @@ import { t } from "@/platform/i18n";
import { call, commands } from "@/platform/ipc";
import { isRemoteWindow } from "@/platform/remote";
import { fileIconName, showContextMenu, type MenuItem } from "@/ui";
-import { fileManagerName } from "@/platform/fileManager";
+import { canRevealInFileManager, fileManagerName } from "@/platform/fileManager";
import {
activateTab,
changeSplitOrientation,
@@ -1910,7 +1910,9 @@ function openInMenu(path: string): MenuItem {
label: "Open In",
submenu: [
{ kind: "action", action: "navigate.selectIn", arg: { path }, label: "Project View" },
- { kind: "action", action: "project.revealInFinder", arg: path, label: fileManagerName() },
+ ...(canRevealInFileManager()
+ ? [{ kind: "action" as const, action: "project.revealInFinder", arg: path, label: fileManagerName() }]
+ : []),
{ kind: "action", action: "project.openInTerminal", arg: path, label: "Terminal" },
{ kind: "separator" },
...menuGroupItems("openIn", { paths: [path] }),
diff --git a/src/features/app/AboutDialog.tsx b/src/features/app/AboutDialog.tsx
index 9d269049b..0ea3660c3 100644
--- a/src/features/app/AboutDialog.tsx
+++ b/src/features/app/AboutDialog.tsx
@@ -110,7 +110,11 @@ function AboutDialog({ onClose }: { onClose: () => void }) {
{t("app.action.showLog", { os: build?.os ?? guessOs() })}
</button>
{app && (
- <button type="button" className={styles.link} onClick={() => void revealInFileManager(app.configDir)}>
+ <button
+ type="button"
+ className={styles.link}
+ onClick={() => void revealInFileManager(app.configDir, null)}
+ >
{t("app.about.showConfig")}
</button>
)}
diff --git a/src/features/app/appActions.ts b/src/features/app/appActions.ts
index de36229be..5dc69b50b 100644
--- a/src/features/app/appActions.ts
+++ b/src/features/app/appActions.ts
@@ -19,7 +19,7 @@ export async function showLog(): Promise<void> {
if (!isTauri()) return;
try {
const loc = await call(commands.appLogLocation());
- await revealInFileManager(loc.file ?? loc.dir);
+ await revealInFileManager(loc.file ?? loc.dir, null);
} catch (e) {
notifications().notify({ level: "error", title: t("app.log.failed"), body: errorText(e) });
}
diff --git a/src/features/project-tree/actions.ts b/src/features/project-tree/actions.ts
index 8f52404bc..13a91e82e 100644
--- a/src/features/project-tree/actions.ts
+++ b/src/features/project-tree/actions.ts
@@ -2,7 +2,7 @@
import { activeEditor } from "@/editor/api";
import { getAction, registerActions, type Action } from "@/platform/actions";
import { getContext } from "@/platform/context";
-import { revealInFileManagerLabel } from "@/platform/fileManager";
+import { canRevealInFileManager, revealInFileManagerLabel } from "@/platform/fileManager";
import { dirname, useProject } from "@/platform/project";
import { showContextMenu, type MenuItem } from "@/ui";
import { maybeEditorService, menuGroupItems, toolWindowService } from "@/workbench/contributions";
@@ -121,7 +121,9 @@ export function selectInTargets(path: string): MenuItem[] {
...(getAction("navigate.navigationBar") && maybeEditorService()?.activePath() === path
? [{ kind: "action" as const, action: "navigate.navigationBar", label: "Navigation Bar" }]
: []),
- { label: revealLabel(), icon: "external-link", run: () => void revealInFinder(nodesFrom(path)) },
+ ...(canRevealInFileManager()
+ ? [{ label: revealLabel(), icon: "external-link", run: () => void revealInFinder(nodesFrom(path)) }]
+ : []),
...(getAction("terminal.openAt")
? [{ label: "Terminal", icon: "terminal", run: () => void delegate("terminal.openAt", parentOf(path)) }]
: []),
diff --git a/src/features/project-tree/contextMenu.test.ts b/src/features/project-tree/contextMenu.test.ts
index 1f97499ea..4944b8c79 100644
--- a/src/features/project-tree/contextMenu.test.ts
+++ b/src/features/project-tree/contextMenu.test.ts
@@ -1,6 +1,7 @@
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { registerActions } from "@/platform/actions";
import { useProject } from "@/platform/project";
+import { useRemote } from "@/platform/remote";
import { resolveMenuItems, type MenuItem } from "@/ui";
import { registerMenuGroup } from "@/workbench/contributions";
import { contextMenuItems, revealLabel } from "./contextMenu";
@@ -73,6 +74,7 @@ afterEach(() => {
disposers.forEach((d) => d());
useProject.setState({ project: null, settings: null });
useProjectTree.setState({ root: null });
+ useRemote.setState({ session: null });
});
describe("project view context menu", () => {
@@ -139,6 +141,19 @@ describe("project view context menu", () => {
}
});
+ it("hides the OS file manager in an SSH or dev-container window, whose files are not on this desktop", () => {
+ const library = { ...node("/root/.m2/lib.jar"), readOnly: true };
+ expect(sub(contextMenuItems([library]), "Open In")).toEqual([revealLabel()]);
+ for (const target of [
+ { kind: "ssh", config: "box" },
+ { kind: "devContainer", folder: "/Users/me/app", config: "" },
+ ] as const) {
+ useRemote.setState({ session: { target, root: ROOT, host: "h", os: "linux", commands: [] } });
+ expect(sub(contextMenuItems([node(`${ROOT}/src/a.py`)]), "Open In")).toEqual(["Terminal"]);
+ expect(labels(contextMenuItems([library]))).not.toContain("Open In");
+ }
+ });
+
it("offers branch comparison for files, folders, their union and the project root", () => {
for (const nodes of [
[node("/p/a.py")],
diff --git a/src/features/project-tree/contextMenu.ts b/src/features/project-tree/contextMenu.ts
index 7f9d81ed0..6dc182f71 100644
--- a/src/features/project-tree/contextMenu.ts
+++ b/src/features/project-tree/contextMenu.ts
@@ -1,6 +1,6 @@
/** Context menu and "New" popup of the project view. */
import { executeAction, getAction } from "@/platform/actions";
-import { fileManagerName } from "@/platform/fileManager";
+import { canRevealInFileManager, fileManagerName } from "@/platform/fileManager";
import { formatBinding, hostBinding, isMacHost, shortcutLabel } from "@/platform/keymap";
import { relativePath, useProject } from "@/platform/project";
import { currentDetectedRoots, currentRoots } from "@/platform/projectRoots";
@@ -300,7 +300,12 @@ export function contextMenuItems(nodes: ProjectNode[]): MenuItem[] {
// Open In ›
push(
submenu("openIn", "Open In", [
- { id: "finder", label: revealLabel(), icon: "external-link", run: () => void revealInFinder(nodes) },
+ canRevealInFileManager() && {
+ id: "finder",
+ label: revealLabel(),
+ icon: "external-link",
+ run: () => void revealInFinder(nodes),
+ },
folder && getAction("terminal.openAt")
? { id: "terminal", label: "Terminal", icon: "terminal", run: () => void delegate("terminal.openAt", folder) }
: null,
@@ -458,7 +463,12 @@ function libraryMenuItems(nodes: ProjectNode[]): MenuItem[] {
!!folder && delegated("find.inPath", { directory: folder }, "Find in Files…", { icon: "search" }),
!!folder && { kind: "separator" },
submenu("openIn", "Open In", [
- { id: "finder", label: revealLabel(), icon: "external-link", run: () => void revealInFinder(nodes) },
+ canRevealInFileManager() && {
+ id: "finder",
+ label: revealLabel(),
+ icon: "external-link",
+ run: () => void revealInFinder(nodes),
+ },
]),
single &&
!single.dir &&
diff --git a/src/features/project-tree/filePath.ts b/src/features/project-tree/filePath.ts
index f797500ea..8ca197301 100644
--- a/src/features/project-tree/filePath.ts
+++ b/src/features/project-tree/filePath.ts
@@ -1,9 +1,10 @@
/** Navigate › File Path (⌥⌘F12): the file and its folders, each revealed in the OS file manager. */
import { openPopup } from "@/editor/lsp/popupStore";
-import { fileManagerName, revealInFileManager } from "@/platform/fileManager";
+import { canRevealInFileManager, fileManagerName, revealInFileManager } from "@/platform/fileManager";
import { notifications } from "@/workbench/contributions";
import { tx } from "@/platform/i18n";
import { nameOf, parentOf } from "./paths";
+import { notifyRevealUnavailable } from "./operations";
const DRIVE_ROOT = /^[A-Za-z]:\/?$/;
@@ -33,6 +34,7 @@ async function reveal(path: string) {
}
export function showFilePathPopup(path: string, isDir = false) {
+ if (!canRevealInFileManager()) return notifyRevealUnavailable();
const items = filePathChain(path).map((p, i) => ({
id: p,
label: nameOf(p) || p,
diff --git a/src/features/project-tree/operations.ts b/src/features/project-tree/operations.ts
index 55241340e..b58c4e96a 100644
--- a/src/features/project-tree/operations.ts
+++ b/src/features/project-tree/operations.ts
@@ -5,7 +5,7 @@
import { createElement, Fragment } from "react";
import { askUsagesDetected, fileUsages, viewUsages } from "@/editor/refactor";
import { executeAction, getAction } from "@/platform/actions";
-import { fileManagerName, fileManagerPath, revealInFileManager } from "@/platform/fileManager";
+import { canRevealInFileManager, fileManagerName, fileManagerPath, revealInFileManager } from "@/platform/fileManager";
import { maybeEditorService, notifications } from "@/workbench/contributions";
import { ask, confirmChecked } from "@/workbench/messages";
import { osClipboard } from "./clipboard";
@@ -833,7 +833,14 @@ export function revealablePath(path: string): string {
return fileManagerPath(path);
}
+/** For a reveal invoked where the menus hide it (shortcut, Search Everywhere) in an SSH or dev-container window. */
+export function notifyRevealUnavailable() {
+ const fileManager = tx(fileManagerName());
+ notifications().notify({ level: "warning", title: tx`Remote project files cannot be shown in ${fileManager}` });
+}
+
export async function revealInFinder(nodes: ProjectNode[] = selectedNodes()) {
+ if (!canRevealInFileManager()) return notifyRevealUnavailable();
try {
await revealInFileManager(nodes.map((n) => n.path));
} catch (e) {
diff --git a/src/features/project-tree/selectIn.test.ts b/src/features/project-tree/selectIn.test.ts
index 391016951..0437a9cfe 100644
--- a/src/features/project-tree/selectIn.test.ts
+++ b/src/features/project-tree/selectIn.test.ts
@@ -1,19 +1,66 @@
-import { afterEach, describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { revealItemInDir } from "@tauri-apps/plugin-opener";
+import { useLspPopup } from "@/editor/lsp/popupStore";
import { executeAction, getAction, registerActions } from "@/platform/actions";
import { setContext } from "@/platform/context";
import { _resetI18nForTests, setLocale } from "@/platform/i18n";
+import type { RemoteSession } from "@/platform/ipc";
import { usePlatform } from "@/platform/platformInfo";
+import { useRemote } from "@/platform/remote";
import { resolveMenuItems, useContextMenuStore, type MenuItem } from "@/ui";
-import { provideEditorService, registerMenuGroup, type EditorService } from "@/workbench/contributions";
+import {
+ provideEditorService,
+ provideNotificationService,
+ registerMenuGroup,
+ type EditorService,
+} from "@/workbench/contributions";
import { registerProjectActions, selectInTargets } from "./actions";
import { revealLabel } from "./contextMenu";
+vi.mock("@tauri-apps/plugin-opener", () => ({ revealItemInDir: vi.fn() }));
+vi.mock("@/platform/ipc", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@/platform/ipc")>()),
+ isTauri: () => true,
+}));
+
const labels = (items: MenuItem[]) => resolveMenuItems(items).map((r) => (r.kind === "separator" ? "-" : r.label));
+const SSH: RemoteSession = {
+ target: { kind: "ssh", config: "box" },
+ root: "/p",
+ host: "box",
+ os: "linux",
+ commands: [],
+};
const disposers: Array<() => void> = [];
afterEach(() => {
disposers.splice(0).forEach((d) => d());
useContextMenuStore.setState({ menu: null });
+ useRemote.setState({ session: null });
+ vi.mocked(revealItemInDir).mockClear();
+});
+
+describe("Reveal in Finder from a remote window", () => {
+ it("warns instead of asking this desktop's file manager for the server's path", async () => {
+ const notify = vi.fn();
+ provideNotificationService({ notify });
+ disposers.push(registerProjectActions(), () => setContext("projectOpen", false));
+ setContext("projectOpen", true);
+ useRemote.setState({ session: SSH });
+ await executeAction("project.revealInFinder", "/p/src/a.ts");
+ expect(revealItemInDir).not.toHaveBeenCalled();
+ expect(notify).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ level: "warning" }));
+
+ notify.mockClear();
+ useLspPopup.setState({ popup: null });
+ await executeAction("navigate.showFilePath", "/p/src/a.ts");
+ expect(useLspPopup.getState().popup).toBeNull();
+ expect(notify).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ level: "warning" }));
+
+ useRemote.setState({ session: null });
+ await executeAction("project.revealInFinder", "/p/src/a.ts");
+ expect(revealItemInDir).toHaveBeenCalledExactlyOnceWith("/p/src/a.ts");
+ });
});
describe("Open in Terminal", () => {
@@ -86,6 +133,11 @@ describe("Select In (⌥F1)", () => {
]);
});
+ it("leaves out the OS file manager in an SSH window", () => {
+ useRemote.setState({ session: SSH });
+ expect(labels(selectInTargets("/p/src/a.ts"))).not.toContain(revealLabel());
+ });
+
it("without a path shows the chooser for the active file; with one selects it in the project view", async () => {
disposers.push(registerProjectActions(), () => setContext("projectOpen", false));
setContext("projectOpen", true);
diff --git a/src/features/vcs/patches.tsx b/src/features/vcs/patches.tsx
index ee3070850..b269fddef 100644
--- a/src/features/vcs/patches.tsx
+++ b/src/features/vcs/patches.tsx
@@ -2,7 +2,7 @@ import { commitRepo } from "./multiRoot";
/** Create Patch… (from local changes or commits) and Apply Patch… (file or clipboard, with a preview). */
import { useEffect, useState } from "react";
import type { Commit, FileStatus, PatchFile, PatchSource, ShelvedChangeList } from "@/bindings";
-import { fileManagerName, revealInFileManager } from "@/platform/fileManager";
+import { canRevealInFileManager, fileManagerName, revealInFileManager } from "@/platform/fileManager";
import { call, commands } from "@/platform/ipc";
import { Button, Checkbox, Dialog, Icon, Input, List, Spinner, fileIconName, T } from "@/ui";
import { workflowSettings } from "@/platform/workflowSettings";
@@ -95,7 +95,7 @@ export function patchSavedBody(): string {
/** Settings › Version Control › Confirmation › When patch is created: ask / no / show in the file manager. */
async function afterPatchSaved(path: string) {
const mode = workflowSettings().vcs.confirmation.onPatchCreated;
- if (mode === "no") return;
+ if (mode === "no" || !canRevealInFileManager()) return;
if (mode === "ask") {
const r = await ask({
title: "Create Patch",
diff --git a/src/features/welcome/RecentList.tsx b/src/features/welcome/RecentList.tsx
index b80d39bd3..35626fd0c 100644
--- a/src/features/welcome/RecentList.tsx
+++ b/src/features/welcome/RecentList.tsx
@@ -139,7 +139,7 @@ export function recentMenu(project: RecentProject, onOpened?: () => void, onRemo
id: "reveal",
label: showInFileManagerLabel(),
icon: "external-link",
- run: () => void revealInFileManager(project.path).catch(() => undefined),
+ run: () => void revealInFileManager(project.path, null).catch(() => undefined),
},
{
id: "copy",
diff --git a/src/features/welcome/welcome.test.tsx b/src/features/welcome/welcome.test.tsx
index 2c8334e2c..c6712147b 100644
--- a/src/features/welcome/welcome.test.tsx
+++ b/src/features/welcome/welcome.test.tsx
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { act, fireEvent, render, screen, within } from "@testing-library/react";
-import type { RecentProject, Settings } from "@/platform/ipc";
+import type { RecentProject, RemoteTarget, Settings } from "@/platform/ipc";
const settingsSet = vi.fn();
const removeRecentProject = vi.fn();
@@ -26,14 +26,17 @@ vi.mock("@/platform/project", async (importOriginal) => {
return { ...real, openProject: (path: string) => openProject(path) };
});
vi.mock("@tauri-apps/api/path", () => ({ homeDir: async () => "/Users/me" }));
+vi.mock("@tauri-apps/plugin-opener", () => ({ revealItemInDir: vi.fn() }));
vi.mock("@tauri-apps/api/webview", () => ({
getCurrentWebview: () => ({ onDragDropEvent: async () => () => {} }),
}));
import { registerActions } from "@/platform/actions";
+import { revealItemInDir } from "@tauri-apps/plugin-opener";
import { usePlatform } from "@/platform/platformInfo";
import { useProject } from "@/platform/project";
-import { ContextMenuHost } from "@/ui";
+import { remoteLocation, useRemote } from "@/platform/remote";
+import { ContextMenuHost, resolveMenuItems } from "@/ui";
import { registerSettingsPage } from "@/workbench/contributions";
import { MessagesHost } from "@/workbench/messages";
import { projectInitials } from "@/workbench/projectColor";
@@ -152,6 +155,33 @@ describe("Welcome › Projects", () => {
}
});
+ it.each<{ entry: string; target: RemoteTarget | null; shown: boolean }>([
+ { entry: "a local project", target: null, shown: true },
+ { entry: "an SSH project", target: { kind: "ssh", config: "box" }, shown: false },
+ {
+ entry: "a dev-container project",
+ target: { kind: "devContainer", folder: "/Users/me/app", config: "" },
+ shown: false,
+ },
+ ])("offers the file manager for $entry only when this desktop has its folder", ({ target, shown }) => {
+ const path = target ? remoteLocation(target, "/home/me/app") : "/Users/me/app";
+ const items = resolveMenuItems(recentMenu(p("app", path)));
+ expect(items.some((i) => i.key === "reveal")).toBe(shown);
+ });
+
+ it("reveals a local recent project from an SSH window's project switcher", async () => {
+ useRemote.setState({
+ session: { target: { kind: "ssh", config: "box" }, root: "/srv/app", host: "box", os: "linux", commands: [] },
+ });
+ try {
+ resolveMenuItems(recentMenu(p("app", "/Users/me/app"))).find((i) => i.key === "reveal")!.run!();
+ await act(async () => {});
+ expect(revealItemInDir).toHaveBeenCalledExactlyOnceWith("/Users/me/app");
+ } finally {
+ useRemote.setState({ session: null });
+ }
+ });
+
it("shows the landing page without recent projects", async () => {
recent = [];
await renderWelcome();
diff --git a/src/platform/fileManager.test.ts b/src/platform/fileManager.test.ts
index b456b14cc..e60bb4355 100644
--- a/src/platform/fileManager.test.ts
+++ b/src/platform/fileManager.test.ts
@@ -1,6 +1,23 @@
-import { afterEach, describe, expect, it } from "vitest";
-import { fileManagerName, fileManagerPath, revealInFileManagerLabel, showInFileManagerLabel } from "./fileManager";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { revealItemInDir } from "@tauri-apps/plugin-opener";
+import {
+ canRevealInFileManager,
+ fileManagerName,
+ fileManagerPath,
+ revealInFileManager,
+ revealInFileManagerLabel,
+ showInFileManagerLabel,
+} from "./fileManager";
import { _resetI18nForTests, setLocale, tx } from "./i18n";
+import type { RemoteTarget } from "./ipc";
+import { usePlatform } from "./platformInfo";
+import { useRemote } from "./remote";
+
+vi.mock("@tauri-apps/plugin-opener", () => ({ revealItemInDir: vi.fn() }));
+vi.mock("./ipc", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("./ipc")>()),
+ isTauri: () => true,
+}));
const raw = String.raw;
@@ -41,6 +58,46 @@ describe("showInFileManagerLabel", () => {
});
});
+describe("revealInFileManager", () => {
+ const platform = usePlatform.getState();
+ afterEach(() => {
+ usePlatform.setState(platform);
+ useRemote.setState({ session: null });
+ vi.mocked(revealItemInDir).mockClear();
+ });
+
+ const ssh: RemoteTarget = { kind: "ssh", config: "box" };
+ const container: RemoteTarget = { kind: "devContainer", folder: "/Users/me/app", config: "" };
+ it.each<{ window: string; os: string; target: RemoteTarget | null; path: string; revealed: string | null }>([
+ { window: "a local window", os: "macos", target: null, path: "/Users/me/app/a.ts", revealed: "/Users/me/app/a.ts" },
+ {
+ window: "a WSL window on Windows",
+ os: "windows",
+ target: { kind: "wsl", distro: "Ubuntu" },
+ path: "/home/me/app/a.ts",
+ revealed: raw`\\wsl.localhost\Ubuntu\home\me\app\a.ts`,
+ },
+ { window: "an SSH window on macOS", os: "macos", target: ssh, path: "/srv/app/a.ts", revealed: null },
+ { window: "an SSH window on Windows", os: "windows", target: ssh, path: "/srv/app/a.ts", revealed: null },
+ { window: "a dev-container window", os: "macos", target: container, path: "/workspaces/app/a.ts", revealed: null },
+ ])("in $window passes only paths this desktop has to the OS", async ({ os, target, path, revealed }) => {
+ usePlatform.setState({ os });
+ useRemote.setState({ session: target && { target, root: "/p", host: "h", os: "linux", commands: [] } });
+ const shown = await revealInFileManager(path);
+ if (revealed) expect(revealItemInDir).toHaveBeenCalledExactlyOnceWith(revealed);
+ else expect(revealItemInDir).not.toHaveBeenCalled();
+ expect(shown).toBe(revealed !== null);
+ expect(canRevealInFileManager()).toBe(revealed !== null);
+ });
+
+ it("reveals this desktop's own files from a remote window", async () => {
+ usePlatform.setState({ os: "macos" });
+ useRemote.setState({ session: { target: ssh, root: "/p", host: "h", os: "linux", commands: [] } });
+ expect(await revealInFileManager("/Users/me/Library/Logs/openidea.log", null)).toBe(true);
+ expect(revealItemInDir).toHaveBeenCalledExactlyOnceWith("/Users/me/Library/Logs/openidea.log");
+ });
+});
+
describe("fileManagerPath", () => {
it("converts verbatim UNC paths to the form Windows Shell accepts", () => {
expect(
@@ -74,14 +131,8 @@ describe("fileManagerPath", () => {
});
it("translates a WSL distro path to a shell-compatible share on Windows", () => {
- expect(
- fileManagerPath("/home/me/my app", "windows", {
- target: { kind: "wsl", distro: "Ubuntu-24.04" },
- root: "/p",
- host: "Ubuntu",
- os: "linux",
- commands: [],
- }),
- ).toBe(raw`\\wsl.localhost\Ubuntu-24.04\home\me\my app`);
+ expect(fileManagerPath("/home/me/my app", "windows", { kind: "wsl", distro: "Ubuntu-24.04" })).toBe(
+ raw`\\wsl.localhost\Ubuntu-24.04\home\me\my app`,
+ );
});
});
diff --git a/src/platform/fileManager.ts b/src/platform/fileManager.ts
index 2d469afbe..531bd8f48 100644
--- a/src/platform/fileManager.ts
+++ b/src/platform/fileManager.ts
@@ -1,11 +1,15 @@
-import type { RemoteSession } from "./ipc";
+import type { RemoteTarget } from "./ipc";
import { isTauri } from "./ipc";
import { usePlatform } from "./platformInfo";
import { useRemote } from "./remote";
-function wslSharePath(path: string, session: RemoteSession | null): string {
- if (session?.target.kind !== "wsl" || !path.startsWith("/")) return path;
- return `\\\\wsl.localhost\\${session.target.distro}${path.replaceAll("/", "\\")}`;
+function wslSharePath(path: string, target: RemoteTarget | null): string {
+ if (target?.kind !== "wsl" || !path.startsWith("/")) return path;
+ return `\\\\wsl.localhost\\${target.distro}${path.replaceAll("/", "\\")}`;
+}
+
+function windowTarget(): RemoteTarget | null {
+ return useRemote.getState().session?.target ?? null;
}
/**
@@ -13,13 +17,9 @@ function wslSharePath(path: string, session: RemoteSession | null): string {
* paths use `/` separators and may be Windows verbatim paths, but Explorer's
* `ILCreateFromPathW` rejects `\\?\UNC\...`.
*/
-export function fileManagerPath(
- path: string,
- os = usePlatform.getState().os,
- session = useRemote.getState().session,
-): string {
+export function fileManagerPath(path: string, os = usePlatform.getState().os, target = windowTarget()): string {
if (os !== "windows") return path;
- path = wslSharePath(path, session);
+ path = wslSharePath(path, target);
if (/^\/\/\?\/unc\//i.test(path)) path = `\\\\${path.slice(8).replaceAll("/", "\\")}`;
else if (path.startsWith("//?/")) path = path.slice(4);
if (/^\\\\\?\\unc\\/i.test(path)) return `\\\\${path.slice(8)}`;
@@ -43,11 +43,27 @@ export function revealInFileManagerLabel(os = usePlatform.getState().os): string
return os === "macos" ? "Reveal in Finder" : showInFileManagerLabel(os);
}
-/** Reveals files in Explorer, Finder or the Linux desktop's file manager. */
-export async function revealInFileManager(paths: string | readonly string[]): Promise<void> {
- if (!isTauri()) return;
- const list = (typeof paths === "string" ? [paths] : paths).map((path) => fileManagerPath(path));
- if (!list.length) return;
+/**
+ * Whether this desktop's file manager can show paths of `target` (default: this window's; `null`: this
+ * desktop's own). SSH and dev-container paths exist only on the server; WSL ones are reachable on
+ * Windows through their `\\wsl.localhost` share.
+ */
+export function canRevealInFileManager(target = windowTarget(), os = usePlatform.getState().os): boolean {
+ return target === null || (target.kind === "wsl" && os === "windows");
+}
+
+/**
+ * Reveals files in Explorer, Finder or the Linux desktop's file manager. `target` says where the paths
+ * live (default: this window's project host); `false` when this desktop cannot show them.
+ */
+export async function revealInFileManager(
+ paths: string | readonly string[],
+ target = windowTarget(),
+): Promise<boolean> {
+ if (!isTauri() || !canRevealInFileManager(target)) return false;
+ const list = (typeof paths === "string" ? [paths] : paths).map((path) => fileManagerPath(path, undefined, target));
+ if (!list.length) return false;
const { revealItemInDir } = await import("@tauri-apps/plugin-opener");
await revealItemInDir(list.length === 1 ? list[0]! : [...list]);
+ return true;
}
diff --git a/src/platform/locales/text/en.json b/src/platform/locales/text/en.json
index 945c8e3df..3751385ce 100644
--- a/src/platform/locales/text/en.json
+++ b/src/platform/locales/text/en.json
@@ -755,5 +755,6 @@
"Maven could not be started. Configure Maven home in Maven settings, install Maven on PATH, or use a project with a Maven wrapper.": "Maven could not be started. Configure Maven home in Maven settings, install Maven on PATH, or use a project with a Maven wrapper.",
"Gradle could not be started. Configure a local installation in Gradle settings, install Gradle on PATH, or use a project with a Gradle wrapper.": "Gradle could not be started. Configure a local installation in Gradle settings, install Gradle on PATH, or use a project with a Gradle wrapper.",
"Remote of {name}": "Remote of {name}",
- "Target branch of {name}": "Target branch of {name}"
+ "Target branch of {name}": "Target branch of {name}",
+ "Remote project files cannot be shown in {fileManager}": "Remote project files cannot be shown in {fileManager}"
}
diff --git a/src/platform/locales/text/zh.json b/src/platform/locales/text/zh.json
index c0e2efa63..d59fa8c4d 100644
--- a/src/platform/locales/text/zh.json
+++ b/src/platform/locales/text/zh.json
@@ -7088,5 +7088,6 @@
"Maven could not be started. Configure Maven home in Maven settings, install Maven on PATH, or use a project with a Maven wrapper.": "无法启动 Maven。请在 Maven 设置中配置 Maven 主目录,将 Maven 安装到 PATH,或使用带有 Maven wrapper 的项目。",
"Gradle could not be started. Configure a local installation in Gradle settings, install Gradle on PATH, or use a project with a Gradle wrapper.": "无法启动 Gradle。请在 Gradle 设置中配置本地安装,将 Gradle 安装到 PATH,或使用带有 Gradle wrapper 的项目。",
"Remote of {name}": "{name} 的远程",
- "Target branch of {name}": "{name} 的目标分支"
+ "Target branch of {name}": "{name} 的目标分支",
+ "Remote project files cannot be shown in {fileManager}": "无法在{fileManager}中显示远程项目的文件"
}