File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 22export * from "./helptag.ts" ;
33export * from "./nerdfont.ts" ;
44export * from "./noop.ts" ;
5+ export * from "./relative_path.ts" ;
56export * from "./smart_path.ts" ;
Original file line number Diff line number Diff line change 1+ import * as fn from "@denops/std/function" ;
2+ import { relative } from "@std/path/relative" ;
3+
4+ import { defineRenderer , type Renderer } from "../../renderer.ts" ;
5+
6+ type Detail = {
7+ path : string ;
8+ } ;
9+
10+ /**
11+ * Options for the relativePath renderer.
12+ */
13+ export type RelativePathOptions = {
14+ /**
15+ * The base directory to calculate the relative path. If not specified, the
16+ * current working directory is used.
17+ */
18+ base ?: string ;
19+ } ;
20+
21+ /**
22+ * Creates a Renderer that replace file path in the label to relative paths.
23+ *
24+ * @returns A Renderer that replace file path in the label to relative paths.
25+ */
26+ export function relativePath (
27+ options : RelativePathOptions = { } ,
28+ ) : Renderer < Detail > {
29+ return defineRenderer ( async ( denops , { items } , { signal } ) => {
30+ // Get the current working directory
31+ const base = options . base ?? await fn . getcwd ( denops ) ;
32+ signal ?. throwIfAborted ( ) ;
33+
34+ // Convert absolute path in label to relative path
35+ items . forEach ( ( item ) => {
36+ const relpath = relative ( base , item . detail . path ) ;
37+ if ( item . label . includes ( item . detail . path ) ) {
38+ item . label = item . label . replace ( item . detail . path , relpath ) ;
39+ }
40+ } ) ;
41+ } ) ;
42+ }
Original file line number Diff line number Diff line change 4646 "./builtin/renderer/helptag" : " ./builtin/renderer/helptag.ts" ,
4747 "./builtin/renderer/nerdfont" : " ./builtin/renderer/nerdfont.ts" ,
4848 "./builtin/renderer/noop" : " ./builtin/renderer/noop.ts" ,
49+ "./builtin/renderer/relative-path" : " ./builtin/renderer/relative_path.ts" ,
4950 "./builtin/renderer/smart-path" : " ./builtin/renderer/smart_path.ts" ,
5051 "./builtin/sorter" : " ./builtin/sorter/mod.ts" ,
5152 "./builtin/sorter/lexical" : " ./builtin/sorter/lexical.ts" ,
You can’t perform that action at this time.
0 commit comments