Created
July 13, 2025 09:27
-
-
Save w1redch4d/bb6b1b435d6ecbd816b3e02c2f012cae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
local pickers = require("telescope.pickers") | |
local finders = require("telescope.finders") | |
local conf = require("telescope.config").values | |
local actions = require("telescope.actions") | |
local action_state = require("telescope.actions.state") | |
local Job = require("plenary.job") | |
local M = {} | |
M.search = function(opts) | |
opts = opts or {} | |
local query = opts.query or vim.fn.input("weggli query > ") | |
local path = opts.path or "." | |
Job:new({ | |
command = "weggli", | |
args = { query, path }, | |
on_exit = function(j, return_val) | |
if return_val ~= 0 then | |
vim.schedule(function() | |
vim.notify("weggli returned an error", vim.log.levels.ERROR) | |
end) | |
return | |
end | |
local results = j:result() | |
vim.schedule(function() | |
pickers.new(opts, { | |
prompt_title = "Weggli Search", | |
finder = finders.new_table { | |
results = results, | |
entry_maker = function(entry) | |
local filename, lnum = string.match(entry, "^(.-):(%d+)$") | |
return { | |
value = entry, | |
display = filename, -- only show filename in picker | |
ordinal = filename, | |
filename = filename, | |
lnum = tonumber(lnum), | |
} | |
end, | |
}, | |
previewer = conf.grep_previewer(opts), -- show preview on the right | |
sorter = conf.generic_sorter(opts), | |
attach_mappings = function(_, _) | |
actions.select_default:replace(function(prompt_bufnr) | |
actions.close(prompt_bufnr) | |
local selection = action_state.get_selected_entry() | |
if selection and selection.filename and selection.lnum then | |
vim.cmd(string.format("e +%d %s", selection.lnum, selection.filename)) | |
else | |
vim.notify("Could not parse file and line number", vim.log.levels.WARN) | |
end | |
end) | |
return true | |
end, | |
}):find() | |
end) | |
end, | |
}):start() | |
end | |
return require("telescope").register_extension({ | |
exports = { | |
weggli = M.search, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment