diff options
-rw-r--r-- | nvim/.config/nvim/lazy-lock.json | 10 | ||||
-rw-r--r-- | nvim/.config/nvim/lua/plugins/lsp.lua | 160 |
2 files changed, 169 insertions, 1 deletions
diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index d4a7abf..852430b 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -1,8 +1,16 @@ { + "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, + "blink.cmp": { "branch": "main", "commit": "4f38ce99a472932d5776337f08f7a8180f1f571a" }, + "conform.nvim": { "branch": "master", "commit": "372fc521f8421b7830ea6db4d6ea3bae1c77548c" }, + "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, "lualine.nvim": { "branch": "master", "commit": "15884cee63a8c205334ab13ab1c891cd4d27101a" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "344876dcf050624ba34dcfcf9d15ef3026f61cad" }, + "mason-tool-installer.nvim": { "branch": "main", "commit": "1d1c08180a5911db2bcd5d307dc4d9c9de26fe42" }, + "mason.nvim": { "branch": "main", "commit": "7c7318e8bae7e3536ef6b9e86b9e38e74f2e125e" }, "no-clown-fiesta.nvim": { "branch": "master", "commit": "2f57d1115e246b62a1a81bba806fe79aaa53b610" }, - "nvim-treesitter": { "branch": "master", "commit": "94ea4f436d2b59c80f02e293466c374584f03b8c" }, + "nvim-lspconfig": { "branch": "master", "commit": "4bc481b6f0c0cf3671fc894debd0e00347089a4e" }, + "nvim-treesitter": { "branch": "master", "commit": "28d480e0624b259095e56f353ec911f9f2a0f404" }, "nvim-web-devicons": { "branch": "master", "commit": "2c2b4eafce6cdd0cb165036faa17396eff18f847" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" } diff --git a/nvim/.config/nvim/lua/plugins/lsp.lua b/nvim/.config/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..5541feb --- /dev/null +++ b/nvim/.config/nvim/lua/plugins/lsp.lua @@ -0,0 +1,160 @@ +return { + { + "neovim/nvim-lspconfig", + dependencies = { + { "williamboman/mason.nvim", opts = {} }, + "williamboman/mason-lspconfig.nvim", + "WhoIsSethDaniel/mason-tool-installer.nvim", + "saghen/blink.cmp", + }, + config = function() + vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("lsp-attach", { clear = true }), + callback = function(event) + vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename) + vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action) + vim.keymap.set("n", "gr", require("telescope.builtin").lsp_references) + vim.keymap.set("n", "gi", require("telescope.builtin").lsp_implementations) + vim.keymap.set("n", "gd", require("telescope.builtin").lsp_definitions) + vim.keymap.set("n", "gD", vim.lsp.buf.declaration) + vim.keymap.set("n", "gO", require("telescope.builtin").lsp_document_symbols) + vim.keymap.set("n", "gW", require("telescope.builtin").lsp_dynamic_workspace_symbols) + vim.keymap.set("n", "<leader>D", require("telescope.builtin").lsp_type_definitions) + + local highlight_augroup = vim.api.nvim_create_augroup("lsp-highlight", { clear = false }) + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.document_highlight, + }) + + vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { + buffer = event.buf, + group = highlight_augroup, + callback = vim.lsp.buf.clear_references, + }) + + vim.api.nvim_create_autocmd("LspDetach", { + group = vim.api.nvim_create_augroup("lsp-detach", { clear = true }), + callback = function(event2) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds({ group = "lsp-highlight", buffer = event2.buf }) + end, + }) + + vim.keymap.set("n", "<leader>th", function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf })) + end) + end, + }) + + vim.diagnostic.config({ + severity_sort = true, + float = { border = "rounded", source = "if_many" }, + underline = { severity = vim.diagnostic.severity.ERROR }, + signs = vim.g.have_nerd_font and { + text = { + [vim.diagnostic.severity.ERROR] = " ", + [vim.diagnostic.severity.WARN] = " ", + [vim.diagnostic.severity.INFO] = " ", + [vim.diagnostic.severity.HINT] = " ", + }, + } or {}, + virtual_text = { + source = "if_many", + spacing = 2, + format = function(diagnostic) + local diagnostic_message = { + [vim.diagnostic.severity.ERROR] = diagnostic.message, + [vim.diagnostic.severity.WARN] = diagnostic.message, + [vim.diagnostic.severity.INFO] = diagnostic.message, + [vim.diagnostic.severity.HINT] = diagnostic.message, + } + return diagnostic_message[diagnostic.severity] + end, + }, + }) + + local capabilities = require("blink.cmp").get_lsp_capabilities() + local servers = { + lua_ls = { + settings = { + Lua = { + completion = { + callSnippet = "Replace", + }, + }, + }, + }, + ts_ls = {}, + } + + local ensure_installed = vim.tbl_keys(servers or {}) + vim.list_extend(ensure_installed, { + "stylua", + "prettier", + "prettierd", + "eslint_d", + }) + require("mason-tool-installer").setup({ ensure_installed = ensure_installed }) + + require("mason-lspconfig").setup({ + ensure_installed = {}, + automatic_installation = false, + handlers = { + function(server_name) + local server = servers[server_name] or {} + server.capabilities = vim.tbl_deep_extend("force", {}, capabilities, server.capabilities or {}) + require("lspconfig")[server_name].setup(server) + end, + }, + }) + end, + }, + + { + "stevearc/conform.nvim", + event = { "BufWritePre" }, + cmd = { "ConformInfo" }, + keys = { + { + "<leader>gf", + function() + require("conform").format({ async = true, lsp_format = "fallback" }) + end, + mode = "", + }, + }, + opts = { + notify_on_error = true, + format_on_save = { + timeout_ms = 500, + lsp_format = "fallback", + }, + formatters_by_ft = { + lua = { "stylua" }, + javascript = { "prettierd", "prettier", stop_after_first = true }, + typescript = { "prettierd", "prettier", stop_after_first = true }, + }, + }, + }, + + { + "saghen/blink.cmp", + event = "VimEnter", + version = "1.*", + dependencies = { + { + "L3MON4D3/LuaSnip", + version = "2.*", + dependencies = {}, + opts = {}, + }, + }, + opts = { + sources = { + default = { "lsp", "path", "snippets", "buffer" }, + }, + }, + }, +} |