Skip to content

Commit 7b755df

Browse files
authored
Merge pull request #10 from mhiro2/feat/dynamic-provider-completion
feat(commands): Complete quick peek providers dynamically
2 parents 580692c + 71b0d7a commit 7b755df

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

lua/peekstack/commands.lua

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,7 @@ function M.setup()
177177
end, {
178178
nargs = "?",
179179
complete = function()
180-
return {
181-
"lsp.definition",
182-
"lsp.implementation",
183-
"lsp.references",
184-
"lsp.type_definition",
185-
"lsp.declaration",
186-
"lsp.symbols_document",
187-
"diagnostics.under_cursor",
188-
"diagnostics.in_buffer",
189-
"file.under_cursor",
190-
"grep.search",
191-
"marks.buffer",
192-
"marks.global",
193-
"marks.all",
194-
}
180+
return require("peekstack").list_providers()
195181
end,
196182
})
197183
end

lua/peekstack/init.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ function M.register_provider(name, fn)
4343
providers[name] = fn
4444
end
4545

46+
---@return string[]
47+
function M.list_providers()
48+
local names = vim.tbl_keys(providers)
49+
table.sort(names)
50+
return names
51+
end
52+
4653
---@param name string
4754
---@param fn PeekstackPicker
4855
function M.register_picker(name, fn)

tests/commands_spec.lua

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
describe("peekstack.commands", function()
22
local commands = require("peekstack.commands")
33
local config = require("peekstack.config")
4+
local peekstack = require("peekstack")
45
local persist = require("peekstack.persist")
56
local original_list_sessions = nil
67
local original_select = nil
@@ -135,15 +136,37 @@ describe("peekstack.commands", function()
135136
assert.equals("alpha: 0 items (updated: formatted-time)", prompts[2])
136137
end)
137138

138-
it("includes extended providers in quick peek completion", function()
139-
commands.setup()
139+
it("uses registered providers for quick peek completion", function()
140+
peekstack.setup({})
140141
local names = vim.fn.getcompletion("PeekstackQuickPeek ", "cmdline")
141142

142143
assert.is_true(vim.list_contains(names, "lsp.declaration"))
143144
assert.is_true(vim.list_contains(names, "lsp.symbols_document"))
144145
assert.is_true(vim.list_contains(names, "diagnostics.in_buffer"))
146+
assert.is_false(vim.list_contains(names, "marks.buffer"))
147+
assert.is_false(vim.list_contains(names, "marks.global"))
148+
assert.is_false(vim.list_contains(names, "marks.all"))
149+
end)
150+
151+
it("reflects provider registration changes in quick peek completion", function()
152+
peekstack.setup({
153+
providers = {
154+
marks = {
155+
enable = true,
156+
},
157+
},
158+
})
159+
160+
local names = vim.fn.getcompletion("PeekstackQuickPeek ", "cmdline")
145161
assert.is_true(vim.list_contains(names, "marks.buffer"))
146162
assert.is_true(vim.list_contains(names, "marks.global"))
147163
assert.is_true(vim.list_contains(names, "marks.all"))
164+
165+
peekstack.register_provider("custom.test", function(_ctx, cb)
166+
cb({})
167+
end)
168+
169+
names = vim.fn.getcompletion("PeekstackQuickPeek ", "cmdline")
170+
assert.is_true(vim.list_contains(names, "custom.test"))
148171
end)
149172
end)

0 commit comments

Comments
 (0)