add .luacheckrc and fix linter issues
This commit is contained in:
parent
1e67a7c6f4
commit
18dac0ed84
13
.luacheckrc
Normal file
13
.luacheckrc
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
-- vim: ft=lua tw=80
|
||||||
|
|
||||||
|
-- Don't report unused self arguments of methods.
|
||||||
|
self = false
|
||||||
|
|
||||||
|
ignore = {
|
||||||
|
"631", -- max_line_length
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Global objects defined by the C code
|
||||||
|
read_globals = {
|
||||||
|
"vim",
|
||||||
|
}
|
||||||
@ -25,7 +25,7 @@ local function get_colors()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_hl_groups()
|
local function get_hl_groups()
|
||||||
local colors = get_colors()
|
local colors = get_colors()
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -96,7 +96,7 @@ M.hl_groups = {
|
|||||||
['ejs'] = 'HtmlIcon';
|
['ejs'] = 'HtmlIcon';
|
||||||
}
|
}
|
||||||
|
|
||||||
local function get_links()
|
local function get_links()
|
||||||
return {
|
return {
|
||||||
FolderName = 'Directory',
|
FolderName = 'Directory',
|
||||||
Normal = 'Normal',
|
Normal = 'Normal',
|
||||||
|
|||||||
@ -28,7 +28,7 @@ local function create_file(file)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_num_entries(iter)
|
local function get_num_entries(iter)
|
||||||
i = 0
|
local i = 0
|
||||||
for _ in iter do
|
for _ in iter do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
@ -37,7 +37,7 @@ end
|
|||||||
|
|
||||||
function M.create(node)
|
function M.create(node)
|
||||||
if node.name == '..' then return end
|
if node.name == '..' then return end
|
||||||
|
|
||||||
local add_into
|
local add_into
|
||||||
if node.entries ~= nil then
|
if node.entries ~= nil then
|
||||||
add_into = node.absolute_path..'/'
|
add_into = node.absolute_path..'/'
|
||||||
|
|||||||
@ -51,8 +51,8 @@ local function create_root(cwd)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.update_status(entries, cwd)
|
function M.update_status(entries, _cwd)
|
||||||
local cwd = cwd:gsub(' ', '\\ ')
|
local cwd = _cwd:gsub(' ', '\\ ')
|
||||||
local git_root, git_status = get_git_root(cwd)
|
local git_root, git_status = get_git_root(cwd)
|
||||||
if not git_root then
|
if not git_root then
|
||||||
if not create_root(cwd) then
|
if not create_root(cwd) then
|
||||||
|
|||||||
@ -125,7 +125,7 @@ function M.refresh_entries(entries, cwd)
|
|||||||
if not named_entries[name] then
|
if not named_entries[name] then
|
||||||
local n = e.fn(cwd, name)
|
local n = e.fn(cwd, name)
|
||||||
|
|
||||||
local idx = 1
|
idx = 1
|
||||||
if prev then
|
if prev then
|
||||||
idx = entries_idx[prev] + 1
|
idx = entries_idx[prev] + 1
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,8 +11,8 @@ local namespace_id = api.nvim_create_namespace('LuaTreeHighlights')
|
|||||||
local icon_state = config.get_icon_state()
|
local icon_state = config.get_icon_state()
|
||||||
|
|
||||||
local get_folder_icon = function() return "" end
|
local get_folder_icon = function() return "" end
|
||||||
local set_folder_hl = function(index, depth, git_icon_len)
|
local set_folder_hl = function(line, depth, git_icon_len)
|
||||||
table.insert(hl, {'LuaTreeFolderName', index, depth+git_icon_len, -1})
|
table.insert(hl, {'LuaTreeFolderName', line, depth+git_icon_len, -1})
|
||||||
end
|
end
|
||||||
|
|
||||||
if icon_state.show_folder_icon then
|
if icon_state.show_folder_icon then
|
||||||
@ -23,9 +23,9 @@ if icon_state.show_folder_icon then
|
|||||||
return icon_state.icons.folder_icons.default .. " "
|
return icon_state.icons.folder_icons.default .. " "
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
set_folder_hl = function(index, depth, icon_len, name_len)
|
set_folder_hl = function(line, depth, icon_len, name_len)
|
||||||
table.insert(hl, {'LuaTreeFolderName', index, depth+icon_len, depth+icon_len+name_len})
|
table.insert(hl, {'LuaTreeFolderName', line, depth+icon_len, depth+icon_len+name_len})
|
||||||
table.insert(hl, {'LuaTreeFolderIcon', index, depth, depth+icon_len})
|
table.insert(hl, {'LuaTreeFolderIcon', line, depth, depth+icon_len})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -33,8 +33,9 @@ local get_file_icon = function() return "" end
|
|||||||
if icon_state.show_file_icon then
|
if icon_state.show_file_icon then
|
||||||
local web_devicons = require'nvim-web-devicons'
|
local web_devicons = require'nvim-web-devicons'
|
||||||
|
|
||||||
get_file_icon = function(fname, extension, index, depth)
|
get_file_icon = function(fname, extension, line, depth)
|
||||||
local icon, hl_group = web_devicons.get_icon(fname, extension)
|
local hl_group
|
||||||
|
local icon, _ = web_devicons.get_icon(fname, extension)
|
||||||
-- TODO: remove this hl_group and make this in nvim-web-devicons
|
-- TODO: remove this hl_group and make this in nvim-web-devicons
|
||||||
if #extension == 0 then
|
if #extension == 0 then
|
||||||
hl_group = colors.hl_groups[fname]
|
hl_group = colors.hl_groups[fname]
|
||||||
@ -42,7 +43,7 @@ if icon_state.show_file_icon then
|
|||||||
hl_group = colors.hl_groups[extension]
|
hl_group = colors.hl_groups[extension]
|
||||||
end
|
end
|
||||||
if hl_group and icon then
|
if hl_group and icon then
|
||||||
table.insert(hl, { 'LuaTree'..hl_group, index, depth, depth + #icon })
|
table.insert(hl, { 'LuaTree'..hl_group, line, depth, depth + #icon })
|
||||||
return icon.." "
|
return icon.." "
|
||||||
else
|
else
|
||||||
return icon_state.icons.default and icon_state.icons.default.." " or ""
|
return icon_state.icons.default and icon_state.icons.default.." " or ""
|
||||||
@ -52,10 +53,8 @@ if icon_state.show_file_icon then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local get_git_icons = function() return "" end
|
local get_git_icons = function() return "" end
|
||||||
local git_icon_state = {}
|
|
||||||
if icon_state.show_git_icon then
|
if icon_state.show_git_icon then
|
||||||
|
local git_icon_state = {
|
||||||
git_icon_state = {
|
|
||||||
["M "] = { { icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" } },
|
["M "] = { { icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" } },
|
||||||
[" M"] = { { icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } },
|
[" M"] = { { icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } },
|
||||||
["MM"] = {
|
["MM"] = {
|
||||||
@ -77,14 +76,14 @@ if icon_state.show_git_icon then
|
|||||||
dirty = { { icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } },
|
dirty = { { icon = icon_state.icons.git_icons.unstaged, hl = "LuaTreeGitDirty" } },
|
||||||
}
|
}
|
||||||
|
|
||||||
get_git_icons = function(node, index, depth, icon_len)
|
get_git_icons = function(node, line, depth, icon_len)
|
||||||
local git_status = node.git_status
|
local git_status = node.git_status
|
||||||
if not git_status then return "" end
|
if not git_status then return "" end
|
||||||
|
|
||||||
local icon = ""
|
local icon = ""
|
||||||
local icons = git_icon_state[git_status]
|
local icons = git_icon_state[git_status]
|
||||||
for _, v in ipairs(icons) do
|
for _, v in ipairs(icons) do
|
||||||
table.insert(hl, { v.hl, index, depth+icon_len+#icon, depth+icon_len+#icon+#v.icon })
|
table.insert(hl, { v.hl, line, depth+icon_len+#icon, depth+icon_len+#icon+#v.icon })
|
||||||
icon = icon..v.icon.." "
|
icon = icon..v.icon.." "
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -166,7 +165,7 @@ function M.draw(tree, reload)
|
|||||||
update_draw_data(tree, 0)
|
update_draw_data(tree, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
api.nvim_buf_set_lines(tree.bufnr, 0, -1, false, lines)
|
api.nvim_buf_set_lines(tree.bufnr, 0, -1, false, lines)
|
||||||
M.render_hl(tree.bufnr)
|
M.render_hl(tree.bufnr)
|
||||||
if #lines > cursor[1] then
|
if #lines > cursor[1] then
|
||||||
api.nvim_win_set_cursor(tree.winnr, cursor)
|
api.nvim_win_set_cursor(tree.winnr, cursor)
|
||||||
|
|||||||
@ -21,8 +21,12 @@ M.Tree = {
|
|||||||
bufnr = nil,
|
bufnr = nil,
|
||||||
winnr = nil,
|
winnr = nil,
|
||||||
buf_options = {
|
buf_options = {
|
||||||
'sidescroll=5', 'noswapfile', 'splitbelow',
|
'sidescroll=5',
|
||||||
'noruler', 'noshowmode', 'noshowcmd'
|
'noswapfile',
|
||||||
|
'splitbelow',
|
||||||
|
'noruler',
|
||||||
|
'noshowmode',
|
||||||
|
'noshowcmd'
|
||||||
},
|
},
|
||||||
win_options = {
|
win_options = {
|
||||||
relativenumber = false,
|
relativenumber = false,
|
||||||
@ -114,7 +118,7 @@ local function refresh_nodes(node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.refresh_tree()
|
function M.refresh_tree()
|
||||||
local stat = luv.fs_stat(M.Tree.cwd)
|
-- local stat = luv.fs_stat(M.Tree.cwd)
|
||||||
-- if stat.mtime.sec ~= M.Tree.last_modified then
|
-- if stat.mtime.sec ~= M.Tree.last_modified then
|
||||||
refresh_nodes(M.Tree)
|
refresh_nodes(M.Tree)
|
||||||
-- end
|
-- end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user