fix(http-client): find the generated request scratch on Windows (#356)

Generate Request in HTTP Client (and Generate Requests for Controller, and the gutter icon) left the scratch file empty on Windows with "Cannot open file …\ai.l0ng.openidea/scratches/generated-requests.http": the scratch path joined the native app data directory (backslashes) with a /-separated suffix, so the opened editor could not be found by its path. Scratch paths now normalise the app data directory to the UI's /-separated form through a shared ipcPath helper, used by scratches, the HTTP client and Spring request generation.

Co-authored-by: kevinh458 <[email protected]>

未在 Windows 实机验证。
Цей коміт міститься в:
kevinh authored and GitHub committed 2026-10-30 15:09:50 +08:00
1 джерело 9575500dd6
коміт 9d1fe17894
7 files changed
+144 -4

No files matched your search

+24
Переглянути файл
@@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";
import { ipcPath } from "./paths";
const raw = String.raw;
const APPDATA = raw`C:\Users\me\AppData\Roaming\ai.l0ng.openidea`;
describe("ipcPath", () => {
it("slashes Windows drive paths, plain or verbatim", () => {
expect(ipcPath(APPDATA)).toBe("C:/Users/me/AppData/Roaming/ai.l0ng.openidea");
expect(ipcPath(raw`\\?\C:\Users\me`)).toBe("C:/Users/me");
});
it("slashes network shares", () => {
expect(ipcPath(raw`\\server\share\dir`)).toBe("//server/share/dir");
expect(ipcPath(raw`\\?\UNC\server\share\dir`)).toBe("//server/share/dir");
});
it("leaves UI paths and POSIX paths alone", () => {
expect(ipcPath("C:/Users/me")).toBe("C:/Users/me");
expect(ipcPath("/home/me/notes")).toBe("/home/me/notes");
// A backslash is a legal character in a POSIX file name.
expect(ipcPath(raw`/home/me/a\b.txt`)).toBe(raw`/home/me/a\b.txt`);
});
});
+22
Переглянути файл
@@ -0,0 +1,22 @@
/**
* Paths coming *into* the UI from a native API (`appDataDir()` from
* `@tauri-apps/api/path`, the file dialogs) are native strings: `C:\a\b` on
* Windows. Everything the UI stores and compares — what the backend returns
* (`IpcPath` in `crates/ide-core/src/ipc_path.rs`), the editor's `ctx.path`, the
* project tree — is `/`-separated on every OS, so such a path has to be
* converted before it is used.
*/
const DRIVE = /^[A-Za-z]:\\/;
const NETWORK = /^\\\\/;
/**
* `p` in the form the UI holds paths: `C:\a\b` and `\\?\C:\a\b` become
* `C:/a/b`, `\\server\share` becomes `//server/share`. A path that already is
* in that form — or one that is not a Windows path at all — is returned as is.
*/
export function ipcPath(p: string): string {
let path = p;
if (path.startsWith("\\\\?\\")) path = path.startsWith("\\\\?\\UNC\\") ? `\\\\${path.slice(8)}` : path.slice(4);
return DRIVE.test(path) || NETWORK.test(path) ? path.replace(/\\/g, "/") : path;
}