Skip to content

Commit

Permalink
feat: implement opts.library.blacklist (folke#148)
Browse files Browse the repository at this point in the history
This PR implements folke#148 by adding a new option (`opts.library.blacklist`) which is a string[] that consists
of plugin names (just as `opts.library.plugins`) which will not be included in the final path.

Note: This overrides `opts.library.plugins` in that, if a plugin is included in the blacklist, it *will not*
be included, even if included in the `plugins` list.
  • Loading branch information
aarondill committed Sep 5, 2023
1 parent dcd3465 commit 9c98ec9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Plug 'folke/neodev.nvim'
plugins = true, -- installed opt or start plugins in packpath
-- you can also specify the list of plugins to make available as a workspace library
-- plugins = { "nvim-treesitter", "plenary.nvim", "telescope.nvim" },
blacklist = {}, -- opposite of plugins list, neodev will not make these available as a workspace library
-- blacklist = { "nvim-treesitter", "plenary.nvim", "telescope.nvim" },
},
setup_jsonls = true, -- configures jsonls to provide completion for project specific .luarc.json files
-- for your Neovim config directory, the config.library settings will be used as is
Expand Down
3 changes: 3 additions & 0 deletions lua/neodev/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ M.defaults = {
plugins = true, -- installed opt or start plugins in packpath
-- you can also specify the list of plugins to make available as a workspace library
-- plugins = { "nvim-treesitter", "plenary.nvim", "telescope.nvim" },
---@type string[]
blacklist = {}, -- opposite of plugins list, neodev will not make these available as a workspace library
-- blacklist = { "nvim-treesitter", "plenary.nvim", "telescope.nvim" },
},
setup_jsonls = true, -- configures jsonls to provide completion for .luarc.json files
-- for your neovim config directory, the config.library settings will be used as is
Expand Down
18 changes: 12 additions & 6 deletions lua/neodev/luals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ function M.library(opts)
table.insert(ret, config.types())
end

local function add(lib, filter)
local function add(lib, filter, blacklist)
---@diagnostic disable-next-line: param-type-mismatch
for _, p in ipairs(vim.fn.expand(lib .. "/lua", false, true)) do
local plugin_name = vim.fn.fnamemodify(p, ":h:t")
p = vim.loop.fs_realpath(p)
if p and (not filter or filter[plugin_name]) then
if p and (not filter or filter[plugin_name]) and (not blacklist or not blacklist[plugin_name]) then
if config.options.pathStrict then
table.insert(ret, p)
else
Expand All @@ -32,21 +32,27 @@ function M.library(opts)

if opts.library.plugins then
---@type table<string, boolean>
local filter
local filter, blacklist
if type(opts.library.plugins) == "table" then
filter = {}
for _, p in pairs(opts.library.plugins) do
filter[p] = true
end
end
if type(opts.library.blacklist) == "table" then
blacklist = {}
for _, p in pairs(opts.library.blacklist) do
blacklist[p] = true
end
end
for _, site in pairs(vim.split(vim.o.packpath, ",")) do
add(site .. "/pack/*/opt/*", filter)
add(site .. "/pack/*/start/*", filter)
add(site .. "/pack/*/opt/*", filter, blacklist)
add(site .. "/pack/*/start/*", filter, blacklist)
end
-- add support for lazy.nvim
if package.loaded["lazy"] then
for _, plugin in ipairs(require("lazy").plugins()) do
add(plugin.dir, filter)
add(plugin.dir, filter, blacklist)
end
end
end
Expand Down

0 comments on commit 9c98ec9

Please sign in to comment.