File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Expand file tree Collapse file tree 3 files changed +45
-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 { defineRenderer , type Renderer } from "../../renderer.ts" ;
6
+
7
+ type Detail = {
8
+ path : string ;
9
+ } ;
10
+
11
+ /**
12
+ * Options for the absolutePath renderer.
13
+ */
14
+ export type AbsolutePathOptions = {
15
+ /**
16
+ * The base directory to calculate the absolute path. If not specified, the
17
+ * current working directory is used.
18
+ */
19
+ base ?: string ;
20
+ } ;
21
+
22
+ /**
23
+ * Creates a Renderer that replace file path in the label to absolute paths.
24
+ *
25
+ * @returns A Renderer that replace file path in the label to absolute paths.
26
+ */
27
+ export function absolutePath (
28
+ options : AbsolutePathOptions = { } ,
29
+ ) : Renderer < Detail > {
30
+ return defineRenderer ( async ( denops , { items } , { signal } ) => {
31
+ // Get the current working directory
32
+ const base = options . base ?? await fn . getcwd ( denops ) ;
33
+ signal ?. throwIfAborted ( ) ;
34
+
35
+ // Convert relative path in label to absolute path
36
+ items . forEach ( ( item ) => {
37
+ const abspath = isAbsolute ( item . detail . path )
38
+ ? item . detail . path
39
+ : join ( base , item . detail . path ) ;
40
+ item . label = item . label . replace ( item . detail . path , abspath ) ;
41
+ } ) ;
42
+ } ) ;
43
+ }
Original file line number Diff line number Diff line change 1
1
// This file is generated by gen-mod.ts
2
+ export * from "./absolute_path.ts" ;
2
3
export * from "./helptag.ts" ;
3
4
export * from "./nerdfont.ts" ;
4
5
export * from "./noop.ts" ;
Original file line number Diff line number Diff line change 44
44
"./builtin/refiner/regexp" : " ./builtin/refiner/regexp.ts" ,
45
45
"./builtin/refiner/relative-path" : " ./builtin/refiner/relative_path.ts" ,
46
46
"./builtin/renderer" : " ./builtin/renderer/mod.ts" ,
47
+ "./builtin/renderer/absolute-path" : " ./builtin/renderer/absolute_path.ts" ,
47
48
"./builtin/renderer/helptag" : " ./builtin/renderer/helptag.ts" ,
48
49
"./builtin/renderer/nerdfont" : " ./builtin/renderer/nerdfont.ts" ,
49
50
"./builtin/renderer/noop" : " ./builtin/renderer/noop.ts" ,
You can’t perform that action at this time.
0 commit comments