From ebb3941d42c146c8822a5e0e2e90158fa50057a5 Mon Sep 17 00:00:00 2001 From: Dhananjay Date: Tue, 16 Jul 2024 17:58:31 +0530 Subject: [PATCH] cscope: mini.pick support (#44) --- README.md | 7 ++++--- doc/cscope_maps.txt | 9 +++++---- lua/cscope/pickers/mini-pick.lua | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 lua/cscope/pickers/mini-pick.lua diff --git a/README.md b/README.md index d342be6..9aa9f01 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Heavily inspired by emacs' [xcscope.el](https://github.com/dkogan/xcscope.el). - Supports `cscope` and `gtags-cscope`. Use `cscope.exec` option to specify executable. - `:Cstag ` does `tags` search if no results are found in `cscope`. - For `nvim < 0.9`, legacy cscope will be used. It will support keymaps. It won't have all the niceties of lua port. -- Opens results in quickfix, **telescope**, or **fzf-lua**. +- Display results in quickfix, **telescope**, **fzf-lua** or **mini.pick**. - Has [which-key.nvim](https://github.com/folke/which-key.nvim) hints. - See [this section](#vim-gutentags) for `vim-gutentags`. @@ -61,7 +61,8 @@ Following example uses [lazy.nvim](https://github.com/folke/lazy.nvim) "folke/which-key.nvim", -- optional [for whichkey hints] "nvim-telescope/telescope.nvim", -- optional [for picker="telescope"] "ibhagwan/fzf-lua", -- optional [for picker="fzf-lua"] - "nvim-tree/nvim-web-devicons", -- optional [for devicons in telescope or fzf] + "echasnovski/mini.pick" -- optional [for picker="mini-pick"] + "nvim-tree/nvim-web-devicons", -- optional [for devicons in telescope, fzf or mini.pick] }, opts = { -- USE EMPTY FOR DEFAULT OPTIONS @@ -94,7 +95,7 @@ _cscope_maps_ comes with following defaults: -- cscope executable exec = "cscope", -- "cscope" or "gtags-cscope" -- choose your fav picker - picker = "quickfix", -- "telescope", "fzf-lua" or "quickfix" + picker = "quickfix", -- "quickfix", "telescope", "fzf-lua" or "mini-pick" -- size of quickfix window qf_window_size = 5, -- any positive integer -- position of quickfix window diff --git a/doc/cscope_maps.txt b/doc/cscope_maps.txt index e7eb9ae..7c6d2f3 100644 --- a/doc/cscope_maps.txt +++ b/doc/cscope_maps.txt @@ -1,4 +1,4 @@ -*cscope_maps.txt* For Neovim >= v0.10.0 Last change: 2024 July 06 +*cscope_maps.txt* For Neovim >= v0.10.0 Last change: 2024 July 16 ============================================================================== Table of Contents *cscope_maps-table-of-contents* @@ -35,7 +35,7 @@ CSCOPE ~ - Supports `cscope` and `gtags-cscope`. Use `cscope.exec` option to specify executable. - `:Cstag ` does `tags` search if no results are found in `cscope`. - For `nvim < 0.9`, legacy cscope will be used. It will support keymaps. It won’t have all the niceties of lua port. -- Opens results in quickfix, **telescope**, or **fzf-lua**. +- Display results in quickfix, **telescope**, **fzf-lua** or **mini.pick**. - Has which-key.nvim hints. - See |cscope_maps-this-section| for `vim-gutentags`. @@ -80,7 +80,8 @@ lazy.nvim "folke/which-key.nvim", -- optional [for whichkey hints] "nvim-telescope/telescope.nvim", -- optional [for picker="telescope"] "ibhagwan/fzf-lua", -- optional [for picker="fzf-lua"] - "nvim-tree/nvim-web-devicons", -- optional [for devicons in telescope or fzf] + "echasnovski/mini.pick" -- optional [for picker="mini-pick"] + "nvim-tree/nvim-web-devicons", -- optional [for devicons in telescope, fzf or mini.pick] }, opts = { -- USE EMPTY FOR DEFAULT OPTIONS @@ -115,7 +116,7 @@ _cscope_maps_ comes with following defaults: -- cscope executable exec = "cscope", -- "cscope" or "gtags-cscope" -- choose your fav picker - picker = "quickfix", -- "telescope", "fzf-lua" or "quickfix" + picker = "quickfix", -- "quickfix", "telescope", "fzf-lua" or "mini-pick" -- size of quickfix window qf_window_size = 5, -- any positive integer -- position of quickfix window diff --git a/lua/cscope/pickers/mini-pick.lua b/lua/cscope/pickers/mini-pick.lua new file mode 100644 index 0000000..f58ff85 --- /dev/null +++ b/lua/cscope/pickers/mini-pick.lua @@ -0,0 +1,27 @@ +local M = {} + +M.run = function(opts) + opts = opts or {} + local entries = {} + + for _, item in ipairs(opts.cscope.parsed_output) do + local entry = { + path = item.filename, + lnum = tonumber(item.lnum), + text = string.format("%s:%s:%s", item.filename, item.lnum, item.text), + } + table.insert(entries, entry) + end + + MiniPick.start({ + source = { + items = entries, + name = opts.cscope.prompt_title, + show = function(buf_id, items, query) + MiniPick.default_show(buf_id, items, query, { show_icons = true }) + end, + }, + }) +end + +return M