all repos

init.lua @ 4d6f4a0

my nvim config
3 files changed, 43 insertions(+), 45 deletions(-)
refactor: migrate to LspAttach for lsp attach function
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed at: 2024-05-22 23:52:16 +0300
Parent: fa3bf83
M lua/plugins/lsp/attach.lua

@@ -1,50 +1,48 @@

--- TODO: migrate to `:h LspAttach` - local u = require "core.utils" -local attach = {} -function attach.basic(_, _) - u.map("n", "<leader>lf", function() - vim.lsp.buf.format { async = true } - end, true) - u.map("n", "]d", function() - vim.diagnostic.goto_next { float = false } - end, true) - u.map("n", "[d", function() - vim.diagnostic.goto_prev { float = false } - end, true) +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("olexsmir_lsp", { clear = true }), + callback = function(args) + local bufnr = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + if not client then + error "couldnt get an lsp server" + end - u.map("n", "]D", vim.diagnostic.goto_next, true) - u.map("n", "[D", vim.diagnostic.goto_prev, true) -end + if client.supports_method "textDocument/codeLens" then + vim.lsp.codelens.run() + end ----@param client vim.lsp.Client ----@param bufnr number -function attach.common(client, bufnr) - if client.supports_method "textDocument/codeLens" then - vim.lsp.codelens.run() - end - - attach.basic(client, bufnr) + u.map("n", "<leader>lf", function() + vim.lsp.buf.format { async = true } + end, bufnr) + u.map("n", "]d", function() + vim.diagnostic.goto_next { float = false } + end, bufnr) + u.map("n", "[d", function() + vim.diagnostic.goto_prev { float = false } + end, bufnr) - u.map("n", "K", vim.lsp.buf.hover, true) - u.map("n", "gd", "<cmd>Telescope lsp_definitions<cr>", true) - u.map("n", "gr", "<cmd>Telescope lsp_references<cr>", true) - u.map("n", "gi", "<cmd>Telescope lsp_implementations<cr>", true) - u.map("n", "gl", vim.diagnostic.open_float, true) - u.map("n", "<leader>la", vim.lsp.buf.code_action, true) - u.map("n", "<leader>lr", vim.lsp.buf.rename, true) - u.map("n", "<leader>ss", "<cmd>Telescope lsp_document_symbols<cr>", true) - u.map("n", "<leader>ll", vim.lsp.codelens.run, true) - u.map("n", "<leader>li", function() - if vim.lsp.inlay_hint.is_enabled { bufnr = bufnr } then - vim.lsp.inlay_hint.enable(false, { bufnr = bufnr }) - vim.print "Inlay hints disabled" - else - vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) - vim.print "Inlay hints enabled" - end - end, true) -end + u.map("n", "]D", vim.diagnostic.goto_next, bufnr) + u.map("n", "[D", vim.diagnostic.goto_prev, bufnr) -return attach + u.map("n", "K", vim.lsp.buf.hover, bufnr) + u.map("n", "gd", "<cmd>Telescope lsp_definitions<cr>", bufnr) + u.map("n", "gr", "<cmd>Telescope lsp_references<cr>", bufnr) + u.map("n", "gi", "<cmd>Telescope lsp_implementations<cr>", bufnr) + u.map("n", "gl", vim.diagnostic.open_float, bufnr) + u.map("n", "<leader>la", vim.lsp.buf.code_action, bufnr) + u.map("n", "<leader>lr", vim.lsp.buf.rename, bufnr) + u.map("n", "<leader>ss", "<cmd>Telescope lsp_document_symbols<cr>", bufnr) + u.map("n", "<leader>ll", vim.lsp.codelens.run, bufnr) + u.map("n", "<leader>li", function() + if vim.lsp.inlay_hint.is_enabled { bufnr = bufnr } then + vim.lsp.inlay_hint.enable(false, { bufnr = bufnr }) + vim.print "Inlay hints disabled" + else + vim.lsp.inlay_hint.enable(true, { bufnr = bufnr }) + vim.print "Inlay hints enabled" + end + end, bufnr) + end, +})
M lua/plugins/lsp/init.lua

@@ -40,6 +40,7 @@ },

}, config = function() for name, conf in pairs(require "plugins.lsp.servers") do + require "plugins.lsp.attach" require("lspconfig")[name].setup(vim.tbl_extend("force", { on_attach = require("plugins.lsp.attach").common, flags = { debounce_text_changes = 150 },
M lua/plugins/lsp/null-ls.lua

@@ -4,7 +4,6 @@ local formatting = null_ls.builtins.formatting

local diagnostic = null_ls.builtins.diagnostics null_ls.setup { - on_attach = require("plugins.lsp.attach").basic, sources = { formatting.stylua, diagnostic.selene,