File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as fn from "@denops/std/function" ;
2+ import { join } from "@std/path/join" ;
3+ import { isAbsolute } from "@std/path/is-absolute" ;
4+
5+ import { defineRefiner , type Refiner } from "../../refiner.ts" ;
6+
7+ type Detail = {
8+ path : string ;
9+ } ;
10+
11+ type DetailAfter = {
12+ abspath : string ;
13+ } ;
14+
15+ /**
16+ * Options for the `absolutePath` Refiner.
17+ */
18+ export type AbsolutePathOptions = {
19+ /**
20+ * The base directory to calculate the absolute path from.
21+ */
22+ base ?: string ;
23+ } ;
24+
25+ /**
26+ * Creates a Projector that converts file path in value to absolute paths.
27+ */
28+ export function absolutePath (
29+ options : AbsolutePathOptions = { } ,
30+ ) : Refiner < Detail , DetailAfter > {
31+ return defineRefiner (
32+ async function * ( denops , { items } , { signal } ) {
33+ // Get the current working directory
34+ const base = options . base ?? await fn . getcwd ( denops ) ;
35+ signal ?. throwIfAborted ( ) ;
36+
37+ for await ( const item of items ) {
38+ const abspath = isAbsolute ( item . detail . path )
39+ ? item . detail . path
40+ : join ( base , item . detail . path ) ;
41+ const value = item . value . replace ( item . detail . path , abspath ) ;
42+
43+ yield {
44+ ...item ,
45+ value,
46+ detail : {
47+ ...item . detail ,
48+ abspath,
49+ } ,
50+ } ;
51+ }
52+ } ,
53+ ) ;
54+ }
Original file line number Diff line number Diff line change 11// This file is generated by gen-mod.ts
2+ export * from "./absolute_path.ts" ;
23export * from "./cwd.ts" ;
34export * from "./exists.ts" ;
45export * from "./noop.ts" ;
Original file line number Diff line number Diff line change 3737 "./builtin/previewer/helptag" : " ./builtin/previewer/helptag.ts" ,
3838 "./builtin/previewer/noop" : " ./builtin/previewer/noop.ts" ,
3939 "./builtin/refiner" : " ./builtin/refiner/mod.ts" ,
40+ "./builtin/refiner/absolute-path" : " ./builtin/refiner/absolute_path.ts" ,
4041 "./builtin/refiner/cwd" : " ./builtin/refiner/cwd.ts" ,
4142 "./builtin/refiner/exists" : " ./builtin/refiner/exists.ts" ,
4243 "./builtin/refiner/noop" : " ./builtin/refiner/noop.ts" ,
You can’t perform that action at this time.
0 commit comments