mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-07 00:44:49 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f49732c63 |
@@ -1,4 +1,6 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { resolveFilePreviewReadTarget } from "@/file-explorer/preview-target";
|
||||||
|
import { resolveWorkspaceFilePaths } from "@/workspace/file-open";
|
||||||
import {
|
import {
|
||||||
classifyAssistantFileLink,
|
classifyAssistantFileLink,
|
||||||
normalizeInlinePathTarget,
|
normalizeInlinePathTarget,
|
||||||
@@ -611,3 +613,43 @@ describe("encoded filename line markers", () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("slash-prefixed drive links in Windows workspaces", () => {
|
||||||
|
it.each([
|
||||||
|
["/E:/demo/repo/tools/tool.vbs", "E:/demo/repo/tools/tool.vbs", undefined],
|
||||||
|
["/E:/demo/repo/docs/my%20file.md#L12", "E:/demo/repo/docs/my file.md", 12],
|
||||||
|
["/E:/demo/repo/docs/guide.md:12", "E:/demo/repo/docs/guide.md", 12],
|
||||||
|
["E:/demo/repo/tools/tool.vbs", "E:/demo/repo/tools/tool.vbs", undefined],
|
||||||
|
["file:///E:/demo/repo/tools/tool.vbs", "E:/demo/repo/tools/tool.vbs", undefined],
|
||||||
|
])("resolves %s to the workspace read target", (href, path, lineStart) => {
|
||||||
|
const workspaceRoot = "E:\\demo\\repo";
|
||||||
|
const target = parseAssistantFileLink(href, {
|
||||||
|
workspaceRoot,
|
||||||
|
decodeHref: true,
|
||||||
|
explicitLink: true,
|
||||||
|
});
|
||||||
|
expect(target).toMatchObject({ raw: href, path });
|
||||||
|
expect(target?.lineStart).toBe(lineStart);
|
||||||
|
expect(resolveFilePreviewReadTarget({ path: target!.path, workspaceRoot })).toEqual({
|
||||||
|
cwd: workspaceRoot,
|
||||||
|
path,
|
||||||
|
});
|
||||||
|
expect(resolveWorkspaceFilePaths({ path: target!.path, workspaceRoot })).toEqual({
|
||||||
|
absolutePath: path,
|
||||||
|
relativePath: path.slice("E:/demo/repo/".length),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(["/home/demo/repo", undefined])(
|
||||||
|
"preserves POSIX paths with workspace %s",
|
||||||
|
(workspaceRoot) => {
|
||||||
|
expect(
|
||||||
|
parseAssistantFileLink("/E:/demo/repo/tools/tool.vbs", {
|
||||||
|
workspaceRoot,
|
||||||
|
decodeHref: true,
|
||||||
|
explicitLink: true,
|
||||||
|
})?.path,
|
||||||
|
).toBe("/E:/demo/repo/tools/tool.vbs");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ export function parseAssistantFileLink(
|
|||||||
return fileUrlTarget;
|
return fileUrlTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
const trimmed = value?.trim();
|
const trimmed = normalizeWindowsLinkPath(value?.trim(), options.workspaceRoot);
|
||||||
if (!trimmed) {
|
if (!trimmed) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ export function parseAssistantFileLink(
|
|||||||
|
|
||||||
const inlinePathTarget = parseAssistantInlinePathLink(trimmed, options);
|
const inlinePathTarget = parseAssistantInlinePathLink(trimmed, options);
|
||||||
if (inlinePathTarget) {
|
if (inlinePathTarget) {
|
||||||
return inlinePathTarget;
|
return { ...inlinePathTarget, raw: value };
|
||||||
}
|
}
|
||||||
|
|
||||||
const windowsTarget = parseWindowsFileLink(trimmed, value, options);
|
const windowsTarget = parseWindowsFileLink(trimmed, value, options);
|
||||||
@@ -350,6 +350,14 @@ export function isFileLookingAssistantToken(value: string): boolean {
|
|||||||
return isPlausibleAssistantLocalPath(path);
|
return isPlausibleAssistantLocalPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A drive-based workspace identifies the target host's path syntax, even when
|
||||||
|
// the client runs elsewhere. Preserve the same spelling on POSIX hosts.
|
||||||
|
function normalizeWindowsLinkPath(value: string, workspaceRoot?: string): string {
|
||||||
|
return /^[A-Za-z]:[\\/]/.test(workspaceRoot?.trim() ?? "") && /^\/[A-Za-z]:[\\/]/.test(value)
|
||||||
|
? value.slice(1)
|
||||||
|
: value;
|
||||||
|
}
|
||||||
|
|
||||||
function parseWindowsFileLink(
|
function parseWindowsFileLink(
|
||||||
trimmed: string,
|
trimmed: string,
|
||||||
raw: string,
|
raw: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user