@@ -13,22 +13,33 @@ local function onread(err, data)
1313 -- TODO handle err
1414 end
1515 if data then
16- for i in string.gmatch (data , " %S+" ) do
16+ local vals = vim .split (data , " \n " )
17+ for _ ,i in pairs (vals ) do
1718 if # i ~= 0 then
18- table.insert (M .items , i )
19+ table.insert (M .items , { t = i : sub ( 1 , 1 ), name = i : sub ( 3 )} )
1920 end
2021 end
2122 end
2223end
2324
25+ local fileTypesMap = {
26+ [' f' ] = " [file]" ,
27+ [' d' ] = " [dir]" ,
28+ [' c' ] = " [char]" ,
29+ [' l' ] = " [link]" ,
30+ [' b' ] = " [block]" ,
31+ [' p' ] = " [pipe]" ,
32+ [' s' ] = " [socket]"
33+ }
34+
2435M .getCompletionItems = function (prefix , score_func )
2536 local complete_items = {}
2637 for _ , val in ipairs (M .items ) do
27- local score = score_func (prefix , val )
38+ local score = score_func (prefix , val . name )
2839 if score < # prefix / 3 or # prefix == 0 then
2940 table.insert (complete_items , {
30- word = val ,
31- kind = ' Path ' ,
41+ word = val . name ,
42+ kind = fileTypesMap [ val . t ] ,
3243 score = score ,
3344 icase = 1 ,
3445 dup = 1 ,
@@ -55,7 +66,6 @@ M.triggerFunction = function(_, _, _, manager)
5566 keyword = keyword :match (" %s*(%S+)%w*/.*$" )
5667 end
5768 local path = vim .fn .expand (' %:p:h' )
58- print (keyword )
5969 if keyword ~= nil then
6070 -- dealing with special case in matching
6171 if keyword == " /" and line :sub (pos [2 ], pos [2 ]) then
@@ -80,11 +90,12 @@ M.triggerFunction = function(_, _, _, manager)
8090 :: continue::
8191 path = path .. ' /'
8292 M .items = {}
83- local stdout = vim .loop .new_pipe (false )
84- local stderr = vim .loop .new_pipe (false )
93+ local stdout = vim .loop .new_pipe (true )
94+ local stderr = vim .loop .new_pipe (true )
8595 local handle , pid
86- handle , pid = vim .loop .spawn (' ls' , {
87- args = {path , ' -A' },
96+ print (path )
97+ handle , pid = vim .loop .spawn (' find' , {
98+ args = {path , ' -mindepth' , ' 1' , ' -maxdepth' , ' 1' , ' -printf' , ' %y %f\n ' },
8899 stdio = {stdout ,stderr }
89100 },
90101 vim .schedule_wrap (function ()
0 commit comments