diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 346a7ee5..02e40775 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,60 +1,88 @@ -local lsp = require("lsp-zero") +vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP keybindings', + callback = function(event) + local opts = {buffer = event.buf} -lsp.preset("recommended") - -lsp.ensure_installed({ - 'tsserver', - 'rust_analyzer', + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + end }) --- Fix Undefined global 'vim' -lsp.nvim_workspace() +local lspconfig = require('lspconfig') +local lsp_capabilities = require('cmp_nvim_lsp').default_capabilities() +require('mason').setup({}) +require('mason-lspconfig').setup({ + ensure_installed = { + 'tsserver', + 'lua_ls', + 'rust_analyzer', + }, + handlers = { + function(server) + lspconfig[server].setup({ + capabilities = lsp_capabilities, + }) + end, + lua_ls = function() + lspconfig.lua_ls.setup({ + capabilities = lsp_capabilities, + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + globals = {'vim'} + }, + workspace = { + library = { + vim.env.VIMRUNTIME, + } + } + } + } + }) + end + } +}) local cmp = require('cmp') local cmp_select = {behavior = cmp.SelectBehavior.Select} -local cmp_mappings = lsp.defaults.cmp_mappings({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [""] = cmp.mapping.complete(), -}) -cmp_mappings[''] = nil -cmp_mappings[''] = nil +--- loads custom snippets from friendly-snippets +-- require('luasnip.loaders.from_vscode').lazy_load() -lsp.setup_nvim_cmp({ - mapping = cmp_mappings +cmp.setup({ + sources = { + {name = 'path'}, + {name = 'nvim_lsp'}, + {name = 'nvim_lua'}, + -- {name = 'buffer', keyword_length = 3}, + -- {name = 'luasnip', keyword_length = 2}, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.complete(), + -- [''] = cmp.mapping.scroll_docs(-4), + -- [''] = cmp.mapping.scroll_docs(4), + }), + window = { + documentation = cmp.config.window.bordered(), + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, }) - -lsp.set_preferences({ - suggest_lsp_servers = false, - sign_icons = { - error = 'E', - warn = 'W', - hint = 'H', - info = 'I' - } -}) - -lsp.on_attach(function(client, bufnr) - local opts = {buffer = bufnr, remap = false} - - vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) - vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) - vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) - vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) - vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) - vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) - vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) - vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) - vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) -end) - -lsp.setup() - -vim.diagnostic.config({ - virtual_text = true -}) - diff --git a/lua/theprimeagen/packer.lua b/lua/theprimeagen/packer.lua index 96f7c6e1..3efc84d6 100644 --- a/lua/theprimeagen/packer.lua +++ b/lua/theprimeagen/packer.lua @@ -47,11 +47,9 @@ return require('packer').startup(function(use) use("nvim-treesitter/nvim-treesitter-context"); use { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v1.x', + 'neovim/nvim-lspconfig', requires = { -- LSP Support - {'neovim/nvim-lspconfig'}, {'williamboman/mason.nvim'}, {'williamboman/mason-lspconfig.nvim'},