diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-24 18:06:06 +0200 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-06-24 18:06:06 +0200 |
| commit | 709e1695f2dae89bc1df71578a73196e0f56c5e0 (patch) | |
| tree | 342c4b34137cbcb19289fb7ce89a47a2c18dc49e /plugin | |
| parent | bc17346650fd043a72045d0be6141aa832336233 (diff) | |
| download | nvim-config-709e1695f2dae89bc1df71578a73196e0f56c5e0.tar.gz nvim-config-709e1695f2dae89bc1df71578a73196e0f56c5e0.zip | |
refactor(nvim): rewrite the lsp plugin
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/50-lsp.lua | 91 |
1 files changed, 52 insertions, 39 deletions
diff --git a/plugin/50-lsp.lua b/plugin/50-lsp.lua index 41229e5..123615b 100644 --- a/plugin/50-lsp.lua +++ b/plugin/50-lsp.lua @@ -1,7 +1,15 @@ -- --- LSP client configurations +-- 50-lsp.lua +-- +-- * Configures and enables the LSP servers (lua_ls, bashls, marksman, vimls, basedpyright, ruff). +-- * On attach, enables completion and inlay hints for clients that support them. +-- +-- User commands: +-- `LspInspect`: inspect the first LSP client's server capabilities +-- `LspHintToggle`: toggle LSP inlay hints in the current buffer -- +-- Notify the first attached LSP client's server capabilities. local function inspect_lsp() local client = vim.lsp.get_clients()[1] if client == nil then @@ -11,40 +19,29 @@ local function inspect_lsp() vim.notify(vim.inspect(client.server_capabilities), vim.log.levels.INFO) end -vim.api.nvim_create_user_command("LspInspect", inspect_lsp, { desc = "Inspect LSP client" }) - --- Enable LSP server capabilities if available when attaching, see `:help lsp-attach` -vim.api.nvim_create_autocmd("LspAttach", { - desc = "Enable LSP capabilities", - group = vim.g.dotfiles.augroup, - callback = function(ev) - local client = assert(vim.lsp.get_client_by_id(ev.data.client_id)) - if client:supports_method("textDocument/completion") then - vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true }) - else - vim.notify( - "Client " .. client.name .. " does not support completion", - vim.log.levels.WARN - ) - end - if client:supports_method("textDocument/inlayHint") then - vim.lsp.inlay_hint.enable(true, { bufnr = 0 }) - else - vim.notify( - "Client " .. client.name .. " does not support inlay hints", - vim.log.levels.WARN - ) - end - end, -}) +-- Enable LSP server capabilities if available when attaching, see `:help lsp-attach`. +local function on_lsp_attach(ev) + local client = assert(vim.lsp.get_client_by_id(ev.data.client_id)) + if client:supports_method("textDocument/completion") then + vim.lsp.completion.enable(true, client.id, ev.buf, { autotrigger = true }) + else + vim.notify("Client " .. client.name .. " does not support completion", vim.log.levels.WARN) + end + if client:supports_method("textDocument/inlayHint") then + vim.lsp.inlay_hint.enable(true, { bufnr = 0 }) + else + vim.notify("Client " .. client.name .. " does not support inlay hints", vim.log.levels.WARN) + end +end -vim.api.nvim_create_user_command("LspHintToggle", function() +-- Toggle LSP inlay hints in the current buffer. +local function toggle_lsp_hints() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = 0 }), { bufnr = 0 }) -end, { desc = "Toggle LSP inlay hints" }) +end ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- -- Lua ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- vim.lsp.config("lua_ls", { on_init = function(client) @@ -63,28 +60,44 @@ vim.lsp.config("lua_ls", { }) vim.lsp.enable("lua_ls") ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- -- Bash ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- vim.lsp.enable("bashls") ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- -- Markdown ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- vim.lsp.config("marksman", { filetypes = { "markdown" } }) vim.lsp.enable("marksman") ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- -- Vimscript ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- vim.lsp.enable("vimls") ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- -- Python ------------------------------------------------------------------------------------------------------------------------- +---------------------------------------------------------------------------------------------------- vim.lsp.enable("basedpyright") vim.lsp.enable("ruff") + +---------------------------------------------------------------------------------------------------- + +vim.api.nvim_create_autocmd("LspAttach", { + desc = "Enable LSP capabilities", + group = vim.g.dotfiles.augroup, + callback = on_lsp_attach, +}) + +vim.api.nvim_create_user_command("LspInspect", inspect_lsp, { desc = "Inspect LSP client" }) + +vim.api.nvim_create_user_command( + "LspHintToggle", + toggle_lsp_hints, + { desc = "Toggle LSP inlay hints" } +) |
