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.
TypeScript code-editorcross-platformdapdatabase-clientdebuggerdesktop-appdeveloper-toolsgithttp-clientideintellijlsprusttauriterminal
fix(windows): reveal verbatim UNC paths in Explorer (#2132)
Yvesjavadb16214306e4
diff --git a/src/features/app/AboutDialog.tsx b/src/features/app/AboutDialog.tsxindex 53e1320c7..9d269049b 100644--- a/src/features/app/AboutDialog.tsx+++ b/src/features/app/AboutDialog.tsx@@ -1,6 +1,7 @@import { useEffect, useState } from "react";import { create } from "zustand";import { executeAction } from "@/platform/actions";+import { revealInFileManager } from "@/platform/fileManager";import { t as translate, useT } from "@/platform/i18n";import { commands, isTauri, type AppInfo, type BuildInfo } from "@/platform/ipc";import { openExternalUrl } from "@/platform/openUrl";@@ -109,11 +110,7 @@ function AboutDialog({ onClose }: { onClose: () => void }) {{t("app.action.showLog", { os: build?.os ?? guessOs() })}</button>{app && (- <button- type="button"- className={styles.link}- onClick={() => void import("@tauri-apps/plugin-opener").then((o) => o.revealItemInDir(app.configDir))}- >+ <button type="button" className={styles.link} onClick={() => void revealInFileManager(app.configDir)}>{t("app.about.showConfig")}</button>)}diff --git a/src/features/app/appActions.ts b/src/features/app/appActions.tsindex 383dbf650..de36229be 100644--- a/src/features/app/appActions.ts+++ b/src/features/app/appActions.ts@@ -1,6 +1,7 @@import { redo, undo } from "@codemirror/commands";import { EditorView } from "@codemirror/view";import type { Action } from "@/platform/actions";+import { revealInFileManager } from "@/platform/fileManager";import { t } from "@/platform/i18n";import { call, commands, isTauri } from "@/platform/ipc";import { maybeEditorService, notifications, runUndoHandlers } from "@/workbench/contributions";@@ -18,8 +19,7 @@ export async function showLog(): Promise<void> {if (!isTauri()) return;try {const loc = await call(commands.appLogLocation());- const { revealItemInDir } = await import("@tauri-apps/plugin-opener");- await revealItemInDir(loc.file ?? loc.dir);+ await revealInFileManager(loc.file ?? loc.dir);} catch (e) {notifications().notify({ level: "error", title: t("app.log.failed"), body: errorText(e) });}diff --git a/src/features/project-tree/filePath.ts b/src/features/project-tree/filePath.tsindex 13a73f4a7..645ac7925 100644--- a/src/features/project-tree/filePath.ts+++ b/src/features/project-tree/filePath.ts@@ -1,5 +1,6 @@/** Navigate › File Path (⌥⌘F12): the file and its folders, each revealed in the OS file manager. */import { openPopup } from "@/editor/lsp/popupStore";+import { revealInFileManager } from "@/platform/fileManager";import { notifications } from "@/workbench/contributions";import { tx } from "@/platform/i18n";import { nameOf, parentOf } from "./paths";@@ -21,8 +22,7 @@ export function filePathChain(path: string): string[] {async function reveal(path: string) {try {- const { revealItemInDir } = await import("@tauri-apps/plugin-opener");- await revealItemInDir(path);+ await revealInFileManager(path);} catch (e) {const fileManager = revealLabel();notifications().notify({diff --git a/src/features/project-tree/operations.ts b/src/features/project-tree/operations.tsindex aabb1de9e..eb705e90f 100644--- a/src/features/project-tree/operations.ts+++ b/src/features/project-tree/operations.ts@@ -5,6 +5,7 @@import { createElement, Fragment } from "react";import { askUsagesDetected, fileUsages, viewUsages } from "@/editor/refactor";import { executeAction, getAction } from "@/platform/actions";+import { fileManagerPath, revealInFileManager } from "@/platform/fileManager";import { maybeEditorService, notifications } from "@/workbench/contributions";import { ask, confirmChecked } from "@/workbench/messages";import { osClipboard } from "./clipboard";@@ -38,7 +39,7 @@ import {useProjectTree,} from "./store";import { tx } from "@/platform/i18n";-import { hostOs, isRemoteWindow, useRemote } from "@/platform/remote";+import { hostOs, isRemoteWindow } from "@/platform/remote";import { usePlatform } from "@/platform/platformInfo";import { pathToCopy, type PathKind } from "@/platform/copyPath";import { projectFolder, useProject } from "@/platform/project";@@ -829,18 +830,12 @@ export async function copyPaths(kind: PathKind, nodes: ProjectNode[] = selectedN* local paths — translate them to `\\wsl.localhost\<distro>\…` UNC shares.*/export function revealablePath(path: string): string {- const session = useRemote.getState().session;- if (session?.target.kind !== "wsl" || usePlatform.getState().os !== "windows") return path;- if (!path.startsWith("/")) return path;- return `\\\\wsl.localhost\\${session.target.distro}${path.replaceAll("/", "\\")}`;+ return fileManagerPath(path);}export async function revealInFinder(nodes: ProjectNode[] = selectedNodes()) {- const paths = nodes.map((n) => revealablePath(n.path));- if (!paths.length) return;try {- const { revealItemInDir } = await import("@tauri-apps/plugin-opener");- await revealItemInDir(paths.length === 1 ? paths[0]! : paths);+ await revealInFileManager(nodes.map((n) => n.path));} catch (e) {// Same names as contextMenu.revealLabel (kept local: contextMenu imports// this module, so importing it back would be a cycle).diff --git a/src/features/vcs/patches.tsx b/src/features/vcs/patches.tsxindex 72ecc8f6f..1c07e9882 100644--- a/src/features/vcs/patches.tsx+++ b/src/features/vcs/patches.tsx@@ -2,6 +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 { 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";@@ -96,7 +97,7 @@ async function afterPatchSaved(path: string) {if (r.checked) await rememberSetting("vcs.confirmation.onPatchCreated", show ? "reveal" : "no");if (!show) return;}- void import("@tauri-apps/plugin-opener").then((m) => m.revealItemInDir(path)).catch(() => undefined);+ void revealInFileManager(path).catch(() => undefined);}function CreatePatchDialog({ origin, onClose }: { origin: PatchOrigin; onClose: () => void }) {diff --git a/src/features/welcome/RecentList.tsx b/src/features/welcome/RecentList.tsxindex 9c4f42248..57ebdfb86 100644--- a/src/features/welcome/RecentList.tsx+++ b/src/features/welcome/RecentList.tsx@@ -1,6 +1,7 @@import { useMemo, useState, type KeyboardEvent, type MouseEvent, type ReactNode } from "react";import clsx from "clsx";import { call, commands, type RecentProject, type RecentProjectGroup } from "@/platform/ipc";+import { revealInFileManager } from "@/platform/fileManager";import { parseRemoteLocation } from "@/platform/remote";import {HighlightedText,@@ -138,8 +139,7 @@ export function recentMenu(project: RecentProject, onOpened?: () => void, onRemoid: "reveal",label: "Show in Finder",icon: "external-link",- run: () =>- void import("@tauri-apps/plugin-opener").then((m) => m.revealItemInDir(project.path)).catch(() => undefined),+ run: () => void revealInFileManager(project.path).catch(() => undefined),},{id: "copy",diff --git a/src/platform/fileManager.test.ts b/src/platform/fileManager.test.tsnew file mode 100644index 000000000..b8b8f1333--- /dev/null+++ b/src/platform/fileManager.test.ts@@ -0,0 +1,49 @@+import { describe, expect, it } from "vitest";+import { fileManagerPath } from "./fileManager";++const raw = String.raw;++describe("fileManagerPath", () => {+ it("converts verbatim UNC paths to the form Windows Shell accepts", () => {+ expect(+ fileManagerPath(+ raw`\\?\UNC\192.168.10.9\nas\apps\ignis\vaults\我的知识库\111health工作\生产日志分析`,+ "windows",+ null,+ ),+ ).toBe(raw`\\192.168.10.9\nas\apps\ignis\vaults\我的知识库\111health工作\生产日志分析`);+ expect(+ fileManagerPath(+ "//?/UNC/192.168.10.9/nas/apps/ignis/vaults/我的知识库/111health工作/生产日志分析",+ "windows",+ null,+ ),+ ).toBe(raw`\\192.168.10.9\nas\apps\ignis\vaults\我的知识库\111health工作\生产日志分析`);+ expect(fileManagerPath(raw`\\?\unc\server\share`, "windows", null)).toBe(raw`\\server\share`);+ });++ it("converts the UI's slash-separated Windows paths to native paths", () => {+ expect(fileManagerPath("//server/share/my notes", "windows", null)).toBe(raw`\\server\share\my notes`);+ expect(fileManagerPath("C:/work/my project", "windows", null)).toBe(raw`C:\work\my project`);+ expect(fileManagerPath(raw`\\?\C:\work\my project`, "windows", null)).toBe(raw`C:\work\my project`);+ expect(fileManagerPath("//?/C:/work/my project", "windows", null)).toBe(raw`C:\work\my project`);+ });++ it("leaves native Windows paths and non-Windows paths alone", () => {+ expect(fileManagerPath(raw`\\server\share\my notes`, "windows", null)).toBe(raw`\\server\share\my notes`);+ expect(fileManagerPath("/home/me/my notes", "linux", null)).toBe("/home/me/my notes");+ expect(fileManagerPath("/Users/me/my notes", "macos", null)).toBe("/Users/me/my notes");+ });++ 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`);+ });+});diff --git a/src/platform/fileManager.ts b/src/platform/fileManager.tsnew file mode 100644index 000000000..02b8daf11--- /dev/null+++ b/src/platform/fileManager.ts@@ -0,0 +1,39 @@+import type { RemoteSession } 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("/", "\\")}`;+}++/**+ * A path in the form the local OS file manager's Shell APIs accept. Project+ * 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 {+ if (os !== "windows") return path;+ path = wslSharePath(path, session);+ 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)}`;+ if (path.startsWith("\\\\?\\")) return path.slice(4);+ if (path.startsWith("//")) return path.replaceAll("/", "\\");+ if (/^[A-Za-z]:\//.test(path)) return path.replaceAll("/", "\\");+ return path;+}++/** 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;+ const { revealItemInDir } = await import("@tauri-apps/plugin-opener");+ await revealItemInDir(list.length === 1 ? list[0]! : [...list]);+}