feat(nvim): refactor to use LspAttach event, fix navic

This commit is contained in:
winston 2023-06-02 00:41:08 +02:00
parent 0f7c3fe09e
commit 85770acd4c
Signed by: winston
GPG key ID: 3786770EDBC2B481
4 changed files with 49 additions and 72 deletions

View file

@ -11,7 +11,7 @@
"cmp-nvim-lsp": { "branch": "main", "commit": "0e6b2ed705ddcff9738ec4ea838141654f12eeef" }, "cmp-nvim-lsp": { "branch": "main", "commit": "0e6b2ed705ddcff9738ec4ea838141654f12eeef" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp-vsnip": { "branch": "main", "commit": "989a8a73c44e926199bfd05fa7a516d51f2d2752" }, "cmp-vsnip": { "branch": "main", "commit": "989a8a73c44e926199bfd05fa7a516d51f2d2752" },
"comment.nvim": { "branch": "master", "commit": "e1fe53117aab24c378d5e6deaad786789c360123" }, "comment.nvim": { "branch": "master", "commit": "c8043290f2d77f61025494d839d88e414608c460" },
"copilot.lua": { "branch": "master", "commit": "77e3a4907928f0813024e573b882dc879dfc0c6b" }, "copilot.lua": { "branch": "master", "commit": "77e3a4907928f0813024e573b882dc879dfc0c6b" },
"diffview.nvim": { "branch": "main", "commit": "bff58a6ea3e081ca50049700f9848b2f84ea57be" }, "diffview.nvim": { "branch": "main", "commit": "bff58a6ea3e081ca50049700f9848b2f84ea57be" },
"dressing.nvim": { "branch": "master", "commit": "f19cbd56f7f8cad212c58a7285d09c5d9c273896" }, "dressing.nvim": { "branch": "master", "commit": "f19cbd56f7f8cad212c58a7285d09c5d9c273896" },
@ -31,12 +31,12 @@
"lualine.nvim": { "branch": "master", "commit": "05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9" }, "lualine.nvim": { "branch": "master", "commit": "05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9" },
"markdown-preview.nvim": { "branch": "master", "commit": "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96" }, "markdown-preview.nvim": { "branch": "master", "commit": "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96" },
"neodev.nvim": { "branch": "main", "commit": "358f11c585fdccfcb5e8eae720c423fbed6d92de" }, "neodev.nvim": { "branch": "main", "commit": "358f11c585fdccfcb5e8eae720c423fbed6d92de" },
"neogit": { "branch": "master", "commit": "80be328067b370744c39323674a2ebaf515dea14" }, "neogit": { "branch": "master", "commit": "4cebc271b13cb7af6b5a3e8ad76a356660c0c00c" },
"null-ls.nvim": { "branch": "main", "commit": "c89333e034a8daba654ebfcf9a4ec9f87765f01e" }, "null-ls.nvim": { "branch": "main", "commit": "c89333e034a8daba654ebfcf9a4ec9f87765f01e" },
"nvim-autopairs": { "branch": "master", "commit": "59df87a84c80a357ca8d8fe86e451b93ac476ccc" }, "nvim-autopairs": { "branch": "master", "commit": "59df87a84c80a357ca8d8fe86e451b93ac476ccc" },
"nvim-cmp": { "branch": "main", "commit": "fc0f694af1a742ada77e5b1c91ff405c746f4a26" }, "nvim-cmp": { "branch": "main", "commit": "fc0f694af1a742ada77e5b1c91ff405c746f4a26" },
"nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" }, "nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" },
"nvim-dap": { "branch": "master", "commit": "56118cee6af15cb9ddba9d080880949d8eeb0c9f" }, "nvim-dap": { "branch": "master", "commit": "d234b0a77fc98a550dbaecdb5cd3dc5cd17147be" },
"nvim-dap-ui": { "branch": "master", "commit": "c020f660b02772f9f3d11f599fefad3268628a9e" }, "nvim-dap-ui": { "branch": "master", "commit": "c020f660b02772f9f3d11f599fefad3268628a9e" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "57f1dbd0458dd84a286b27768c142e1567f3ce3b" }, "nvim-dap-virtual-text": { "branch": "master", "commit": "57f1dbd0458dd84a286b27768c142e1567f3ce3b" },
"nvim-lspconfig": { "branch": "master", "commit": "9166622781a39a829878d1fd24c174529d996838" }, "nvim-lspconfig": { "branch": "master", "commit": "9166622781a39a829878d1fd24c174529d996838" },
@ -45,12 +45,12 @@
"nvim-spectre": { "branch": "master", "commit": "1abe23ec9b7bc3082164f4cb842d521ef70e080e" }, "nvim-spectre": { "branch": "master", "commit": "1abe23ec9b7bc3082164f4cb842d521ef70e080e" },
"nvim-surround": { "branch": "main", "commit": "10b20ca7d9da1ac8df8339e140ffef94f9ab3b18" }, "nvim-surround": { "branch": "main", "commit": "10b20ca7d9da1ac8df8339e140ffef94f9ab3b18" },
"nvim-tree.lua": { "branch": "master", "commit": "e2a4c9d09d205ebe5f071264f43f73a0077c43a3" }, "nvim-tree.lua": { "branch": "master", "commit": "e2a4c9d09d205ebe5f071264f43f73a0077c43a3" },
"nvim-treesitter": { "branch": "master", "commit": "62146fe415193879290c523b54cb5072e1f5dbbc" }, "nvim-treesitter": { "branch": "master", "commit": "56c63529c052a179134842c56c6df5728cc375da" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "95b76b95eff25e1e64f363938cd853852355d70a" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "95b76b95eff25e1e64f363938cd853852355d70a" },
"nvim-ts-autotag": { "branch": "main", "commit": "40615e96075c743ef47aaf9de966dc348bec6459" }, "nvim-ts-autotag": { "branch": "main", "commit": "40615e96075c743ef47aaf9de966dc348bec6459" },
"nvim-ts-rainbow2": { "branch": "master", "commit": "5becf2cec4b8e06b6df745cf515ac35c6c2e6308" }, "nvim-ts-rainbow2": { "branch": "master", "commit": "5becf2cec4b8e06b6df745cf515ac35c6c2e6308" },
"nvim-web-devicons": { "branch": "master", "commit": "2a125024a137677930efcfdf720f205504c97268" }, "nvim-web-devicons": { "branch": "master", "commit": "2a125024a137677930efcfdf720f205504c97268" },
"octo.nvim": { "branch": "master", "commit": "95a7f271eff4397e593c90246891c18058bdffc2" }, "octo.nvim": { "branch": "master", "commit": "0ea81c0cda4d21d054d78cd1bca7e1371df1969f" },
"playground": { "branch": "master", "commit": "2b81a018a49f8e476341dfcb228b7b808baba68b" }, "playground": { "branch": "master", "commit": "2b81a018a49f8e476341dfcb228b7b808baba68b" },
"plenary.nvim": { "branch": "master", "commit": "499e0743cf5e8075cd32af68baa3946a1c76adf1" }, "plenary.nvim": { "branch": "master", "commit": "499e0743cf5e8075cd32af68baa3946a1c76adf1" },
"presence.nvim": { "branch": "main", "commit": "87c857a56b7703f976d3a5ef15967d80508df6e6" }, "presence.nvim": { "branch": "main", "commit": "87c857a56b7703f976d3a5ef15967d80508df6e6" },

View file

@ -115,50 +115,48 @@ cmp.setup.cmdline(":", {
}), }),
}) })
local capabilities = require("cmp_nvim_lsp").default_capabilities( local capabilities = require("cmp_nvim_lsp").default_capabilities()
vim.lsp.protocol.make_client_capabilities()
)
---@diagnostic disable-next-line: unused-local vim.api.nvim_create_autocmd("LspAttach", {
local on_attach = function(client, bufnr) group = vim.api.nvim_create_augroup("UserLspConfig", {}),
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
vim.keymap.set("n", "<leader>wa", vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set(
"n",
"<leader>wr",
vim.lsp.buf.remove_workspace_folder,
bufopts
)
vim.keymap.set("n", "<leader>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set("n", "<leader>D", vim.lsp.buf.type_definition, bufopts)
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, bufopts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
vim.keymap.set("n", "<leader>lr", "<cmd>LspRestart<CR>", bufopts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, bufopts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, bufopts)
if navic_present and client.server_capabilities.documentSymbolProvider then if navic_present and client.server_capabilities.documentSymbolProvider then
navic.attach(client, bufnr) navic.attach(client, ev.buf)
end
end end
local opts = { buffer = ev.buf }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<space>lr", "<cmd>LspRestart<CR>", opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "<space>fm", function()
vim.lsp.buf.format({ async = true })
end, opts)
end,
})
lspconfig.ltex.setup({ lspconfig.ltex.setup({
capabilities = capabilities, capabilities = capabilities,
on_attach = function(client, bufnr) on_attach = function()
require("ltex_extra").setup({ require("ltex_extra").setup({
load_langs = { "en-US", "de-AT" }, load_langs = { "en-US", "de-AT" },
init_check = true, init_check = true,
path = vim.fn.stdpath("data") .. "/dictionary", path = vim.fn.stdpath("data") .. "/dictionary",
}) })
on_attach(client, bufnr)
end, end,
settings = { settings = {
ltex = {}, ltex = {},
@ -168,10 +166,7 @@ lspconfig.ltex.setup({
-- register jq for jqls -- register jq for jqls
vim.cmd([[au BufRead,BufNewFile *.jq setfiletype jq]]) vim.cmd([[au BufRead,BufNewFile *.jq setfiletype jq]])
local common = { local common = { capabilities = capabilities }
capabilities = capabilities,
on_attach = on_attach,
}
require("lsp.go").setup(common) require("lsp.go").setup(common)
require("lsp.helm-ls") require("lsp.helm-ls")

View file

@ -17,7 +17,7 @@ null.setup({
null.builtins.formatting.gofumpt, null.builtins.formatting.gofumpt,
null.builtins.formatting.isort, null.builtins.formatting.isort,
null.builtins.formatting.prettier, null.builtins.formatting.prettier,
null.builtins.formatting.rustfmt, -- null.builtins.formatting.rustfmt,
null.builtins.formatting.shfmt, null.builtins.formatting.shfmt,
null.builtins.formatting.stylua, null.builtins.formatting.stylua,
null.builtins.formatting.taplo, null.builtins.formatting.taplo,

View file

@ -6,7 +6,9 @@ return {
"nvim-tree/nvim-web-devicons", "nvim-tree/nvim-web-devicons",
{ {
"SmiteshP/nvim-navic", "SmiteshP/nvim-navic",
dependencies = { "neovim/nvim-lspconfig" },
opts = { opts = {
highlight = true,
icons = { icons = {
File = "", File = "",
Module = "", Module = "",
@ -40,19 +42,12 @@ return {
}, },
config = function() config = function()
local lualine = require("lualine") local lualine = require("lualine")
local navic = require("nvim-navic") lualine.setup({
local config = {
options = { options = {
icons_enabled = true, icons_enabled = true,
theme = "auto", theme = "catppuccin",
component_separators = { left = "", right = "" }, component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" }, section_separators = { left = "", right = "" },
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true, always_divide_middle = true,
globalstatus = true, globalstatus = true,
refresh = { refresh = {
@ -62,35 +57,22 @@ return {
}, },
}, },
sections = { sections = {
lualine_a = { lualine_a = { "mode" },
{
"mode",
fmt = function(str)
return "" .. str
end,
},
},
lualine_b = { lualine_b = {
{ "branch", icon = "" }, "branch",
"diff", "diff",
"diagnostics", "diagnostics",
}, },
lualine_c = { lualine_c = { "searchcount" },
{ navic.get_location, condition = navic.is_available }, lualine_x = { { "filetype", colored = false } },
"searchcount",
"lsp_progress",
},
lualine_x = { "filetype" },
lualine_y = { "progress" }, lualine_y = { "progress" },
lualine_z = { "location" }, lualine_z = { "location" },
}, },
tabline = {}, tabline = {},
winbar = {}, winbar = { lualine_c = { "navic" } },
inactive_winbar = {}, inactive_winbar = {},
extensions = {}, extensions = {},
} })
lualine.setup(config)
end, end,
}, },
} }