diff --git a/lua/peekstack/commands.lua b/lua/peekstack/commands.lua index 9720369..af0902e 100644 --- a/lua/peekstack/commands.lua +++ b/lua/peekstack/commands.lua @@ -177,21 +177,7 @@ function M.setup() end, { nargs = "?", complete = function() - return { - "lsp.definition", - "lsp.implementation", - "lsp.references", - "lsp.type_definition", - "lsp.declaration", - "lsp.symbols_document", - "diagnostics.under_cursor", - "diagnostics.in_buffer", - "file.under_cursor", - "grep.search", - "marks.buffer", - "marks.global", - "marks.all", - } + return require("peekstack").list_providers() end, }) end diff --git a/lua/peekstack/init.lua b/lua/peekstack/init.lua index f52bb52..3bef8ea 100644 --- a/lua/peekstack/init.lua +++ b/lua/peekstack/init.lua @@ -43,6 +43,13 @@ function M.register_provider(name, fn) providers[name] = fn end +---@return string[] +function M.list_providers() + local names = vim.tbl_keys(providers) + table.sort(names) + return names +end + ---@param name string ---@param fn PeekstackPicker function M.register_picker(name, fn) diff --git a/tests/commands_spec.lua b/tests/commands_spec.lua index e41cbaf..c6e37e7 100644 --- a/tests/commands_spec.lua +++ b/tests/commands_spec.lua @@ -1,6 +1,7 @@ describe("peekstack.commands", function() local commands = require("peekstack.commands") local config = require("peekstack.config") + local peekstack = require("peekstack") local persist = require("peekstack.persist") local original_list_sessions = nil local original_select = nil @@ -135,15 +136,37 @@ describe("peekstack.commands", function() assert.equals("alpha: 0 items (updated: formatted-time)", prompts[2]) end) - it("includes extended providers in quick peek completion", function() - commands.setup() + it("uses registered providers for quick peek completion", function() + peekstack.setup({}) local names = vim.fn.getcompletion("PeekstackQuickPeek ", "cmdline") assert.is_true(vim.list_contains(names, "lsp.declaration")) assert.is_true(vim.list_contains(names, "lsp.symbols_document")) assert.is_true(vim.list_contains(names, "diagnostics.in_buffer")) + assert.is_false(vim.list_contains(names, "marks.buffer")) + assert.is_false(vim.list_contains(names, "marks.global")) + assert.is_false(vim.list_contains(names, "marks.all")) + end) + + it("reflects provider registration changes in quick peek completion", function() + peekstack.setup({ + providers = { + marks = { + enable = true, + }, + }, + }) + + local names = vim.fn.getcompletion("PeekstackQuickPeek ", "cmdline") assert.is_true(vim.list_contains(names, "marks.buffer")) assert.is_true(vim.list_contains(names, "marks.global")) assert.is_true(vim.list_contains(names, "marks.all")) + + peekstack.register_provider("custom.test", function(_ctx, cb) + cb({}) + end) + + names = vim.fn.getcompletion("PeekstackQuickPeek ", "cmdline") + assert.is_true(vim.list_contains(names, "custom.test")) end) end)