nvim: Add lsp references preview window

Add 'glances.nvim' plugin which shows the LSP references, definitions and
implementations in a very nice floating preview window. (Previously we
used Telescope which is still called if the glances plugin does not
exist.)

Can preview, scroll in the floating window, go to the destination, open
the destination in vert/horiz splits.
This commit is contained in:
Marty Oehme 2024-03-01 10:36:16 +01:00
parent fcaaba9e8d
commit b0aabf719a
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
3 changed files with 15 additions and 7 deletions

View file

@ -29,6 +29,7 @@
"fwatch.nvim": { "branch": "main", "commit": "a691f7349dc66285cd75a1a698dd28bca45f2bf8" }, "fwatch.nvim": { "branch": "main", "commit": "a691f7349dc66285cd75a1a698dd28bca45f2bf8" },
"git-conflict.nvim": { "branch": "main", "commit": "4c8e252b87d54d944c1e56bfb477f78b6fdaf661" }, "git-conflict.nvim": { "branch": "main", "commit": "4c8e252b87d54d944c1e56bfb477f78b6fdaf661" },
"gitsigns.nvim": { "branch": "main", "commit": "6ef8c54fb526bf3a0bc4efb0b2fe8e6d9a7daed2" }, "gitsigns.nvim": { "branch": "main", "commit": "6ef8c54fb526bf3a0bc4efb0b2fe8e6d9a7daed2" },
"glance.nvim": { "branch": "master", "commit": "8ed5cf3b3b1231ea696d88c9efd977027429d869" },
"headlines.nvim": { "branch": "master", "commit": "d39c4e6ed8963717bc9b2dc39fada8fe1039e9bf" }, "headlines.nvim": { "branch": "master", "commit": "d39c4e6ed8963717bc9b2dc39fada8fe1039e9bf" },
"image.nvim": { "branch": "master", "commit": "9b6248bd8b58b505559e31eb581b7c4638369ec3" }, "image.nvim": { "branch": "master", "commit": "9b6248bd8b58b505559e31eb581b7c4638369ec3" },
"lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" }, "lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" },

View file

@ -79,7 +79,12 @@ local function on_attach(client, bufnr)
) )
map("n", "<localleader>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", { buffer = bufnr, desc = "Codeactions" }) map("n", "<localleader>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", { buffer = bufnr, desc = "Codeactions" })
map("n", "<localleader>ln", "<cmd>lua vim.lsp.buf.rename()<cr>", { buffer = bufnr, desc = "Rename element" }) map("n", "<localleader>ln", "<cmd>lua vim.lsp.buf.rename()<cr>", { buffer = bufnr, desc = "Rename element" })
if vim.fn.exists(":Telescope") then if vim.fn.exists(":Glance") then
map("n", "<localleader>lr", "<cmd>Glance references<cr>", { buffer = bufnr, desc = "References" })
map("n", "<localleader>lf", "<cmd>Glance definitions<cr>", { buffer = bufnr, desc = "Definition" })
map("n", "<localleader>lt", "<cmd>Glance type_definitions<cr>", { buffer = bufnr, desc = "Type definition" })
map("n", "<localleader>lm", "<cmd>Glance implementations<cr>", { buffer = bufnr, desc = "Implementation" })
elseif vim.fn.exists(":Telescope") then
map("n", "<localleader>lr", "<cmd>Telescope lsp_references<cr>", { buffer = bufnr, desc = "References" }) map("n", "<localleader>lr", "<cmd>Telescope lsp_references<cr>", { buffer = bufnr, desc = "References" })
map("n", "<localleader>lf", "<cmd>Telescope lsp_definitions<cr>", { buffer = bufnr, desc = "Definition" }) map("n", "<localleader>lf", "<cmd>Telescope lsp_definitions<cr>", { buffer = bufnr, desc = "Definition" })
map( map(
@ -128,7 +133,7 @@ local function on_attach(client, bufnr)
end end
-- Display diagnostics as virtual text only if not in insert mode -- Display diagnostics as virtual text only if not in insert mode
-- https://lr.artemislena.eu/r/neovim/comments/12inp4c/disable_diagnostics_virtual_text_when_in_insert/jqqifwk/ -- /r/neovim/comments/12inp4c/disable_diagnostics_virtual_text_when_in_insert/jqqifwk/
vim.api.nvim_create_autocmd("InsertEnter", { vim.api.nvim_create_autocmd("InsertEnter", {
callback = function() callback = function()
vim.diagnostic.config({ virtual_text = false }) vim.diagnostic.config({ virtual_text = false })

View file

@ -66,11 +66,13 @@ return {
config = function() config = function()
require("plugins.config.lsp") require("plugins.config.lsp")
end, end,
keys = { { keys = { { "<leader>vs", ":LspInfo<cr>", desc = "LspInfo" } },
"<leader>vs", },
":LspInfo<cr>", -- very very pretty lsp 'peek' menus
desc = "LspInfo", {
} }, "DNLHC/glance.nvim",
opts = { border = { enable = true }, theme = { enable = true, mode = "auto" } },
cmd = { "Glance" },
}, },
-- linting setup -- linting setup