fix: add compatibility for Lua 5.1 (#456)
Some architectures don't support LuaJIT. Remove the goto's from the code to be compatible with Neovim built without LuaJIT. Signed-off-by: Julian Ruess <julianonline+github@posteo.de>
This commit is contained in:
parent
fcca212c2e
commit
b39a78959f
2 changed files with 109 additions and 107 deletions
|
|
@ -192,115 +192,119 @@ M.parse = function(bufnr)
|
||||||
seen_names[name] = true
|
seen_names[name] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, line in ipairs(lines) do
|
for i, line in ipairs(lines) do
|
||||||
if line:match("^/%d+") then
|
-- hack to be compatible with Lua 5.1
|
||||||
-- Parse the line for an existing entry
|
-- use return instead of goto
|
||||||
local result, err = M.parse_line(adapter, line, column_defs)
|
(function()
|
||||||
if not result or err then
|
if line:match("^/%d+") then
|
||||||
table.insert(errors, {
|
-- Parse the line for an existing entry
|
||||||
message = err,
|
local result, err = M.parse_line(adapter, line, column_defs)
|
||||||
lnum = i - 1,
|
if not result or err then
|
||||||
end_lnum = i,
|
table.insert(errors, {
|
||||||
col = 0,
|
message = err,
|
||||||
})
|
lnum = i - 1,
|
||||||
goto continue
|
end_lnum = i,
|
||||||
elseif result.data.id == 0 then
|
col = 0,
|
||||||
-- Ignore entries with ID 0 (typically the "../" entry)
|
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
local parsed_entry = result.data
|
|
||||||
local entry = result.entry
|
|
||||||
|
|
||||||
local err_message
|
|
||||||
if not parsed_entry.name then
|
|
||||||
err_message = "No filename found"
|
|
||||||
elseif not entry then
|
|
||||||
err_message = "Could not find existing entry (was the ID changed?)"
|
|
||||||
elseif parsed_entry.name:match("/") or parsed_entry.name:match(fs.sep) then
|
|
||||||
err_message = "Filename cannot contain path separator"
|
|
||||||
end
|
|
||||||
if err_message then
|
|
||||||
table.insert(errors, {
|
|
||||||
message = err_message,
|
|
||||||
lnum = i - 1,
|
|
||||||
end_lnum = i,
|
|
||||||
col = 0,
|
|
||||||
})
|
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
assert(entry)
|
|
||||||
|
|
||||||
check_dupe(parsed_entry.name, i)
|
|
||||||
local meta = entry[FIELD_META]
|
|
||||||
if original_entries[parsed_entry.name] == parsed_entry.id then
|
|
||||||
if entry[FIELD_TYPE] == "link" and not compare_link_target(meta, parsed_entry) then
|
|
||||||
table.insert(diffs, {
|
|
||||||
type = "new",
|
|
||||||
name = parsed_entry.name,
|
|
||||||
entry_type = "link",
|
|
||||||
link = parsed_entry.link_target,
|
|
||||||
})
|
})
|
||||||
elseif entry[FIELD_TYPE] ~= parsed_entry._type then
|
return
|
||||||
|
elseif result.data.id == 0 then
|
||||||
|
-- Ignore entries with ID 0 (typically the "../" entry)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local parsed_entry = result.data
|
||||||
|
local entry = result.entry
|
||||||
|
|
||||||
|
local err_message
|
||||||
|
if not parsed_entry.name then
|
||||||
|
err_message = "No filename found"
|
||||||
|
elseif not entry then
|
||||||
|
err_message = "Could not find existing entry (was the ID changed?)"
|
||||||
|
elseif parsed_entry.name:match("/") or parsed_entry.name:match(fs.sep) then
|
||||||
|
err_message = "Filename cannot contain path separator"
|
||||||
|
end
|
||||||
|
if err_message then
|
||||||
|
table.insert(errors, {
|
||||||
|
message = err_message,
|
||||||
|
lnum = i - 1,
|
||||||
|
end_lnum = i,
|
||||||
|
col = 0,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
assert(entry)
|
||||||
|
|
||||||
|
check_dupe(parsed_entry.name, i)
|
||||||
|
local meta = entry[FIELD_META]
|
||||||
|
if original_entries[parsed_entry.name] == parsed_entry.id then
|
||||||
|
if entry[FIELD_TYPE] == "link" and not compare_link_target(meta, parsed_entry) then
|
||||||
|
table.insert(diffs, {
|
||||||
|
type = "new",
|
||||||
|
name = parsed_entry.name,
|
||||||
|
entry_type = "link",
|
||||||
|
link = parsed_entry.link_target,
|
||||||
|
})
|
||||||
|
elseif entry[FIELD_TYPE] ~= parsed_entry._type then
|
||||||
|
table.insert(diffs, {
|
||||||
|
type = "new",
|
||||||
|
name = parsed_entry.name,
|
||||||
|
entry_type = parsed_entry._type,
|
||||||
|
})
|
||||||
|
else
|
||||||
|
original_entries[parsed_entry.name] = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
table.insert(diffs, {
|
table.insert(diffs, {
|
||||||
type = "new",
|
type = "new",
|
||||||
name = parsed_entry.name,
|
name = parsed_entry.name,
|
||||||
entry_type = parsed_entry._type,
|
entry_type = parsed_entry._type,
|
||||||
|
id = parsed_entry.id,
|
||||||
|
link = parsed_entry.link_target,
|
||||||
})
|
})
|
||||||
else
|
end
|
||||||
original_entries[parsed_entry.name] = nil
|
|
||||||
|
for _, col_def in ipairs(column_defs) do
|
||||||
|
local col_name = util.split_config(col_def)
|
||||||
|
if columns.compare(adapter, col_name, entry, parsed_entry[col_name]) then
|
||||||
|
table.insert(diffs, {
|
||||||
|
type = "change",
|
||||||
|
name = parsed_entry.name,
|
||||||
|
entry_type = entry[FIELD_TYPE],
|
||||||
|
column = col_name,
|
||||||
|
value = parsed_entry[col_name],
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
table.insert(diffs, {
|
-- Parse a new entry
|
||||||
type = "new",
|
local name, isdir = parsedir(vim.trim(line))
|
||||||
name = parsed_entry.name,
|
if vim.startswith(name, "/") then
|
||||||
entry_type = parsed_entry._type,
|
table.insert(errors, {
|
||||||
id = parsed_entry.id,
|
message = "Paths cannot start with '/'",
|
||||||
link = parsed_entry.link_target,
|
lnum = i - 1,
|
||||||
})
|
end_lnum = i,
|
||||||
end
|
col = 0,
|
||||||
|
})
|
||||||
for _, col_def in ipairs(column_defs) do
|
return
|
||||||
local col_name = util.split_config(col_def)
|
end
|
||||||
if columns.compare(adapter, col_name, entry, parsed_entry[col_name]) then
|
if name ~= "" then
|
||||||
|
local link_pieces = vim.split(name, " -> ", { plain = true })
|
||||||
|
local entry_type = isdir and "directory" or "file"
|
||||||
|
local link
|
||||||
|
if #link_pieces == 2 then
|
||||||
|
entry_type = "link"
|
||||||
|
name, link = unpack(link_pieces)
|
||||||
|
end
|
||||||
|
check_dupe(name, i)
|
||||||
table.insert(diffs, {
|
table.insert(diffs, {
|
||||||
type = "change",
|
type = "new",
|
||||||
name = parsed_entry.name,
|
name = name,
|
||||||
entry_type = entry[FIELD_TYPE],
|
entry_type = entry_type,
|
||||||
column = col_name,
|
link = link,
|
||||||
value = parsed_entry[col_name],
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
end)()
|
||||||
-- Parse a new entry
|
|
||||||
local name, isdir = parsedir(vim.trim(line))
|
|
||||||
if vim.startswith(name, "/") then
|
|
||||||
table.insert(errors, {
|
|
||||||
message = "Paths cannot start with '/'",
|
|
||||||
lnum = i - 1,
|
|
||||||
end_lnum = i,
|
|
||||||
col = 0,
|
|
||||||
})
|
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
if name ~= "" then
|
|
||||||
local link_pieces = vim.split(name, " -> ", { plain = true })
|
|
||||||
local entry_type = isdir and "directory" or "file"
|
|
||||||
local link
|
|
||||||
if #link_pieces == 2 then
|
|
||||||
entry_type = "link"
|
|
||||||
name, link = unpack(link_pieces)
|
|
||||||
end
|
|
||||||
check_dupe(name, i)
|
|
||||||
table.insert(diffs, {
|
|
||||||
type = "new",
|
|
||||||
name = name,
|
|
||||||
entry_type = entry_type,
|
|
||||||
link = link,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for name, child_id in pairs(original_entries) do
|
for name, child_id in pairs(original_entries) do
|
||||||
|
|
|
||||||
|
|
@ -626,19 +626,17 @@ local function render_buffer(bufnr, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, entry in ipairs(entry_list) do
|
for _, entry in ipairs(entry_list) do
|
||||||
if not M.should_display(entry[FIELD_NAME], bufnr) then
|
if M.should_display(entry[FIELD_NAME], bufnr) then
|
||||||
goto continue
|
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)
|
||||||
end
|
table.insert(line_table, cols)
|
||||||
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)
|
|
||||||
table.insert(line_table, cols)
|
|
||||||
|
|
||||||
local name = entry[FIELD_NAME]
|
local name = entry[FIELD_NAME]
|
||||||
if seek_after_render == name then
|
if seek_after_render == name then
|
||||||
seek_after_render_found = true
|
seek_after_render_found = true
|
||||||
jump_idx = #line_table
|
jump_idx = #line_table
|
||||||
M.set_last_cursor(bufname, nil)
|
M.set_last_cursor(bufname, nil)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local lines, highlights = util.render_table(line_table, col_width)
|
local lines, highlights = util.render_table(line_table, col_width)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue