Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions lua/peekstack/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lua/peekstack/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 25 additions & 2 deletions tests/commands_spec.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)