@@ -64,6 +64,44 @@ util.join_paths = function(...)
64
64
return table.concat ({ ... }, separator )
65
65
end
66
66
67
+ util .path_complete = function (lead )
68
+ local split = vim .split (lead , ' =' )
69
+ local command , path = split [1 ] .. ' =' , split [2 ]
70
+ if # path == 0 then
71
+ path = ' .'
72
+ end
73
+ path = vim .fs .normalize (path )
74
+
75
+ local completion_list = {}
76
+ local is_dir = vim .fn .isdirectory (path ) == 1
77
+ local dirpath = is_dir and path or vim .fs .dirname (path )
78
+ local filepath = not is_dir and vim .fs .basename (path )
79
+
80
+ local sep = util .get_separator ()
81
+ local dir = vim .loop .fs_opendir (dirpath )
82
+
83
+ local function join (d , f )
84
+ return d :sub (# d , # d ) == sep and d .. f or d .. sep .. f
85
+ end
86
+
87
+ local res = vim .loop .fs_readdir (dir )
88
+ while res ~= nil do
89
+ for _ , entry in ipairs (res ) do
90
+ if filepath then
91
+ if vim .startswith (entry .name , filepath ) then
92
+ completion_list [# completion_list + 1 ] = command .. join (dirpath , entry .name )
93
+ end
94
+ else
95
+ completion_list [# completion_list + 1 ] = command .. join (dirpath , entry .name )
96
+ end
97
+ end
98
+ res = vim .loop .fs_readdir (dir )
99
+ end
100
+
101
+ vim .loop .fs_closedir (dir )
102
+ return completion_list
103
+ end
104
+
67
105
util .get_plugin_short_name = function (plugin )
68
106
local path = vim .fn .expand (plugin [1 ])
69
107
local name_segments = vim .split (path , util .get_separator ())
0 commit comments