generated from mrcjkb/nvim-lua-nix-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
800 additions
and
102 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
result | ||
.pre-commit-config.yaml | ||
.direnv | ||
.luarc.json |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
local loader = require('lz.n.loader') | ||
|
||
---@class LzCmdHandler: LzHandler | ||
|
||
---@type LzCmdHandler | ||
local M = { | ||
---@type table<string, LzPlugin> | ||
active = {}, | ||
managed = {}, | ||
type = 'cmd', | ||
} | ||
|
||
---@param cmd string | ||
local function load(cmd) | ||
vim.api.nvim_del_user_command(cmd) | ||
loader.load(M.active[cmd]) | ||
end | ||
|
||
---@param cmd string | ||
function M.add(cmd) | ||
vim.api.nvim_create_user_command(cmd, function(event) | ||
---@cast event vim.api.keyset.user_command | ||
local command = { | ||
cmd = cmd, | ||
bang = event.bang or nil, | ||
---@diagnostic disable-next-line: undefined-field | ||
mods = event.smods, | ||
---@diagnostic disable-next-line: undefined-field | ||
args = event.fargs, | ||
count = event.count >= 0 and event.range == 0 and event.count or nil, | ||
} | ||
|
||
if event.range == 1 then | ||
---@diagnostic disable-next-line: undefined-field | ||
command.range = { event.line1 } | ||
elseif event.range == 2 then | ||
---@diagnostic disable-next-line: undefined-field | ||
command.range = { event.line1, event.line2 } | ||
end | ||
|
||
---@type string | ||
local plugins = '`' .. table.concat(vim.tbl_values(M.active[cmd]), ', ') .. '`' | ||
|
||
load(cmd) | ||
|
||
local info = vim.api.nvim_get_commands({})[cmd] or vim.api.nvim_buf_get_commands(0, {})[cmd] | ||
if not info then | ||
vim.schedule(function() | ||
vim.notify('Command `' .. cmd .. '` not found after loading ' .. plugins, vim.log.levels.ERROR) | ||
end) | ||
return | ||
end | ||
|
||
command.nargs = info.nargs | ||
---@diagnostic disable-next-line: undefined-field | ||
if event.args and event.args ~= '' and info.nargs and info.nargs:find('[1?]') then | ||
---@diagnostic disable-next-line: undefined-field | ||
command.args = { event.args } | ||
end | ||
vim.cmd(command) | ||
end, { | ||
bang = true, | ||
range = true, | ||
nargs = '*', | ||
complete = function(_, line) | ||
load(cmd) | ||
return vim.fn.getcompletion(line, 'cmdline') | ||
end, | ||
}) | ||
end | ||
|
||
---@param cmd string | ||
function M.del(cmd) | ||
pcall(vim.api.nvim_del_user_command, cmd) | ||
end | ||
|
||
return M |
Oops, something went wrong.