Skip to content

Commit e752d22

Browse files
authored
chore: update stylua action and format (#1664)
1 parent 1fab54c commit e752d22

File tree

17 files changed

+368
-360
lines changed

17 files changed

+368
-360
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ jobs:
1212
stylua-check:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v1
15+
- uses: actions/checkout@v4
1616

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

2424
plenary-tests:
2525
runs-on: ubuntu-20.04

.stylua.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ line_endings = "Unix"
33
indent_type = "Spaces"
44
indent_width = 2
55
quote_style = "AutoPreferDouble"
6+
syntax = "LuaJIT"

lua/neo-tree/setup/init.lua

+18-11
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ local define_events = function()
4646
return args
4747
end)
4848

49-
50-
5149
local update_opened_buffers = function(args)
5250
args.opened_buffers = utils.get_opened_buffers()
5351
return args
@@ -298,10 +296,12 @@ M.win_enter_event = function()
298296
local buf_name, message
299297
if vim.startswith(filename, "[No Name]#") then
300298
buf_name = string.sub(filename, 11)
301-
message = "Cannot close because an unnamed buffer is modified. Please save or discard this file."
299+
message =
300+
"Cannot close because an unnamed buffer is modified. Please save or discard this file."
302301
else
303302
buf_name = filename
304-
message = "Cannot close because one of the files is modified. Please save or discard changes."
303+
message =
304+
"Cannot close because one of the files is modified. Please save or discard changes."
305305
end
306306
log.trace("close_if_last_window, showing unnamed modified buffer: ", filename)
307307
vim.schedule(function()
@@ -625,9 +625,11 @@ M.merge_config = function(user_config, is_auto_config)
625625
-- Setting new "sources" to be the parsed names of the sources
626626
M.config.sources = all_source_names
627627

628-
if ( M.config.source_selector.winbar or M.config.source_selector.statusline )
628+
if
629+
(M.config.source_selector.winbar or M.config.source_selector.statusline)
629630
and M.config.source_selector.sources
630-
and not user_config.default_source then
631+
and not user_config.default_source
632+
then
631633
-- Set the default source to the head of these
632634
-- This resolves some weirdness with the source selector having
633635
-- a different "head" item than our current default.
@@ -640,14 +642,19 @@ M.merge_config = function(user_config, is_auto_config)
640642
-- log a warning and then "pick" the first in the sources list
641643
local match = false
642644
for _, source in ipairs(M.config.sources) do
643-
if source == M.config.default_source then
644-
match = true
645-
break
646-
end
645+
if source == M.config.default_source then
646+
match = true
647+
break
648+
end
647649
end
648650
if not match and M.config.default_source ~= "last" then
649651
M.config.default_source = M.config.sources[1]
650-
log.warn(string.format("Invalid default source found in configuration. Using first available source: %s", M.config.default_source))
652+
log.warn(
653+
string.format(
654+
"Invalid default source found in configuration. Using first available source: %s",
655+
M.config.default_source
656+
)
657+
)
651658
end
652659

653660
if not M.config.enable_git_status then

lua/neo-tree/sources/buffers/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ local git = require("neo-tree.git")
1111

1212
local M = {
1313
name = "buffers",
14-
display_name = " 󰈚 Buffers "
14+
display_name = " 󰈚 Buffers ",
1515
}
1616

1717
local wrap = function(func)

lua/neo-tree/sources/common/components.lua

+7-7
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ local truncate_string = function(str, max_length)
464464
return str:sub(1, max_length - 1) .. ""
465465
end
466466

467-
local get_header = function (state, label, size)
467+
local get_header = function(state, label, size)
468468
if state.sort and state.sort.label == label then
469469
local icon = state.sort.direction == 1 and "" or ""
470470
size = size - 2
@@ -478,7 +478,7 @@ M.file_size = function(config, node, state)
478478
if node:get_depth() == 1 then
479479
return {
480480
text = get_header(state, "Size", config.width),
481-
highlight = highlights.FILE_STATS_HEADER
481+
highlight = highlights.FILE_STATS_HEADER,
482482
}
483483
end
484484

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

497497
return {
498498
text = vim.fn.printf("%" .. config.width .. "s ", truncate_string(text, config.width)),
499-
highlight = config.highlight or highlights.FILE_STATS
499+
highlight = config.highlight or highlights.FILE_STATS,
500500
}
501501
end
502502

@@ -511,7 +511,7 @@ local file_time = function(config, node, state, stat_field)
511511
end
512512
return {
513513
text = get_header(state, label, config.width),
514-
highlight = highlights.FILE_STATS_HEADER
514+
highlight = highlights.FILE_STATS_HEADER,
515515
}
516516
end
517517

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

523523
return {
524524
text = vim.fn.printf("%" .. config.width .. "s ", truncate_string(display, config.width)),
525-
highlight = config.highlight or highlights.FILE_STATS
525+
highlight = config.highlight or highlights.FILE_STATS,
526526
}
527527
end
528528

@@ -551,13 +551,13 @@ M.type = function(config, node, state)
551551
if node:get_depth() == 1 then
552552
return {
553553
text = get_header(state, "Type", config.width),
554-
highlight = highlights.FILE_STATS_HEADER
554+
highlight = highlights.FILE_STATS_HEADER,
555555
}
556556
end
557557

558558
return {
559559
text = vim.fn.printf("%" .. config.width .. "s ", truncate_string(text, config.width)),
560-
highlight = highlights.FILE_STATS
560+
highlight = highlights.FILE_STATS,
561561
}
562562
end
563563

lua/neo-tree/sources/common/container.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ local render_content = function(config, node, state, context)
8585
vim.list_extend(zindex_rendered[align], rendered_item)
8686
rendered_width = rendered_width + calc_rendered_width(rendered_item)
8787
end
88-
::continue::
88+
::continue::
8989
end
9090

9191
max_width = math.max(max_width, rendered_width)

lua/neo-tree/sources/common/filters/filter_fzy.lua

+10-8
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,24 @@ function M.has_match(needle, haystack, case_sensitive)
6060
end
6161

6262
local function is_lower(c)
63-
return c:match('%l')
63+
return c:match("%l")
6464
end
6565

6666
local function is_upper(c)
67-
return c:match('%u')
67+
return c:match("%u")
6868
end
6969

7070
local function precompute_bonus(haystack)
7171
local match_bonus = {}
7272

73-
local last_char = '/'
73+
local last_char = "/"
7474
for i = 1, string.len(haystack) do
7575
local this_char = haystack:sub(i, i)
76-
if last_char == '/' or last_char == '\\' then
76+
if last_char == "/" or last_char == "\\" then
7777
match_bonus[i] = SCORE_MATCH_SLASH
78-
elseif last_char == '-' or last_char == '_' or last_char == ' ' then
78+
elseif last_char == "-" or last_char == "_" or last_char == " " then
7979
match_bonus[i] = SCORE_MATCH_WORD
80-
elseif last_char == '.' then
80+
elseif last_char == "." then
8181
match_bonus[i] = SCORE_MATCH_DOT
8282
elseif is_lower(last_char) and is_upper(this_char) then
8383
match_bonus[i] = SCORE_MATCH_CAPITAL
@@ -200,7 +200,9 @@ function M.score_and_positions(needle, haystack, case_sensitive)
200200
for i = n, 1, -1 do
201201
while j >= 1 do
202202
if D[i][j] ~= SCORE_MIN and (match_required or D[i][j] == T[i][j]) then
203-
match_required = (i ~= 1) and (j ~= 1) and (T[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE)
203+
match_required = (i ~= 1)
204+
and (j ~= 1)
205+
and (T[i][j] == D[i - 1][j - 1] + SCORE_MATCH_CONSECUTIVE)
204206
positions[i] = j
205207
j = j - 1
206208
break
@@ -240,7 +242,7 @@ function M.get_score_ceiling()
240242
end
241243

242244
function M.get_implementation_name()
243-
return 'lua'
245+
return "lua"
244246
end
245247

246248
return M

lua/neo-tree/sources/common/hijack_cursor.lua

+26-26
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@ local manager = require("neo-tree.sources.manager")
55
local M = {}
66

77
local hijack_cursor_handler = function()
8-
if vim.o.filetype ~= "neo-tree" then
9-
return
10-
end
11-
local success, source = pcall(vim.api.nvim_buf_get_var, 0, "neo_tree_source")
12-
if not success then
13-
log.debug("Cursor hijack failure: " .. vim.inspect(source))
14-
return
15-
end
16-
local winid = nil
17-
local _, position = pcall(vim.api.nvim_buf_get_var, 0, "neo_tree_position")
18-
if position == "current" then
19-
winid = vim.api.nvim_get_current_win()
20-
end
8+
if vim.o.filetype ~= "neo-tree" then
9+
return
10+
end
11+
local success, source = pcall(vim.api.nvim_buf_get_var, 0, "neo_tree_source")
12+
if not success then
13+
log.debug("Cursor hijack failure: " .. vim.inspect(source))
14+
return
15+
end
16+
local winid = nil
17+
local _, position = pcall(vim.api.nvim_buf_get_var, 0, "neo_tree_position")
18+
if position == "current" then
19+
winid = vim.api.nvim_get_current_win()
20+
end
2121

22-
local state = manager.get_state(source, nil, winid)
23-
if state == nil or not state.tree then
24-
return
25-
end
26-
local node = state.tree:get_node()
27-
log.debug("Cursor moved in tree window, hijacking cursor position")
28-
local cursor = vim.api.nvim_win_get_cursor(0)
29-
local row = cursor[1]
30-
local current_line = vim.api.nvim_get_current_line()
31-
local startIndex, _ = string.find(current_line, node.name, nil, true)
32-
if startIndex then
33-
vim.api.nvim_win_set_cursor(0, { row, startIndex - 1 })
34-
end
22+
local state = manager.get_state(source, nil, winid)
23+
if state == nil or not state.tree then
24+
return
25+
end
26+
local node = state.tree:get_node()
27+
log.debug("Cursor moved in tree window, hijacking cursor position")
28+
local cursor = vim.api.nvim_win_get_cursor(0)
29+
local row = cursor[1]
30+
local current_line = vim.api.nvim_get_current_line()
31+
local startIndex, _ = string.find(current_line, node.name, nil, true)
32+
if startIndex then
33+
vim.api.nvim_win_set_cursor(0, { row, startIndex - 1 })
34+
end
3535
end
3636

3737
--Enables cursor hijack behavior for all sources

lua/neo-tree/sources/common/node_expander.lua

+31-31
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,49 @@ local log = require("neo-tree.log")
33
local M = {}
44

55
--- Recursively expand all loaded nodes under the given node
6-
--- returns table with all discovered nodes that need to be loaded
6+
--- returns table with all discovered nodes that need to be loaded
77
---@param node table a node to expand
88
---@param state table current state of the source
99
---@return table discovered nodes that need to be loaded
1010
local function expand_loaded(node, state, prefetcher)
11-
local function rec(current_node, to_load)
12-
if prefetcher.should_prefetch(current_node) then
13-
log.trace("Node " .. current_node:get_id() .. "not loaded, saving for later")
14-
table.insert(to_load, current_node)
15-
else
16-
if not current_node:is_expanded() then
17-
current_node:expand()
18-
state.explicitly_opened_directories[current_node:get_id()] = true
19-
end
20-
local children = state.tree:get_nodes(current_node:get_id())
21-
log.debug("Expanding childrens of " .. current_node:get_id())
22-
for _, child in ipairs(children) do
23-
if child.type == "directory" then
24-
rec(child, to_load)
25-
else
26-
log.trace("Child: " .. child.name .. " is not a directory, skipping")
27-
end
11+
local function rec(current_node, to_load)
12+
if prefetcher.should_prefetch(current_node) then
13+
log.trace("Node " .. current_node:get_id() .. "not loaded, saving for later")
14+
table.insert(to_load, current_node)
15+
else
16+
if not current_node:is_expanded() then
17+
current_node:expand()
18+
state.explicitly_opened_directories[current_node:get_id()] = true
19+
end
20+
local children = state.tree:get_nodes(current_node:get_id())
21+
log.debug("Expanding childrens of " .. current_node:get_id())
22+
for _, child in ipairs(children) do
23+
if child.type == "directory" then
24+
rec(child, to_load)
25+
else
26+
log.trace("Child: " .. child.name .. " is not a directory, skipping")
2827
end
2928
end
3029
end
30+
end
3131

32-
local to_load = {}
33-
rec(node, to_load)
34-
return to_load
32+
local to_load = {}
33+
rec(node, to_load)
34+
return to_load
3535
end
3636

3737
--- Recursively expands all nodes under the given node collecting all unloaded nodes
38-
--- Then run prefetcher on all unloaded nodes. Finally, expand loded nodes.
38+
--- Then run prefetcher on all unloaded nodes. Finally, expand loded nodes.
3939
--- async method
4040
---@param node table a node to expand
4141
---@param state table current state of the source
4242
local function expand_and_load(node, state, prefetcher)
43-
local to_load = expand_loaded(node, state, prefetcher)
44-
for _, _node in ipairs(to_load) do
45-
prefetcher.prefetch(state, _node)
46-
-- no need to handle results as prefetch is recursive
47-
expand_loaded(_node, state, prefetcher)
48-
end
43+
local to_load = expand_loaded(node, state, prefetcher)
44+
for _, _node in ipairs(to_load) do
45+
prefetcher.prefetch(state, _node)
46+
-- no need to handle results as prefetch is recursive
47+
expand_loaded(_node, state, prefetcher)
48+
end
4949
end
5050

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

7373
M.default_prefetcher = {
74-
prefetch = function (state, node)
74+
prefetch = function(state, node)
7575
log.debug("Default expander prefetch does nothing")
7676
end,
77-
should_prefetch = function (node)
77+
should_prefetch = function(node)
7878
return false
79-
end
79+
end,
8080
}
8181

8282
return M

0 commit comments

Comments
 (0)