diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2024-05-26 00:45:53 -0400 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2024-05-26 00:45:53 -0400 |
commit | f03a8e53b88d7db5f5b52b2d5481cdad4fa40bf0 (patch) | |
tree | 50b18ab66d6fa8381f53b660641ad006c3f0ec97 /lua/plugins/lsp.lua | |
parent | 1cd0761d4a433f920d1d0fb25b27e9a6f0033ef1 (diff) |
NOW THE LSP IS COMFY!!! :)
Diffstat (limited to 'lua/plugins/lsp.lua')
-rw-r--r-- | lua/plugins/lsp.lua | 143 |
1 files changed, 114 insertions, 29 deletions
diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index aafd16e..ccd25a0 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -1,34 +1,119 @@ return { - "neovim/nvim-lspconfig", - dependencies = { - { - "nvim-telescope/telescope.nvim" + { + "williamboman/mason.nvim", + dependencies = { + "williamboman/mason-lspconfig.nvim", }, - { - "hrsh7th/nvim-cmp", - dependencies = { - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - }, - } + config = function() + local mason = require('mason') + local mlsp = require('mason-lspconfig') + mason.setup({ + ui = { + icons = { + package_installed = "", + package_not_installed = "", + package_pending = "", + } + } + }) + -- Global so it can be used by both mason and lspconfig ;) + local myServers = { + "gopls", + "lua_ls", + "bashls", + "graphql", + "rust_analyzer", + } + mlsp.setup({ + ensure_installed = myServers, + automatic_installation = false, + }) + end, }, - lazy=false, - config = function() - telescope = require('telescope') - require("lspconfig").gopls.setup{ - on_attach = function() - vim.keymap.set("n", "K", vim.lsp.buf.hover, {buffer=0}) - vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, {buffer=0}) - vim.keymap.set("n", "gd", vim.lsp.buf.definition, {buffer=0}) - vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, {buffer=0}) - vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {buffer=0}) - vim.keymap.set("n", "<leader>fa", vim.lsp.buf.code_action, {buffer=0}) - vim.keymap.set("n", "<leader>fn", vim.diagnostic.goto_next, {buffer=0}) - vim.keymap.set("n", "<leader>fp", vim.diagnostic.goto_prev, {buffer=0}) - - -- like "K" but for diagnostics - vim.keymap.set("n", "S", vim.diagnostic.open_float, {buffer=0}) + { + "neovim/nvim-lspconfig", + dependencies = { + "hrsh7th/nvim-cmp", + "hrsh7th/cmp-nvim-lsp", + "nvim-telescope/telescope.nvim", + }, + config = function() + + -- Use icons in the sidebar + local signs = { Error="", Warn ="", Hint ="", Info ="" } + for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, {text = icon, texthl = hl, numhl = ""}) end - } - end, + -- Hide inline virtual text and use only the icons for debbuging/tips + vim.diagnostic.config({ + virtual_text = false, + signs = true, + underline = true + }) + + local lsp = require('lspconfig') + local lspCaps = require('cmp_nvim_lsp').default_capabilities() + local lspMaps = function() + + vim.keymap.set("n", "K", vim.lsp.buf.hover, {buffer=0, + desc = "Show object description on hover"}) + + vim.keymap.set("n", "<leader>r", vim.lsp.buf.rename, {buffer=0, + desc = "Rename object across all occurences"}) + + vim.keymap.set("n", "gd", vim.lsp.buf.definition, {buffer=0, + desc = "Go to the location where the object is defined"}) + + vim.keymap.set("n", "gt", vim.lsp.buf.type_definition, {buffer=0, + desc = "Go to the definition of the objects type"}) + + vim.keymap.set("n", "gi", vim.lsp.buf.implementation, {buffer=0, + desc = "Go to the method implementation"}) + + vim.keymap.set("n", "<leader>fa", vim.lsp.buf.code_action, {buffer=0, + desc = ""}) + vim.keymap.set("n", "]d", vim.diagnostic.goto_next, {buffer=0, + desc = "Go to the next diagnostic/issue"}) + + vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, {buffer=0, + desc = "Go to the previous diagnostic/issue"}) + + vim.keymap.set("n", "H", vim.diagnostic.open_float, {buffer=0, + desc = "View diagnostics information in a floating window"}) + + end + + -- Configure every lsp installed and managed by mason + -- TODO: automate this with a global myServers table + lsp["gopls"].setup({ capabilities = lspCaps, on_attach = lspMaps }) + lsp["bashls"].setup({ capabilities = lspCaps, on_attach = lspMaps }) + lsp["graphql"].setup({ capabilities = lspCaps, on_attach = lspMaps }) + lsp["rust_analyzer"].setup({ capabilities = lspCaps, on_attach = lspMaps }) + -- Non standard language settings: + lsp.lua_ls.setup({ + capabilities = lspCaps, + on_attach = lspMaps, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using + -- -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT' + }, + diagnostic = { + -- Get the language server to recognize the `vim` global + globals = { + 'vim', + 'require' + } + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + } + } + }) + end, + }, } |