diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..de94759 --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,127 @@ +local lsp_servers = { + "lua_ls", + -- "nil_ls", -- nix + "rust_analyzer", + "gopls", + "pyright", + "bashls", + "ts_ls", + "marksman", + } + +return { + "neovim/nvim-lspconfig", + dependencies = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "hrsh7th/nvim-cmp", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "j-hui/fidget.nvim", + }, + + config = function() + -- Add additional capabilities supported by nvim-cmp + + + +local capabilities = require("cmp_nvim_lsp").default_capabilities() + +local lspconfig = require('lspconfig') + require("fidget").setup({}) + require("mason").setup() + require("mason-lspconfig").setup({ + ensure_installed = lsp_servers + }) + +-- Enable some language servers with the additional completion capabilities offered by nvim-cmp +local servers = lsp_servers +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + -- on_attach = my_custom_on_attach, + capabilities = capabilities, + } +end + + -- configure lua server (with special settings) + lspconfig["lua_ls"].setup({ + capabilities = capabilities, + on_attach = on_attach, + settings = { -- custom settings for lua + Lua = { + -- make the language server recognize "vim" global + diagnostics = { + globals = { "vim" }, + }, + workspace = { + -- make language server aware of runtime files + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, + }) + + lspconfig["pyright"].setup({ + capabilities = capabilities, + filetypes = {"python"}, + }) + +-- luasnip setup +local luasnip = require 'luasnip' + +-- nvim-cmp setup +local cmp = require 'cmp' +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + ['gd'] = vim.lsp.buf.definition(), -- Up + [''] = cmp.mapping.scroll_docs(-4), -- Up + [''] = cmp.mapping.scroll_docs(4), -- Down + -- C-b (back) C-f (forward) for snippet placeholder navigation. + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's' }), + }), + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + { name = "buffer" }, + }, +} +vim.keymap.set('n', "gd", vim.lsp.buf.definition, { silent = true }) + + + + end +}