Skip to content

Commit

Permalink
cleanup!: Remove ability to use g:aerial variables to configure
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Aug 4, 2022
1 parent 86b8341 commit a1c0fa1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 137 deletions.
76 changes: 0 additions & 76 deletions lua/aerial/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -409,84 +409,8 @@ M.setup = function(opts)
})
end
end

-- Clear the metatable that looks up the vim.g.aerial values
setmetatable(M, {})
end

local bool_opts = {
close_on_select = true,
default_bindings = true,
diagnostics_trigger_update = true,
highlight_mode = true,
highlight_on_jump = true,
link_folds_to_tree = true,
link_tree_to_folds = true,
manage_folds = true,
nerd_font = true,
open_automatic = true,
placement_editor_edge = true,
post_jump_cmd = true,
update_when_errors = true,
}

local function calculate_opts()
local opts
local found_var = false
if vim.g.aerial then
opts = vim.g.aerial
found_var = true
else
opts = vim.deepcopy(default_options)
end

local function walk(prefix, obj)
for k, v in pairs(obj) do
local found, var = pcall(vim.api.nvim_get_var, prefix .. k)
-- This is for backwards compatibility with lsp options that used to be in the
-- global namespace
if not found and prefix == "aerial_lsp_" then
found, var = pcall(vim.api.nvim_get_var, "aerial_" .. k)
end
if found then
found_var = true
-- Convert 0/1 to true/false for backwards compatibility
if bool_opts[k] and type(var) ~= "boolean" then
vim.notify(
string.format(
"Deprecated: aerial expects a boolean for option '%s'",
k,
vim.log.levels.WARN
)
)
var = var ~= 0
end
obj[k] = var
elseif type(v) == "table" and not vim.tbl_islist(v) then
walk(prefix .. k .. "_", v)
end
end
end
walk("aerial_", opts)

if found_var then
vim.notify(
"Deprecated: aerial should no longer be configured with g:aerial, you should use require('aerial').setup(). See :help aerial for more details",
vim.log.levels.WARN
)
end
return opts
end

-- For backwards compatibility: if we search for config values and we haven't
-- yet called setup(), call setup with the config values pulled from global vars
setmetatable(M, {
__index = function(t, key)
M.setup(calculate_opts())
return rawget(M, key)
end,
})

local function get_icon(kind, filetypes)
for _, ft in ipairs(filetypes) do
local icon_map = M.icons[ft]
Expand Down
76 changes: 15 additions & 61 deletions tests/config_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,42 @@ end

describe("config", function()
before_each(function()
pcall(vim.api.nvim_del_var, "aerial")
reset()
end)

it("falls back to default options", function()
config.setup()
assert.equals(config.close_behavior, "auto")
end)

it("reads options from g:aerial dict var", function()
vim.g.aerial = {
close_behavior = "persist",
}
assert.equals(config.close_behavior, "persist")
end)

it("reads options from g:aerial_<name> vars", function()
vim.g.aerial_close_behavior = "persist"
assert.equals(config.close_behavior, "persist")
vim.api.nvim_del_var("aerial_close_behavior")
end)

it("merges nested options with g:aerial dict", function()
vim.g.aerial = {
float = {
border = "single",
},
}
assert.equals(config.float.border, "single")
assert.equals(config.float.max_height, 0.9)
end)

it("merges nested options with g:aerial_<name> vars", function()
vim.g.aerial_float_border = "single"
assert.equals(config.float.border, "single")
vim.api.nvim_del_var("aerial_float_border")
end)

-- Filetype maps
it("reads the default value for filetype map option", function()
config.setup()
assert.equals(config.open_automatic(0), false)
end)
it("reads the filetype default value for filetype map option", function()
vim.g.aerial = {
config.setup({
open_automatic = {
["_"] = true,
},
}
})
assert.equals(config.open_automatic(0), true)
end)
it("reads the filetype value for filetype map option", function()
vim.g.aerial = {
config.setup({
open_automatic = {
fake_ft = true,
},
}
})
vim.api.nvim_buf_set_option(0, "filetype", "fake_ft")
assert.equals(config.open_automatic(0), true)
end)
it("reads the filetype value when using a compound filetype", function()
vim.g.aerial = {
config.setup({
open_automatic = {
fake_ft = true,
},
}
})
vim.api.nvim_buf_set_option(0, "filetype", "fake_ft.extension")
assert.equals(config.open_automatic(0), true)
end)
Expand All @@ -86,26 +58,26 @@ describe("config", function()

-- Filter kind
it("reads the filter_kind option", function()
vim.g.aerial = {
config.setup({
filter_kind = { "Function" },
}
})
local fk = config.get_filter_kind_map()
assert.equals(nil, fk.Class)
assert.equals(true, fk.Function)
end)
it("reads the filter_kind option from filetype map", function()
vim.g.aerial = {
config.setup({
filter_kind = { foo = { "Function" } },
}
})
vim.api.nvim_buf_set_option(0, "filetype", "foo")
local fk = config.get_filter_kind_map()
assert.equals(nil, fk.Class)
assert.equals(true, fk.Function)
end)
it("recognizes when filter_kind is false", function()
vim.g.aerial = {
filter_kind = { foo = 0 },
}
config.setup({
filter_kind = { foo = false },
})
vim.api.nvim_buf_set_option(0, "filetype", "foo")
local fk = config.get_filter_kind_map()
assert.equals(true, fk.Class)
Expand Down Expand Up @@ -166,22 +138,4 @@ describe("config", function()
vim.api.nvim_buf_set_option(0, "filetype", "foo")
assert.equals("a", config.get_icon(0, "Function", false))
end)

-- This is for backwards compatibility with lsp options that used to be in the
-- global namespace
it("reads lsp_ options from g:aerial dict var", function()
assert.equals(config.lsp.update_when_errors, true)
vim.g.aerial = {
update_when_errors = false,
}
reset()
assert.equals(config.lsp.update_when_errors, false)
end)
it("reads lsp_ options from g:aerial_<name> vars", function()
assert.equals(config.lsp.update_when_errors, true)
vim.g.aerial_update_when_errors = false
reset()
assert.equals(config.lsp.update_when_errors, false)
vim.api.nvim_del_var("aerial_update_when_errors")
end)
end)

0 comments on commit a1c0fa1

Please sign in to comment.