From edb7234f958304d06904f3357953b5ed0edb232f Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Sun, 2 Jun 2024 16:06:26 -0700 Subject: [PATCH] feat: add `Precognition` command --- lua/precognition/init.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lua/precognition/init.lua b/lua/precognition/init.lua index d9cb5f8..b0b9d49 100644 --- a/lua/precognition/init.lua +++ b/lua/precognition/init.lua @@ -314,6 +314,39 @@ local function on_buf_leave(ev) dirty = true end +local function create_command() + local subcommands = { + peek = M.peek, + toggle = M.toggle, + show = M.show, + hide = M.hide, + } + + local function execute(args) + local cmd_args = args.fargs + local subcmd = cmd_args[1] + if not subcmd then + return + end + if subcommands[subcmd] then + subcommands[subcmd]() + else + vim.notify("Invalid subcommand: " .. subcmd, vim.log.levels.ERROR, { + title = "Precognition", + }) + end + end + + local function complete(_line, _len, _arg_lead) + return vim.tbl_keys(subcommands) + end + + vim.api.nvim_create_user_command("Precognition", execute, { + nargs = "*", + complete = complete, + }) +end + --- Show the hints until the next keypress or CursorMoved event function M.peek() display_marks() @@ -395,6 +428,8 @@ function M.setup(opts) local hl_name = "PrecognitionHighlight" vim.api.nvim_set_hl(0, hl_name, config.highlightColor) + create_command() + if config.startVisible then M.show() end