feat: Add goto-preview and close_handler
This commit is contained in:
parent
8cd86d3088
commit
fbc9cb8b16
4 changed files with 77 additions and 3 deletions
|
|
@ -16,6 +16,9 @@ require("window_management").setup()
|
|||
-- Initializes custom commands and keybindings for handling code formatting
|
||||
require("format_handler").setup()
|
||||
|
||||
-- Initialize the custom close handler for handling window closing events
|
||||
require("close_handler").setup()
|
||||
|
||||
-- Set configs for servers and enable them in the Neovim LSP Client
|
||||
require("lspsetup")
|
||||
|
||||
|
|
@ -28,7 +31,6 @@ require("diagnostics")
|
|||
--[[
|
||||
-- Annoyances in Neovim environment:
|
||||
-- 1. codelldb doesn't terminate C++ program after debugging. : Don't know how to fix, have asked for help.
|
||||
-- 2. Sometimes very seldomly the cursor stops rendering, the only fix I found is to restsart Neovim.
|
||||
-- 3. Add PR to lspsaga so you can add keybindings for closing hover_doc, rename, finder, incoming_calls, and code actions using many configurable keybindings. I'm after "<Esc>" and "q".
|
||||
-- 4. Remove usage of dap-go, dap-python, and rustaceanvim. These are really just providing DAP/LSP configs which I prefer to have without plugin bloat. However, they require more to setup than your average conf.
|
||||
-- 2. Sometimes very seldomly the cursor stops rendering, the only fix I found is to restart Neovim.
|
||||
-- 3. Remove usage of dap-go, dap-python, and rustaceanvim. These are really just providing DAP/LSP configs which I prefer to have without plugin bloat. However, they require more to setup than your average conf.
|
||||
--]]
|
||||
|
|
|
|||
|
|
@ -6,10 +6,12 @@
|
|||
"copilot.vim": { "branch": "release", "commit": "d1e8429bef7f7709586886b0a23a46fbecc685c4" },
|
||||
"diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
|
||||
"gitsigns.nvim": { "branch": "main", "commit": "43b0c856ae5f32a195d83f4a27fe21d63e6c966c" },
|
||||
"goto-preview": { "branch": "main", "commit": "d1faf6ea992b5bcaaaf2c682e1aba3131a01143e" },
|
||||
"inc-rename.nvim": { "branch": "main", "commit": "2eaff20526ff6101337b84f4b0d238c11f47d7f4" },
|
||||
"incline.nvim": { "branch": "main", "commit": "27040695b3bbfcd3257669037bd008d1a892831d" },
|
||||
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
|
||||
"leap.nvim": { "branch": "main", "commit": "2b68ddc0802bd295e64c9e2e75f18f755e50dbcc" },
|
||||
"logger.nvim": { "branch": "main", "commit": "63dd10c9b9a159fd6cfe08435d9606384ff103c5" },
|
||||
"lualine.nvim": { "branch": "master", "commit": "15884cee63a8c205334ab13ab1c891cd4d27101a" },
|
||||
"markview.nvim": { "branch": "main", "commit": "3fd645600961781966adcfc1c77a6af8730042d7" },
|
||||
"mini.diff": { "branch": "main", "commit": "ec8a5ae365c5d15920721ea42b1351dbc9e61f2d" },
|
||||
|
|
|
|||
41
nvim/lua/close_handler.lua
Normal file
41
nvim/lua/close_handler.lua
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
local utils = require("utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
local callbacks = {}
|
||||
local handle_count = 1
|
||||
|
||||
function M.setup()
|
||||
utils.set_keymap_list({
|
||||
{
|
||||
"q",
|
||||
function()
|
||||
for _, cb in ipairs(callbacks) do
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
function M.register_on_close_cb(cb)
|
||||
assert(type(cb) == "function", "Callback must be a function")
|
||||
|
||||
local handle = handle_count
|
||||
handle_count = handle_count + 1
|
||||
table.insert(callbacks, cb)
|
||||
|
||||
return handle
|
||||
end
|
||||
|
||||
function M.remove_on_close_cb(cb_handle)
|
||||
assert(type(cb_handle) == "number", "Callback handle must be a number")
|
||||
assert(cb_handle > 0 and cb_handle <= #callbacks, "Invalid callback handle")
|
||||
assert(callbacks[cb_handle] ~= nil, "Callback does not exist")
|
||||
|
||||
callbacks[cb_handle] = nil
|
||||
end
|
||||
|
||||
return M
|
||||
29
nvim/lua/plugs/goto-preview.lua
Normal file
29
nvim/lua/plugs/goto-preview.lua
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
local close_handler = require("close_handler")
|
||||
|
||||
local close_cb_handle = 0
|
||||
|
||||
return {
|
||||
"rmagatti/goto-preview",
|
||||
dependencies = { "rmagatti/logger.nvim" },
|
||||
event = "BufEnter",
|
||||
config = true, -- necessary as per https://github.com/rmagatti/goto-preview/issues/88
|
||||
opts = {
|
||||
post_open_hook = function(_, _)
|
||||
close_cb_handle = close_handler.register_on_close_cb(function()
|
||||
require("goto-preview").close_all_win()
|
||||
end)
|
||||
end,
|
||||
post_close_hook = function(_, _)
|
||||
close_handler.remove_on_close_cb(close_cb_handle)
|
||||
end,
|
||||
border = { "↖", "─", "┐", "│", "┘", "─", "└", "│" },
|
||||
focus_on_open = true,
|
||||
stack_floating_preview_windows = false,
|
||||
preview_window_title = { enable = true, position = "left" },
|
||||
vim_ui_input = false,
|
||||
},
|
||||
keys = {
|
||||
{ "gp", function() require("goto-preview").goto_preview_definition() end, },
|
||||
{ "gy", function() require("goto-preview").goto_preview_type_definition() end, },
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue