Merge pull request #30 from dmitmel/main

Stop using goto to support Lua 5.1
This commit is contained in:
hrsh7th 2021-12-30 22:01:20 +09:00 committed by GitHub
commit 4d58224e31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,32 +109,24 @@ source._candidates = function(_, dirname, include_hidden, callback)
local items = {} local items = {}
while true do local function create_item(name, fs_type)
local name, type, e = vim.loop.fs_scandir_next(fs)
if e then
return callback(type, nil)
end
if not name then
break
end
if not (include_hidden or string.sub(name, 1, 1) ~= '.') then if not (include_hidden or string.sub(name, 1, 1) ~= '.') then
goto continue return
end end
local path = dirname .. '/' .. name local path = dirname .. '/' .. name
local stat = vim.loop.fs_stat(path) local stat = vim.loop.fs_stat(path)
local lstat = nil local lstat = nil
if stat then if stat then
type = stat.type fs_type = stat.type
elseif type == 'link' then elseif fs_type == 'link' then
-- Broken symlink -- Broken symlink
lstat = vim.loop.fs_lstat(dirname) lstat = vim.loop.fs_lstat(dirname)
if not lstat then if not lstat then
goto continue return
end end
else else
goto continue return
end end
local item = { local item = {
@ -144,20 +136,29 @@ source._candidates = function(_, dirname, include_hidden, callback)
kind = cmp.lsp.CompletionItemKind.File, kind = cmp.lsp.CompletionItemKind.File,
data = { data = {
path = path, path = path,
type = type, type = fs_type,
stat = stat, stat = stat,
lstat = lstat, lstat = lstat,
}, },
} }
if type == 'directory' then if fs_type == 'directory' then
item.kind = cmp.lsp.CompletionItemKind.Folder item.kind = cmp.lsp.CompletionItemKind.Folder
item.word = name item.word = name
item.label = name .. '/' item.label = name .. '/'
item.insertText = name .. '/' item.insertText = name .. '/'
end end
table.insert(items, item) table.insert(items, item)
end
::continue:: while true do
local name, fs_type, e = vim.loop.fs_scandir_next(fs)
if e then
return callback(fs_type, nil)
end
if not name then
break
end
create_item(name, fs_type)
end end
callback(nil, items) callback(nil, items)