feat(app): support file:// protocol URLs for opening workspace files

This commit is contained in:
Mohamed Boudra
2026-03-13 10:24:01 +07:00
parent debe4b543b
commit bed03be332
3 changed files with 148 additions and 6 deletions
+40 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { parseInlinePathToken } from "./inline-path";
import { parseFileProtocolUrl, parseInlinePathToken } from "./inline-path";
describe("parseInlinePathToken", () => {
it("returns null for plain paths (no line)", () => {
@@ -31,3 +31,42 @@ describe("parseInlinePathToken", () => {
});
});
describe("parseFileProtocolUrl", () => {
it("parses file URLs with line fragments", () => {
expect(
parseFileProtocolUrl("file:///Users/test/project/src/app.tsx#L81")
).toEqual({
raw: "file:///Users/test/project/src/app.tsx#L81",
path: "/Users/test/project/src/app.tsx",
lineStart: 81,
lineEnd: undefined,
});
});
it("parses file URLs without line fragments", () => {
expect(
parseFileProtocolUrl("file:///Users/test/project/src/app.tsx")
).toEqual({
raw: "file:///Users/test/project/src/app.tsx",
path: "/Users/test/project/src/app.tsx",
lineStart: undefined,
lineEnd: undefined,
});
});
it("parses windows file URLs and line ranges", () => {
expect(
parseFileProtocolUrl("file:///C:/Users/test/project/src/app.tsx#L12-L20")
).toEqual({
raw: "file:///C:/Users/test/project/src/app.tsx#L12-L20",
path: "C:/Users/test/project/src/app.tsx",
lineStart: 12,
lineEnd: 20,
});
});
it("rejects non-file URLs and invalid ranges", () => {
expect(parseFileProtocolUrl("https://example.com/test.ts#L10")).toBeNull();
expect(parseFileProtocolUrl("file:///Users/test/project/src/app.tsx#L20-L12")).toBeNull();
});
});