Skip to content

Commit 1ca518c

Browse files
committed
feat: only apply relative path to the value
1 parent 9aceada commit 1ca518c

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

builtin/refiner/relative_path.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ type Detail = {
88
};
99

1010
type DetailAfter = {
11-
abspath: string;
11+
relpath: string;
12+
};
13+
14+
export type RelativePathOptions = {
15+
base?: string;
1216
};
1317

1418
/**
15-
* Creates a Projector that converts file paths to relative paths.
16-
*
17-
* This Projector transforms each item's `path` property to a relative path
18-
* based on the current working directory. It also preserves the original
19-
* absolute path in a new `abspath` field in `DetailAfter`.
20-
*
21-
* @returns A Projector that converts absolute paths to relative paths and includes the absolute path as `abspath`.
19+
* Creates a Projector that converts file path in value to relative paths.
2220
*/
23-
export function relativePath(): Refiner<Detail, DetailAfter> {
21+
export function relativePath(
22+
options: RelativePathOptions = {},
23+
): Refiner<Detail, DetailAfter> {
2424
return defineRefiner(
2525
async function* (denops, { items }, { signal }) {
2626
// Get the current working directory
27-
const cwd = await fn.getcwd(denops);
27+
const base = options.base ?? await fn.getcwd(denops);
2828
signal?.throwIfAborted();
2929

3030
// Convert each item's path to a relative path
3131
for await (const item of items) {
32-
const relpath = relative(cwd, item.detail.path);
32+
const relpath = relative(base, item.detail.path);
3333
const value = item.value.replace(item.detail.path, relpath);
3434

3535
// Yield item with updated relative path and original absolute path
@@ -38,8 +38,7 @@ export function relativePath(): Refiner<Detail, DetailAfter> {
3838
value,
3939
detail: {
4040
...item.detail,
41-
path: relpath,
42-
abspath: item.detail.path,
41+
relpath,
4342
},
4443
};
4544
}

0 commit comments

Comments
 (0)