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 11// This file is generated by gen-mod.ts
2+ export * from "./absolute_path.ts" ;
23export * from "./helptag.ts" ;
34export * from "./nerdfont.ts" ;
45export * from "./noop.ts" ;
Original file line number Diff line number Diff line change 4444 "./builtin/refiner/regexp" : " ./builtin/refiner/regexp.ts" ,
4545 "./builtin/refiner/relative-path" : " ./builtin/refiner/relative_path.ts" ,
4646 "./builtin/renderer" : " ./builtin/renderer/mod.ts" ,
47+ "./builtin/renderer/absolute-path" : " ./builtin/renderer/absolute_path.ts" ,
4748 "./builtin/renderer/helptag" : " ./builtin/renderer/helptag.ts" ,
4849 "./builtin/renderer/nerdfont" : " ./builtin/renderer/nerdfont.ts" ,
4950 "./builtin/renderer/noop" : " ./builtin/renderer/noop.ts" ,
You can’t perform that action at this time.
0 commit comments