Skip to content

Commit 9b14f13

Browse files
authored
refactor: use telescope/fzf-lua to replace glance.nvim (#1519)
* refactor: use telescope/fzf-lua to replace glance.nvim * fix(ci): lint code * refactor(ci): remove lint args
1 parent 68ec5c7 commit 9b14f13

7 files changed

Lines changed: 55 additions & 130 deletions

File tree

.github/workflows/lint_code.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ jobs:
88
- uses: actions/checkout@v6
99
- uses: lunarmodules/luacheck@v1
1010
with:
11-
args: . --std luajit --max-line-length 150 --no-config --globals vim _debugging _command_panel _flash_esc_or_noh _telescope_collections _toggle_inlayhint _toggle_virtuallines _toggle_lazygit _select_chat_model
11+
args: . --std luajit --max-line-length 150 --no-config --globals vim _debugging

lua/keymap/completion.lua

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local bind = require("keymap.bind")
22
local map_cr = bind.map_cr
33
local map_callback = bind.map_callback
4+
local helpers = require("keymap.helpers")
45

56
local mappings = {
67
fmt = {
@@ -26,14 +27,7 @@ function M.lsp(buf)
2627
:with_buffer(buf)
2728
:with_desc("lsp: Toggle outline"),
2829
["n|gto"] = map_callback(function()
29-
if require("core.settings").search_backend == "fzf" then
30-
local prompt_position = require("telescope.config").values.layout_config.horizontal.prompt_position
31-
require("fzf-lua").lsp_document_symbols({
32-
fzf_opts = { ["--layout"] = prompt_position == "top" and "reverse" or "default" },
33-
})
34-
else
35-
require("telescope.builtin").lsp_document_symbols()
36-
end
30+
helpers.picker("lsp_document_symbols")
3731
end)
3832
:with_silent()
3933
:with_buffer(buf)
@@ -67,13 +61,25 @@ function M.lsp(buf)
6761
:with_silent()
6862
:with_buffer(buf)
6963
:with_desc("lsp: Code action for cursor"),
70-
["n|gd"] = map_cr("Glance definitions"):with_silent():with_buffer(buf):with_desc("lsp: Preview definition"),
71-
["n|gD"] = map_cr("Lspsaga goto_definition"):with_silent():with_buffer(buf):with_desc("lsp: Goto definition"),
72-
["n|gh"] = map_cr("Glance references"):with_silent():with_buffer(buf):with_desc("lsp: Show reference"),
73-
["n|gm"] = map_cr("Glance implementations")
64+
["n|gd"] = map_cr("Lspsaga peek_definition")
7465
:with_silent()
7566
:with_buffer(buf)
76-
:with_desc("lsp: Show implementation"),
67+
:with_desc("lsp: Preview definition"),
68+
["n|gD"] = map_cr("Lspsaga goto_definition"):with_silent():with_buffer(buf):with_desc("lsp: Goto definition"),
69+
["n|gh"] = map_callback(function()
70+
helpers.picker("lsp_references")
71+
end)
72+
:with_noremap()
73+
:with_nowait()
74+
:with_silent()
75+
:with_desc("lsp: show finder"),
76+
["n|gm"] = map_callback(function()
77+
helpers.picker("lsp_implementations")
78+
end)
79+
:with_noremap()
80+
:with_nowait()
81+
:with_silent()
82+
:with_desc("lsp: show implementations"),
7783
["n|gci"] = map_cr("Lspsaga incoming_calls")
7884
:with_silent()
7985
:with_buffer(buf)
@@ -83,13 +89,13 @@ function M.lsp(buf)
8389
:with_buffer(buf)
8490
:with_desc("lsp: Show outgoing calls"),
8591
["n|<leader>lv"] = map_callback(function()
86-
_toggle_virtuallines()
92+
helpers.toggle_virtuallines()
8793
end)
8894
:with_noremap()
8995
:with_silent()
9096
:with_desc("lsp: Toggle virtual lines"),
9197
["n|<leader>lh"] = map_callback(function()
92-
_toggle_inlayhint()
98+
helpers.toggle_inlayhint()
9399
end)
94100
:with_noremap()
95101
:with_silent()

lua/keymap/editor.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
---@diagnostic disable: undefined-global
12
local bind = require("keymap.bind")
23
local map_cr = bind.map_cr
34
local map_cu = bind.map_cu
45
local map_cmd = bind.map_cmd
56
local map_callback = bind.map_callback
67
local et = bind.escape_termcode
8+
local helpers = require("keymap.helpers")
79

810
local ts_to_select = require("nvim-treesitter-textobjects.select")
911
local ts_to_swap = require("nvim-treesitter-textobjects.swap")
@@ -49,7 +51,7 @@ local mappings = {
4951
["n|J"] = map_cmd("mzJ`z"):with_noremap():with_desc("edit: Join next line"),
5052
["n|<S-Tab>"] = map_cr("normal za"):with_noremap():with_silent():with_desc("edit: Toggle code fold"),
5153
["n|<Esc>"] = map_callback(function()
52-
_flash_esc_or_noh()
54+
helpers.flash_esc_or_noh()
5355
end)
5456
:with_noremap()
5557
:with_silent()

lua/keymap/helpers.lua

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
_G._command_panel = function()
2-
require("telescope.builtin").keymaps({
3-
lhs_filter = function(lhs)
4-
return not string.find(lhs, "Þ")
5-
end,
6-
})
7-
end
1+
local M = {}
82

9-
_G._flash_esc_or_noh = function()
3+
M.flash_esc_or_noh = function()
104
local flash_active, state = pcall(function()
115
return require("flash.plugins.char").state
126
end)
@@ -17,7 +11,7 @@ _G._flash_esc_or_noh = function()
1711
end
1812
end
1913

20-
_G._telescope_collections = function(opts)
14+
M.telescope_collections = function(opts)
2115
local tabs = require("search.tabs")
2216
local actions = require("telescope.actions")
2317
local state = require("telescope.actions.state")
@@ -45,7 +39,7 @@ _G._telescope_collections = function(opts)
4539
:find()
4640
end
4741

48-
_G._toggle_inlayhint = function()
42+
M.toggle_inlayhint = function()
4943
local is_enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = 0 })
5044
vim.lsp.inlay_hint.enable(not is_enabled)
5145
vim.notify(
@@ -55,7 +49,7 @@ _G._toggle_inlayhint = function()
5549
)
5650
end
5751

58-
_G._toggle_virtuallines = function()
52+
M.toggle_virtuallines = function()
5953
require("tiny-inline-diagnostic").toggle()
6054
vim.notify(
6155
"Virtual lines are now "
@@ -66,7 +60,7 @@ _G._toggle_virtuallines = function()
6660
end
6761

6862
local _lazygit = nil
69-
_G._toggle_lazygit = function()
63+
M.toggle_lazygit = function()
7064
if vim.fn.executable("lazygit") == 1 then
7165
if not _lazygit then
7266
_lazygit = require("toggleterm.terminal").Terminal:new({
@@ -82,7 +76,7 @@ _G._toggle_lazygit = function()
8276
end
8377
end
8478

85-
_G._select_chat_model = function()
79+
M.select_chat_model = function()
8680
local actions = require("telescope.actions")
8781
local action_state = require("telescope.actions.state")
8882
local finder = require("telescope.finders")
@@ -110,3 +104,17 @@ _G._select_chat_model = function()
110104
})
111105
:find()
112106
end
107+
108+
M.picker = function(method, tele_opts)
109+
local prompt_position = require("telescope.config").values.layout_config.horizontal.prompt_position
110+
local fzf_opts = { ["--layout"] = prompt_position == "top" and "reverse" or "default" }
111+
if require("core.settings").search_backend == "fzf" then
112+
require("fzf-lua")[method]({
113+
fzf_opts = fzf_opts,
114+
})
115+
else
116+
require("telescope.builtin")[method](tele_opts)
117+
end
118+
end
119+
120+
return M

lua/keymap/tool.lua

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local map_cr = bind.map_cr
44
local map_cu = bind.map_cu
55
local map_cmd = bind.map_cmd
66
local map_callback = bind.map_callback
7-
require("keymap.helpers")
7+
local helpers = require("keymap.helpers")
88

99
local mappings = {
1010
plugins = {
@@ -74,7 +74,7 @@ local mappings = {
7474
:with_desc("terminal: Toggle float"),
7575
["t|<A-d>"] = map_cmd("<Cmd>ToggleTerm<CR>"):with_noremap():with_silent():with_desc("terminal: Toggle float"),
7676
["n|<leader>gg"] = map_callback(function()
77-
_toggle_lazygit()
77+
helpers.toggle_lazygit()
7878
end)
7979
:with_noremap()
8080
:with_silent()
@@ -100,20 +100,17 @@ local mappings = {
100100

101101
-- Plugin: telescope
102102
["n|<C-p>"] = map_callback(function()
103-
if require("core.settings").search_backend == "fzf" then
104-
local prompt_position = require("telescope.config").values.layout_config.horizontal.prompt_position
105-
require("fzf-lua").keymaps({
106-
fzf_opts = { ["--layout"] = prompt_position == "top" and "reverse" or "default" },
107-
})
108-
else
109-
_command_panel()
110-
end
103+
helpers.picker("keymaps", {
104+
lhs_filter = function(lhs)
105+
return not string.find(lhs, "Þ")
106+
end,
107+
})
111108
end)
112109
:with_noremap()
113110
:with_silent()
114111
:with_desc("tool: Toggle command panel"),
115112
["n|<leader>fc"] = map_callback(function()
116-
_telescope_collections(require("telescope.themes").get_dropdown())
113+
helpers.telescope_collections(require("telescope.themes").get_dropdown())
117114
end)
118115
:with_noremap()
119116
:with_silent()
@@ -248,7 +245,7 @@ local mappings = {
248245

249246
--- Plugin: CodeCompanion and edgy
250247
["n|<leader>cs"] = map_callback(function()
251-
_select_chat_model()
248+
helpers.select_chat_model()
252249
end)
253250
:with_noremap()
254251
:with_silent()

lua/modules/configs/completion/glance.lua

Lines changed: 0 additions & 83 deletions
This file was deleted.

lua/modules/plugins/completion.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ completion["nvimdev/lspsaga.nvim"] = {
2020
config = require("completion.lspsaga"),
2121
dependencies = "nvim-tree/nvim-web-devicons",
2222
}
23-
completion["DNLHC/glance.nvim"] = {
24-
lazy = true,
25-
event = "LspAttach",
26-
config = require("completion.glance"),
27-
}
2823
completion["rachartier/tiny-inline-diagnostic.nvim"] = {
2924
lazy = false,
3025
config = require("completion.tiny-inline-diagnostic"),

0 commit comments

Comments
 (0)