all repos

init.lua @ d42338b

my nvim config
3 files changed, 49 insertions(+), 40 deletions(-)
refactor(lsp): change the way of mappings in on_attach
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed at: 2024-02-16 00:23:03 +0200
Parent: 9724c36
M lua/plugins/lsp/attach.lua

@@ -1,3 +1,5 @@

+local attach = {} + local function map(from, to) vim.keymap.set("n", from, to, { buffer = true,

@@ -6,43 +8,52 @@ silent = true,

}) end -return { - common = function(client, bufnr) - client.server_capabilities.documentFormattingProvider = false - if client.name == "gopls" then - vim.lsp.codelens.refresh() - end +function attach.basic(_, _) + map("<leader>lf", function() + vim.lsp.buf.format { async = true } + end) + map("]d", function() + vim.diagnostic.goto_next { float = false } + end) + map("[d", function() + vim.diagnostic.goto_prev { float = false } + end) + + map("]D", vim.diagnostic.goto_next) + map("[D", vim.diagnostic.goto_prev) +end + +function attach.common(client, bufnr) + client.server_capabilities.documentFormattingProvider = false + if client.name == "gopls" then + vim.lsp.codelens.refresh() + end + + if client.server_capabilities.inlayHintProvider then + vim.lsp.inlay_hint.enable(bufnr, true) + end + + attach.basic(client, bufnr) + + map("K", vim.lsp.buf.hover) + map("gd", "<cmd>Telescope lsp_definitions<cr>") + map("gr", "<cmd>Telescope lsp_references<cr>") + map("gi", "<cmd>Telescope lsp_implementations<cr>") + map("gl", vim.diagnostic.open_float) + map("<leader>la", vim.lsp.buf.code_action) + map("<leader>lr", vim.lsp.buf.rename) + map("<leader>ls", "<cmd>Telescope lsp_document_symbols<cr>") + map("<leader>ll", vim.lsp.codelens.run) - if client.server_capabilities.inlayHintProvider then + map("<leader>li", function() + if vim.lsp.inlay_hint.is_enabled(bufnr) then + vim.lsp.inlay_hint.enable(bufnr, false) + vim.print "Inlay hints disabled" + else vim.lsp.inlay_hint.enable(bufnr, true) + vim.print "Inlay hints enabled" end + end) +end - map("K", vim.lsp.buf.hover) - map("gd", "<cmd>Telescope lsp_definitions<cr>") - map("gr", "<cmd>Telescope lsp_references<cr>") - map("gi", "<cmd>Telescope lsp_implementations<cr>") - map("gl", vim.diagnostic.open_float) - map("<leader>la", vim.lsp.buf.code_action) - map("<leader>lr", vim.lsp.buf.rename) - map("<leader>lf", "<cmd>lua vim.lsp.buf.format {async = true}<cr>") - map("<leader>ls", "<cmd>Telescope lsp_document_symbols<cr>") - map("<leader>ll", vim.lsp.codelens.run) - map("]d", vim.diagnostic.goto_next) - map("[d", vim.diagnostic.goto_prev) - - map("<leader>li", function() - if vim.lsp.inlay_hint.is_enabled(bufnr) then - vim.lsp.inlay_hint.enable(bufnr, false) - vim.print "Inlay hints disabled" - else - vim.lsp.inlay_hint.enable(bufnr, true) - vim.print "Inlay hints enabled" - end - end) - end, - null_ls = function(_, _) - map("<leader>lf", "<cmd>lua vim.lsp.buf.format {async = true}<cr>") - map("]d", vim.diagnostic.goto_next) - map("[d", vim.diagnostic.goto_prev) - end, -} +return attach
M lua/plugins/lsp/init.lua

@@ -40,9 +40,7 @@ {

"williamboman/mason.nvim", config = true, build = function() - pcall(function() - vim.cmd "MasonUpdate" - end) + pcall(vim.cmd.MasonUpdate()) end, }, },
M lua/plugins/lsp/null-ls.lua

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

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