Skip to content

chore: update stylua action and format #1664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
stylua-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4

- name: Check formatting
uses: JohnnyMorganz/stylua-action@v2
uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v0.16.0
args: --color always --check -g '!**/defaults.lua' lua/
version: latest
args: --color always --check lua/

plenary-tests:
runs-on: ubuntu-20.04
Expand Down
1 change: 1 addition & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ line_endings = "Unix"
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferDouble"
syntax = "LuaJIT"
29 changes: 18 additions & 11 deletions lua/neo-tree/setup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ local define_events = function()
return args
end)



local update_opened_buffers = function(args)
args.opened_buffers = utils.get_opened_buffers()
return args
Expand Down Expand Up @@ -298,10 +296,12 @@ M.win_enter_event = function()
local buf_name, message
if vim.startswith(filename, "[No Name]#") then
buf_name = string.sub(filename, 11)
message = "Cannot close because an unnamed buffer is modified. Please save or discard this file."
message =
"Cannot close because an unnamed buffer is modified. Please save or discard this file."
else
buf_name = filename
message = "Cannot close because one of the files is modified. Please save or discard changes."
message =
"Cannot close because one of the files is modified. Please save or discard changes."
end
log.trace("close_if_last_window, showing unnamed modified buffer: ", filename)
vim.schedule(function()
Expand Down Expand Up @@ -625,9 +625,11 @@ M.merge_config = function(user_config, is_auto_config)
-- Setting new "sources" to be the parsed names of the sources
M.config.sources = all_source_names

if ( M.config.source_selector.winbar or M.config.source_selector.statusline )
if
(M.config.source_selector.winbar or M.config.source_selector.statusline)
and M.config.source_selector.sources
and not user_config.default_source then
and not user_config.default_source
then
-- Set the default source to the head of these
-- This resolves some weirdness with the source selector having
-- a different "head" item than our current default.
Expand All @@ -640,14 +642,19 @@ M.merge_config = function(user_config, is_auto_config)
-- log a warning and then "pick" the first in the sources list
local match = false
for _, source in ipairs(M.config.sources) do
if source == M.config.default_source then
match = true
break
end
if source == M.config.default_source then
match = true
break
end
end
if not match and M.config.default_source ~= "last" then
M.config.default_source = M.config.sources[1]
log.warn(string.format("Invalid default source found in configuration. Using first available source: %s", M.config.default_source))
log.warn(
string.format(
"Invalid default source found in configuration. Using first available source: %s",
M.config.default_source
)
)
end

if not M.config.enable_git_status then
Expand Down
2 changes: 1 addition & 1 deletion lua/neo-tree/sources/buffers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local git = require("neo-tree.git")

local M = {
name = "buffers",
display_name = " 󰈚 Buffers "
display_name = " 󰈚 Buffers ",
}

local wrap = function(func)
Expand Down
14 changes: 7 additions & 7 deletions lua/neo-tree/sources/common/components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ local truncate_string = function(str, max_length)
return str:sub(1, max_length - 1) .. "…"
end

local get_header = function (state, label, size)
local get_header = function(state, label, size)
if state.sort and state.sort.label == label then
local icon = state.sort.direction == 1 and "▲" or "▼"
size = size - 2
Expand All @@ -478,7 +478,7 @@ M.file_size = function(config, node, state)
if node:get_depth() == 1 then
return {
text = get_header(state, "Size", config.width),
highlight = highlights.FILE_STATS_HEADER
highlight = highlights.FILE_STATS_HEADER,
}
end

Expand All @@ -496,7 +496,7 @@ M.file_size = function(config, node, state)

return {
text = vim.fn.printf("%" .. config.width .. "s ", truncate_string(text, config.width)),
highlight = config.highlight or highlights.FILE_STATS
highlight = config.highlight or highlights.FILE_STATS,
}
end

Expand All @@ -511,7 +511,7 @@ local file_time = function(config, node, state, stat_field)
end
return {
text = get_header(state, label, config.width),
highlight = highlights.FILE_STATS_HEADER
highlight = highlights.FILE_STATS_HEADER,
}
end

Expand All @@ -522,7 +522,7 @@ local file_time = function(config, node, state, stat_field)

return {
text = vim.fn.printf("%" .. config.width .. "s ", truncate_string(display, config.width)),
highlight = config.highlight or highlights.FILE_STATS
highlight = config.highlight or highlights.FILE_STATS,
}
end

Expand Down Expand Up @@ -551,13 +551,13 @@ M.type = function(config, node, state)
if node:get_depth() == 1 then
return {
text = get_header(state, "Type", config.width),
highlight = highlights.FILE_STATS_HEADER
highlight = highlights.FILE_STATS_HEADER,
}
end

return {
text = vim.fn.printf("%" .. config.width .. "s ", truncate_string(text, config.width)),
highlight = highlights.FILE_STATS
highlight = highlights.FILE_STATS,
}
end

Expand Down
2 changes: 1 addition & 1 deletion lua/neo-tree/sources/common/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ local render_content = function(config, node, state, context)
vim.list_extend(zindex_rendered[align], rendered_item)
rendered_width = rendered_width + calc_rendered_width(rendered_item)
end
::continue::
::continue::
end

max_width = math.max(max_width, rendered_width)
Expand Down
18 changes: 10 additions & 8 deletions lua/neo-tree/sources/common/filters/filter_fzy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@ function M.has_match(needle, haystack, case_sensitive)
end

local function is_lower(c)
return c:match('%l')
return c:match("%l")
end

local function is_upper(c)
return c:match('%u')
return c:match("%u")
end

local function precompute_bonus(haystack)
local match_bonus = {}

local last_char = '/'
local last_char = "/"
for i = 1, string.len(haystack) do
local this_char = haystack:sub(i, i)
if last_char == '/' or last_char == '\\' then
if last_char == "/" or last_char == "\\" then
match_bonus[i] = SCORE_MATCH_SLASH
elseif last_char == '-' or last_char == '_' or last_char == ' ' then
elseif last_char == "-" or last_char == "_" or last_char == " " then
match_bonus[i] = SCORE_MATCH_WORD
elseif last_char == '.' then
elseif last_char == "." then
match_bonus[i] = SCORE_MATCH_DOT
elseif is_lower(last_char) and is_upper(this_char) then
match_bonus[i] = SCORE_MATCH_CAPITAL
Expand Down Expand Up @@ -200,7 +200,9 @@ function M.score_and_positions(needle, haystack, case_sensitive)
for i = n, 1, -1 do
while j >= 1 do
if D[i][j] ~= SCORE_MIN and (match_required or D[i][j] == T[i][j]) then
match_required = (i ~= 1) and (j ~= 1) and (T[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE)
match_required = (i ~= 1)
and (j ~= 1)
and (T[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE)
positions[i] = j
j = j - 1
break
Expand Down Expand Up @@ -240,7 +242,7 @@ function M.get_score_ceiling()
end

function M.get_implementation_name()
return 'lua'
return "lua"
end

return M
52 changes: 26 additions & 26 deletions lua/neo-tree/sources/common/hijack_cursor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ local manager = require("neo-tree.sources.manager")
local M = {}

local hijack_cursor_handler = function()
if vim.o.filetype ~= "neo-tree" then
return
end
local success, source = pcall(vim.api.nvim_buf_get_var, 0, "neo_tree_source")
if not success then
log.debug("Cursor hijack failure: " .. vim.inspect(source))
return
end
local winid = nil
local _, position = pcall(vim.api.nvim_buf_get_var, 0, "neo_tree_position")
if position == "current" then
winid = vim.api.nvim_get_current_win()
end
if vim.o.filetype ~= "neo-tree" then
return
end
local success, source = pcall(vim.api.nvim_buf_get_var, 0, "neo_tree_source")
if not success then
log.debug("Cursor hijack failure: " .. vim.inspect(source))
return
end
local winid = nil
local _, position = pcall(vim.api.nvim_buf_get_var, 0, "neo_tree_position")
if position == "current" then
winid = vim.api.nvim_get_current_win()
end

local state = manager.get_state(source, nil, winid)
if state == nil or not state.tree then
return
end
local node = state.tree:get_node()
log.debug("Cursor moved in tree window, hijacking cursor position")
local cursor = vim.api.nvim_win_get_cursor(0)
local row = cursor[1]
local current_line = vim.api.nvim_get_current_line()
local startIndex, _ = string.find(current_line, node.name, nil, true)
if startIndex then
vim.api.nvim_win_set_cursor(0, { row, startIndex - 1 })
end
local state = manager.get_state(source, nil, winid)
if state == nil or not state.tree then
return
end
local node = state.tree:get_node()
log.debug("Cursor moved in tree window, hijacking cursor position")
local cursor = vim.api.nvim_win_get_cursor(0)
local row = cursor[1]
local current_line = vim.api.nvim_get_current_line()
local startIndex, _ = string.find(current_line, node.name, nil, true)
if startIndex then
vim.api.nvim_win_set_cursor(0, { row, startIndex - 1 })
end
end

--Enables cursor hijack behavior for all sources
Expand Down
62 changes: 31 additions & 31 deletions lua/neo-tree/sources/common/node_expander.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@ local log = require("neo-tree.log")
local M = {}

--- Recursively expand all loaded nodes under the given node
--- returns table with all discovered nodes that need to be loaded
--- returns table with all discovered nodes that need to be loaded
---@param node table a node to expand
---@param state table current state of the source
---@return table discovered nodes that need to be loaded
local function expand_loaded(node, state, prefetcher)
local function rec(current_node, to_load)
if prefetcher.should_prefetch(current_node) then
log.trace("Node " .. current_node:get_id() .. "not loaded, saving for later")
table.insert(to_load, current_node)
else
if not current_node:is_expanded() then
current_node:expand()
state.explicitly_opened_directories[current_node:get_id()] = true
end
local children = state.tree:get_nodes(current_node:get_id())
log.debug("Expanding childrens of " .. current_node:get_id())
for _, child in ipairs(children) do
if child.type == "directory" then
rec(child, to_load)
else
log.trace("Child: " .. child.name .. " is not a directory, skipping")
end
local function rec(current_node, to_load)
if prefetcher.should_prefetch(current_node) then
log.trace("Node " .. current_node:get_id() .. "not loaded, saving for later")
table.insert(to_load, current_node)
else
if not current_node:is_expanded() then
current_node:expand()
state.explicitly_opened_directories[current_node:get_id()] = true
end
local children = state.tree:get_nodes(current_node:get_id())
log.debug("Expanding childrens of " .. current_node:get_id())
for _, child in ipairs(children) do
if child.type == "directory" then
rec(child, to_load)
else
log.trace("Child: " .. child.name .. " is not a directory, skipping")
end
end
end
end

local to_load = {}
rec(node, to_load)
return to_load
local to_load = {}
rec(node, to_load)
return to_load
end

--- Recursively expands all nodes under the given node collecting all unloaded nodes
--- Then run prefetcher on all unloaded nodes. Finally, expand loded nodes.
--- Then run prefetcher on all unloaded nodes. Finally, expand loded nodes.
--- async method
---@param node table a node to expand
---@param state table current state of the source
local function expand_and_load(node, state, prefetcher)
local to_load = expand_loaded(node, state, prefetcher)
for _, _node in ipairs(to_load) do
prefetcher.prefetch(state, _node)
-- no need to handle results as prefetch is recursive
expand_loaded(_node, state, prefetcher)
end
local to_load = expand_loaded(node, state, prefetcher)
for _, _node in ipairs(to_load) do
prefetcher.prefetch(state, _node)
-- no need to handle results as prefetch is recursive
expand_loaded(_node, state, prefetcher)
end
end

--- Expands given node recursively loading all descendant nodes if needed
Expand All @@ -71,12 +71,12 @@ M.expand_directory_recursively = function(state, node, prefetcher)
end

M.default_prefetcher = {
prefetch = function (state, node)
prefetch = function(state, node)
log.debug("Default expander prefetch does nothing")
end,
should_prefetch = function (node)
should_prefetch = function(node)
return false
end
end,
}

return M
Loading
Loading