From 7077ed61b0a273dde89fd17433c197f911292307 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Braun Date: Tue, 9 Nov 2021 11:21:42 +0100 Subject: [PATCH] Get filetype for unsupported FS As per http://docs.libuv.org/en/v1.x/fs.html `uv_fs_scandir_next` returns a type only for btrfs, ext2, ext3 and ext4 FS. --- lua/cmp_path/init.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/cmp_path/init.lua b/lua/cmp_path/init.lua index 114aa06..8c1ad38 100644 --- a/lua/cmp_path/init.lua +++ b/lua/cmp_path/init.lua @@ -145,6 +145,16 @@ source._candidates = function(_, params, dirname, offset, callback) accept = accept or include_hidden accept = accept or name:sub(1, 1) ~= '.' + local stat = nil + -- Stat when fs_scandir_next doesn't return file type + if type == nil then + stat = vim.loop.fs_stat(dirname .. '/' .. name) + if not stat then + break + end + type = stat.type + end + -- Create items if accept then if type == 'directory' then @@ -155,7 +165,9 @@ source._candidates = function(_, params, dirname, offset, callback) kind = cmp.lsp.CompletionItemKind.Folder, }) elseif type == 'link' then - local stat = vim.loop.fs_stat(dirname .. '/' .. name) + if not stat then + stat = vim.loop.fs_stat(dirname .. '/' .. name) + end if stat then if stat.type == 'directory' then table.insert(items, {