Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
uses: JohnnyMorganz/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v0.13.1
args: --color always --check lua/

plenary-tests:
Expand Down
131 changes: 66 additions & 65 deletions lua/neo-tree/command/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,76 @@ local M = {
REF = "<REF>",
}

-- For lists, the first value is the default value.
local arguments = {
action = {
type = M.LIST,
values = {
"close",
"focus",
"show",
M.setup = function(all_source_names)
local source_names = utils.table_copy(all_source_names)
table.insert(source_names, "migrations")

-- For lists, the first value is the default value.
local arguments = {
action = {
type = M.LIST,
values = {
"close",
"focus",
"show",
},
},
},
position = {
type = M.LIST,
values = {
"left",
"right",
--"top", --technically valid, but why show it if no one will use it?
--"bottom", --technically valid, but why show it if no one will use it?
"float",
"current",
position = {
type = M.LIST,
values = {
"left",
"right",
--"top", --technically valid, but why show it if no one will use it?
--"bottom", --technically valid, but why show it if no one will use it?
"float",
"current",
},
},
},
source = {
type = M.LIST,
values = {
"filesystem",
"buffers",
"git_status",
"migrations",
source = {
type = M.LIST,
values = source_names,
},
},
dir = { type = M.PATH, stat_type = "directory" },
reveal_file = { type = M.PATH, stat_type = "file" },
git_base = { type = M.REF },
toggle = { type = M.FLAG },
reveal = { type = M.FLAG },
reveal_force_cwd = { type = M.FLAG },
}
dir = { type = M.PATH, stat_type = "directory" },
reveal_file = { type = M.PATH, stat_type = "file" },
git_base = { type = M.REF },
toggle = { type = M.FLAG },
reveal = { type = M.FLAG },
reveal_force_cwd = { type = M.FLAG },
}

local arg_type_lookup = {}
local list_args = {}
local path_args = {}
local ref_args = {}
local flag_args = {}
local reverse_lookup = {}
for name, def in pairs(arguments) do
arg_type_lookup[name] = def.type
if def.type == M.LIST then
table.insert(list_args, name)
for _, vv in ipairs(def.values) do
reverse_lookup[tostring(vv)] = name
local arg_type_lookup = {}
local list_args = {}
local path_args = {}
local ref_args = {}
local flag_args = {}
local reverse_lookup = {}
for name, def in pairs(arguments) do
arg_type_lookup[name] = def.type
if def.type == M.LIST then
table.insert(list_args, name)
for _, vv in ipairs(def.values) do
reverse_lookup[tostring(vv)] = name
end
elseif def.type == M.PATH then
table.insert(path_args, name)
elseif def.type == M.FLAG then
table.insert(flag_args, name)
reverse_lookup[name] = M.FLAG
elseif def.type == M.REF then
table.insert(ref_args, name)
else
error("Unknown type: " .. def.type)
end
elseif def.type == M.PATH then
table.insert(path_args, name)
elseif def.type == M.FLAG then
table.insert(flag_args, name)
reverse_lookup[name] = M.FLAG
elseif def.type == M.REF then
table.insert(ref_args, name)
else
error("Unknown type: " .. def.type)
end
end

M.arguments = arguments
M.list_args = list_args
M.path_args = path_args
M.ref_args = ref_args
M.flag_args = flag_args
M.arg_type_lookup = arg_type_lookup
M.reverse_lookup = reverse_lookup
M.arguments = arguments
M.list_args = list_args
M.path_args = path_args
M.ref_args = ref_args
M.flag_args = flag_args
M.arg_type_lookup = arg_type_lookup
M.reverse_lookup = reverse_lookup
end

M.resolve_path = function(path, validate_type)
local expanded = vim.fn.expand(path)
Expand All @@ -101,7 +101,7 @@ local parse_arg = function(result, arg)
if eq then
local key = arg:sub(1, eq - 1)
local value = arg:sub(eq + 1)
local def = arguments[key]
local def = M.arguments[key]
if not def.type then
error("Invalid argument: " .. arg)
end
Expand All @@ -126,7 +126,7 @@ local parse_arg = function(result, arg)
end
else
local value = arg
local key = reverse_lookup[value]
local key = M.reverse_lookup[value]
if key == nil then
-- maybe it's a git ref
if M.verify_git_ref(value) then
Expand Down Expand Up @@ -155,6 +155,7 @@ local parse_arg = function(result, arg)
end

M.parse = function(args, strict_checking)
require("neo-tree").ensure_config()
local result = {}

if type(args) == "string" then
Expand Down
15 changes: 12 additions & 3 deletions lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
local config = {
-- If a user has a sources list it will replace this one.
-- Only sources listed here will be loaded.
-- You can also add an external source by adding it's name to this list.
-- The name used here must be the same name you would use in a require() call.
sources = {
"filesystem",
"buffers",
"git_status",
},
close_if_last_window = false, -- Close Neo-tree if it is the last window left in the tab
-- popup_border_style is for input and confirmation dialogs.
-- Configurtaion of floating window is done in the individual source sections.
Expand Down Expand Up @@ -106,7 +115,7 @@ local config = {
highlight = "NeoTreeFileIcon"
},
modified = {
symbol = "[+]",
symbol = "[+] ",
highlight = "NeoTreeModified",
},
name = {
Expand Down Expand Up @@ -139,7 +148,7 @@ local config = {
{
"container",
width = "100%",
right_padding = 1,
right_padding = 0,
--max_width = 60,
content = {
{ "name", zindex = 10 },
Expand All @@ -159,7 +168,7 @@ local config = {
{
"container",
width = "100%",
right_padding = 1,
right_padding = 0,
--max_width = 60,
content = {
{
Expand Down
10 changes: 8 additions & 2 deletions lua/neo-tree/git/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,14 @@ M.status_async = function(path, base, opts)
end,
})

local showUntracked =
vim.fn.systemlist({ "git", "-C", git_root, "config", "--get", "status.showUntrackedFiles" })
local showUntracked = vim.fn.systemlist({
"git",
"-C",
git_root,
"config",
"--get",
"status.showUntrackedFiles",
})
log.debug("git status.showUntrackedFiles =", showUntracked[1])
if showUntracked[1] == "no" then
unstaged_job:after(parse_lines)
Expand Down
7 changes: 5 additions & 2 deletions lua/neo-tree/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ end
log.new = function(config, standalone)
config = vim.tbl_deep_extend("force", default_config, config)

local outfile =
string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "data" }), config.plugin)
local outfile = string.format(
"%s/%s.log",
vim.api.nvim_call_function("stdpath", { "data" }),
config.plugin
)

local obj
if standalone then
Expand Down
15 changes: 11 additions & 4 deletions lua/neo-tree/setup/deprecations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ M.migrate = function(config)
end
utils.set_value(config, new, exising)
config[old] = nil
migrations[#migrations + 1] =
string.format("The `%s` option has been deprecated, please use `%s` instead.", old, new)
migrations[#migrations + 1] = string.format(
"The `%s` option has been deprecated, please use `%s` instead.",
old,
new
)
end
end

Expand All @@ -58,8 +61,12 @@ M.migrate = function(config)
local value = utils.get_value(config, key)
if value == old_value then
utils.set_value(config, key, new_value)
migrations[#migrations + 1] =
string.format("The `%s=%s` option has been renamed to `%s`.", key, old_value, new_value)
migrations[#migrations + 1] = string.format(
"The `%s=%s` option has been renamed to `%s`.",
key,
old_value,
new_value
)
end
end

Expand Down
56 changes: 40 additions & 16 deletions lua/neo-tree/setup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ local highlights = require("neo-tree.ui.highlights")
local manager = require("neo-tree.sources.manager")
local netrw = require("neo-tree.setup.netrw")

-- If you add a new source, you need to add it to the sources table.
-- Each source should have a defaults module that contains the default values
-- for the source config, and a setup function that takes that config.
local sources = {
"filesystem",
"buffers",
"git_status",
"example",
}

local M = {}

local normalize_mappings = function(config)
Expand Down Expand Up @@ -410,16 +400,49 @@ M.merge_config = function(user_config, is_auto_config)
normalize_mappings(default_config)
normalize_mappings(user_config)
merge_renderers(default_config, nil, user_config)
for _, source_name in ipairs(sources) do

-- used to either limit the sources that or loaded, or add extra external sources
local all_sources = {}
local all_source_names = {}
for _, source in ipairs(user_config.sources or default_config.sources) do
local parts = utils.split(source, ".")
local name = parts[#parts]
if #parts > 1 then
-- fully qualified module name
all_sources[name] = source
else
-- might be a module name in the internal namespace
local is_internal_ns, _ = pcall(require, "neo-tree.sources." .. source)
if is_internal_ns then
all_sources[name] = "neo-tree.sources." .. name
else
-- could also be a root level module name
local exists, module = pcall(require, source)
if exists then
all_sources[name] = module.name or source
else
log.error("Source module not found", source)
name = nil
end
end
end
if name then
table.insert(all_source_names, name)
end
end
log.debug("Sources to load: ", vim.inspect(all_sources))
require("neo-tree.command.parser").setup(all_source_names)

for source_name, mod_root in pairs(all_sources) do
local module = require(mod_root)
default_config[source_name] = default_config[source_name]
or {
renderers = {},
components = {},
}
local source_default_config = default_config[source_name]
local mod_root = "neo-tree.sources." .. source_name
source_default_config.components = require(mod_root .. ".components")
source_default_config.commands = require(mod_root .. ".commands")
source_default_config.components = module.components or require(mod_root .. ".components")
source_default_config.commands = module.commands or require(mod_root .. ".commands")
source_default_config.name = source_name

if user_config.use_default_mappings == false then
Expand Down Expand Up @@ -465,11 +488,12 @@ M.merge_config = function(user_config, is_auto_config)

file_nesting.setup(M.config.nesting_rules)

for _, source_name in ipairs(sources) do
for source_name, mod_root in pairs(all_sources) do
for name, rndr in pairs(M.config[source_name].renderers) do
M.config[source_name].renderers[name] = merge_global_components_config(rndr, M.config)
end
manager.setup(source_name, M.config[source_name], M.config)
local module = require(mod_root)
manager.setup(source_name, M.config[source_name], M.config, module)
manager.redraw(source_name)
end

Expand Down
3 changes: 2 additions & 1 deletion lua/neo-tree/sources/common/components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ end

M.modified = function(config, node, state)
local modified_buffers = state.modified_buffers or {}

if modified_buffers[node.path] then
return {
text = (config.symbol or "[+] "),
text = (make_two_char(config.symbol) or "[+] "),
highlight = config.highlight or highlights.MODIFIED,
}
else
Expand Down
21 changes: 0 additions & 21 deletions lua/neo-tree/sources/example/commands.lua

This file was deleted.

Loading