Skip to content

Commit

Permalink
fix: add compatibility for Lua 5.1 (#456)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
juru1234 authored Aug 17, 2024
1 parent fcca212 commit b39a789
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 107 deletions.
194 changes: 99 additions & 95 deletions lua/oil/mutator/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,115 +192,119 @@ M.parse = function(bufnr)
seen_names[name] = true
end
end
for i, line in ipairs(lines) do
if line:match("^/%d+") then
-- Parse the line for an existing entry
local result, err = M.parse_line(adapter, line, column_defs)
if not result or err then
table.insert(errors, {
message = err,
lnum = i - 1,
end_lnum = i,
col = 0,
})
goto continue
elseif result.data.id == 0 then
-- 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)
for i, line in ipairs(lines) do
-- hack to be compatible with Lua 5.1
-- use return instead of goto
(function()
if line:match("^/%d+") then
-- Parse the line for an existing entry
local result, err = M.parse_line(adapter, line, column_defs)
if not result or err then
table.insert(errors, {
message = err,
lnum = i - 1,
end_lnum = i,
col = 0,
})
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

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,
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,
})
elseif entry[FIELD_TYPE] ~= parsed_entry._type then
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, {
type = "new",
name = parsed_entry.name,
entry_type = parsed_entry._type,
id = parsed_entry.id,
link = parsed_entry.link_target,
})
else
original_entries[parsed_entry.name] = nil
end
else
table.insert(diffs, {
type = "new",
name = parsed_entry.name,
entry_type = parsed_entry._type,
id = parsed_entry.id,
link = parsed_entry.link_target,
})
end

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],
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
else
-- 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,
})
return
end
end
else
-- 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)
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
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
Expand Down
22 changes: 10 additions & 12 deletions lua/oil/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -626,19 +626,17 @@ local function render_buffer(bufnr, opts)
end

for _, entry in ipairs(entry_list) do
if not M.should_display(entry[FIELD_NAME], bufnr) then
goto continue
end
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)
table.insert(line_table, cols)

local name = entry[FIELD_NAME]
if seek_after_render == name then
seek_after_render_found = true
jump_idx = #line_table
M.set_last_cursor(bufname, nil)
if M.should_display(entry[FIELD_NAME], bufnr) then
local cols = M.format_entry_cols(entry, column_defs, col_width, adapter)
table.insert(line_table, cols)

local name = entry[FIELD_NAME]
if seek_after_render == name then
seek_after_render_found = true
jump_idx = #line_table
M.set_last_cursor(bufname, nil)
end
end
::continue::
end

local lines, highlights = util.render_table(line_table, col_width)
Expand Down

0 comments on commit b39a789

Please sign in to comment.