diff --git a/src/test/providers/pathOperationTreeProvider.test.ts b/src/test/providers/pathOperationTreeProvider.test.ts index 0c9c077..2d03628 100644 --- a/src/test/providers/pathOperationTreeProvider.test.ts +++ b/src/test/providers/pathOperationTreeProvider.test.ts @@ -81,6 +81,18 @@ suite("getAppLabel", () => { test("falls back to filename when no parent dirs", () => { assert.strictEqual(getAppLabel(makeApp("app", "main.py")), "main") }) + + test("decodes a URI path before using the parent directory", () => { + assert.strictEqual( + getAppLabel( + makeApp( + "app", + "file:///c%3A/project/day01_FastAPI%E5%9F%BA%E7%A1%80/%E4%BB%A3%E7%A0%81/01-%E8%B7%AF%E7%94%B1.py", + ), + ), + "代码", + ) + }) }) suite("getRouterLabel", () => { @@ -122,6 +134,31 @@ suite("getRouterLabel", () => { "items", ) }) + + test("decodes a URI path before using the filename", () => { + assert.strictEqual( + getRouterLabel( + makeRouter("/", { + filePath: + "file:///project/%E4%BB%A3%E7%A0%81/01-%E8%B7%AF%E7%94%B1.py", + }), + "/", + ), + "01-路由", + ) + }) + + test("decodes a URI path before using a generic filename's parent", () => { + assert.strictEqual( + getRouterLabel( + makeRouter("/", { + filePath: "file:///project/%E4%BB%A3%E7%A0%81/routes.py", + }), + "/", + ), + "代码", + ) + }) }) suite("getRouteLabel", () => { diff --git a/src/vscode/pathOperationTreeProvider.ts b/src/vscode/pathOperationTreeProvider.ts index 35d7298..d215625 100644 --- a/src/vscode/pathOperationTreeProvider.ts +++ b/src/vscode/pathOperationTreeProvider.ts @@ -45,7 +45,7 @@ const METHOD_ORDER: Record = { export function getAppLabel(app: AppDefinition): string { if (app.name !== "app") return app.name - const pathParts = app.filePath.split("/") + const pathParts = Uri.parse(app.filePath).path.split("/") const fileName = pathParts.pop() ?? "" const parentDir = pathParts.pop() ?? "" const grandParentDir = pathParts.pop() ?? "" @@ -73,7 +73,7 @@ export function getRouterLabel( if (label !== "/") return label if (router.tags.length > 0) return `/${router.tags[0]}` - const parts = router.location.filePath.split("/") + const parts = Uri.parse(router.location.filePath).path.split("/") const fileName = parts.pop()?.replace(/\.py$/, "") ?? "" if (fileName === "router" || fileName === "routes") return parts.pop() ?? fileName