mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
fix(agents): resolve typed paths against Windows project roots
This commit is contained in:
@@ -288,5 +288,7 @@ describe("typed path references", () => {
|
||||
expect(resolveTyped("/r/idea", "../kalo/a.ts")).toBe("/r/kalo/a.ts");
|
||||
expect(resolveTyped("/r/idea", "./src")).toBe("/r/idea/src");
|
||||
expect(resolveTyped("/r/idea", "/etc/hosts")).toBe("/etc/hosts");
|
||||
expect(resolveTyped("C:\\r\\idea", "../kalo/a.ts")).toBe("C:/r/kalo/a.ts");
|
||||
expect(resolveTyped("C:\\r", "../../x")).toBe("C:/x");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -77,14 +77,19 @@ function inOrder(text: string, query: string): boolean {
|
||||
/** Whether an `@` query is a typed-out path (`../x`, `./x`, `/x`) rather than a project file search. */
|
||||
export const isPathQuery = (query: string) => /^(\.\.?(\/|$)|\/)/.test(query);
|
||||
|
||||
const isDrive = (part: string | undefined) => !!part && /^[A-Za-z]:$/.test(part);
|
||||
|
||||
/** `rel` (as typed after `@`) resolved against `root`, `.` and `..` folded lexically. */
|
||||
export function resolveTyped(root: string, rel: string): string {
|
||||
const out: string[] = [];
|
||||
for (const part of (rel.startsWith("/") ? rel : `${root}/${rel}`).split("/")) {
|
||||
if (part === "..") out.pop();
|
||||
else if (part && part !== ".") out.push(part);
|
||||
const path = rel.startsWith("/") ? rel : `${root.replace(/\\/g, "/")}/${rel}`;
|
||||
for (const part of path.split("/")) {
|
||||
if (part === "..") {
|
||||
// Never fold away a Windows drive (`C:`).
|
||||
if (out.length > 1 || !isDrive(out[0])) out.pop();
|
||||
} else if (part && part !== ".") out.push(part);
|
||||
}
|
||||
return `/${out.join("/")}`;
|
||||
return isDrive(out[0]) ? out.join("/") : `/${out.join("/")}`;
|
||||
}
|
||||
|
||||
/** `@rel` with a line range suffix when given ("@src/a.rs:10-20"). */
|
||||
|
||||
Reference in New Issue
Block a user