| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- local pickers = require("telescope.pickers")
- local actions = require("telescope.actions")
- local action_state = require("telescope.actions.state")
- local finders = require("telescope.finders")
- local conf = require("telescope.config").values
- local entry_display = require("telescope.pickers.entry_display")
- -- Utility function: navigate diagnostics
- local diagnostic = function(next, severity)
- local opts = { float = false }
- if severity then opts.severity = { min = severity } end
- if next then
- opts.count = 1
- return vim.diagnostic.jump(opts)
- else
- opts.count = -1
- return vim.diagnostic.jump(opts)
- end
- end
- -- Utility function: navigate git hunks (if gitsigns is installed)
- local githunk
- local gitsigns
- if pcall(require, "gitsigns") then
- gitsigns = require("gitsigns")
- githunk = function(next)
- if (next) then
- gitsigns.next_hunk()
- else
- gitsigns.prev_hunk()
- end
- vim.defer_fn(function()
- vim.schedule(function() gitsigns.preview_hunk_inline() end)
- end, 100)
- end
- else
- githunk = function(_) end
- end
- local targets = {
- {
- "Error", "Any error diagnostic in the current buffer",
- function() diagnostic(true, vim.diagnostic.severity.ERROR) end,
- function() diagnostic(false, vim.diagnostic.severity.ERROR) end
- }, {
- "Warn", "Any warn or error diagnostic in the current buffer",
- function() diagnostic(true, vim.diagnostic.severity.WARN) end,
- function() diagnostic(false, vim.diagnostic.severity.WARN) end
- }, {
- "Info", "Any info, warn, or error diagnostic in the current buffer",
- function() diagnostic(true, vim.diagnostic.severity.INFO) end,
- function() diagnostic(false, vim.diagnostic.severity.INFO) end
- }, {
- "Diagnostic",
- "Any diagnostic in the current buffer, regardless of severity",
- function() diagnostic(true) end, function() diagnostic(false) end
- }, {
- "Search", "The last search made with /",
- function()
- vim.fn.search(vim.fn.getreginfo("/")["regcontents"][1])
- end,
- function()
- vim.fn.search(vim.fn.getreginfo("/")["regcontents"][1], "b")
- end
- }, {
- "Git", "Next diff hunk in current buffer", function()
- githunk(true)
- end, function() githunk(false) end
- }
- }
- local target = targets[4]
- local set_target = function(index) target = targets[index] end
- local open_picker
- open_picker = function(opts)
- pickers.new(opts, {
- prompt_title = "Bit-Browse Target",
- finder = finders.new_table({
- results = targets,
- entry_maker = function(entry)
- local displayer = entry_display.create({
- separator = " ▏",
- items = { { width = 32 }, { remaining = true } }
- })
- return {
- value = entry,
- display = function()
- return displayer({ { entry[1] }, { entry[2] } })
- end,
- ordinal = string.format("%s %s", entry[1], entry[2])
- }
- end
- }),
- sorter = conf.generic_sorter(),
- attach_mappings = function(prompt_bufnr, _)
- actions.select_default:replace(function()
- actions.close(prompt_bufnr)
- target = action_state.get_selected_entry().value
- end)
- return true
- end
- }):find()
- end
- local function add_item() end
- local function next_item() target[3]() end
- local function prev_item() target[4]() end
- local function get_target() return target[1] end
- return {
- open = open_picker,
- add = add_item,
- next = next_item,
- prev = prev_item,
- set_target = set_target,
- get_target = get_target
- }
|