-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not allow 3 or more specs for the same plugin
Workaround for lazy.nvim but folke/lazy.nvim#1328
- Loading branch information
Showing
12 changed files
with
72 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
local M = { | ||
_spec_loaded = {}, | ||
} | ||
|
||
|
||
-- Fill second apperance of plugin spec. | ||
-- First apperance is in the "installed.lua" file | ||
-- Second apperance may be in separate file dedicated for each plugin. | ||
-- It is filled with keys from "config.keymaps", changed default for "optional" | ||
function M.spec(plugins) | ||
local plugin_keymaps = require("config.keymaps").plugins | ||
if type(plugins[1]) == "string" then | ||
plugins = { plugins } | ||
end | ||
for _, plugin in pairs(plugins) do | ||
local full_name = plugin[1] | ||
local name_parts = vim.split(full_name, "/") | ||
local name = name_parts[#name_parts] | ||
local keys = plugin_keymaps[full_name] or plugin_keymaps[name] | ||
if keys then | ||
plugin.keys = require("core.tbl").array_append(plugin.keys or {}, keys:to_lazy()) | ||
end | ||
if plugin.optional == nil then | ||
plugin.optional = true | ||
end | ||
M._spec_loaded[name] = true | ||
end | ||
return plugins | ||
end | ||
|
||
-- If plugin spec has no second apperance, we need to load it's keymaps as new spec | ||
function M.load_missing_keymaps() | ||
local spec = {} | ||
for name, val in pairs(require("config.keymaps").plugins) do | ||
if not M._spec_loaded[name] then | ||
table.insert(spec, {name, optional = true, keys = val:to_lazy()}) | ||
end | ||
end | ||
return spec | ||
end | ||
|
||
return M | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,2 @@ | ||
-- This file is loaded by lazy.nvim. | ||
-- It extracts keymaps for plugins from "config.keymaps" and converts it to LazyKeySpec format | ||
local spec = {} | ||
|
||
for name, val in pairs(require("config.keymaps").plugins) do | ||
table.insert(spec, {name, keys = val:to_lazy()}) | ||
end | ||
return spec | ||
return require("core.plugin_spec").load_missing_keymaps() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,7 +215,7 @@ function lsp.config(_, opts) | |
end | ||
|
||
|
||
return { | ||
return require("core.plugin_spec").spec({ | ||
clangd, | ||
lsp, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters