From bb2e30b412c23b76ae876e792398f4926467d962 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 8 Jan 2025 15:45:00 -0800 Subject: added current config --- nvim/lua/plugins/lsp.lua | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 nvim/lua/plugins/lsp.lua (limited to 'nvim/lua/plugins/lsp.lua') diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..e33925e --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,100 @@ +return +{ + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + dependencies = { + -- LSP Support + {'neovim/nvim-lspconfig'}, + {'williamboman/mason.nvim'}, + {'williamboman/mason-lspconfig.nvim'}, + {'folke/todo-comments.nvim'}, -- doesn't load for some reason + + -- Autocompletion + {'hrsh7th/nvim-cmp'}, + {'hrsh7th/cmp-nvim-lsp'}, + {'hrsh7th/cmp-buffer'}, + {'hrsh7th/cmp-path'}, + {'saadparwaiz1/cmp_luasnip'}, + {'hrsh7th/cmp-nvim-lua'}, + + -- Snippets + {'L3MON4D3/LuaSnip'}, + {'rafamadriz/friendly-snippets'}, + }, + + config = function() + local lsp_zero = require('lsp-zero') + + lsp_zero.on_attach(function(client, bufnr) + -- see :help lsp-zero-keybindings + -- to learn the available actions + lsp_zero.default_keymaps({buffer = bufnr}) + + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + end) + + -- to learn how to use mason.nvim with lsp-zero + -- read this: https://github.com/VonHeikemen/lsp-zero.nvim/blob/v3.x/doc/md/guides/integrate-with-mason-nvim.md + require('mason').setup({}) + require('mason-lspconfig').setup({ + ensure_installed = { + 'lua_ls', + 'clangd', + 'texlab', + }, + handlers = { + lsp_zero.default_setup, + }, + }) + + -- Setup completion + local cmp = require('cmp') + local cmp_action = lsp_zero.cmp_action() + + cmp.setup({ + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.confirm({select = false}), + [''] = cmp.mapping.complete(), + [''] = cmp_action.luasnip_jump_forward(), + [''] = cmp_action.luasnip_jump_backward(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + }), + snippet = { + expand = function(args) + -- You need Neovim v0.10 to use vim.snippet + vim.snippet.expand(args.body) + end, + }, + }) + + require('lspconfig').lua_ls.setup({ + capabilities = lsp_capabilities, + settings = { + Lua = { + runtime = { + version = 'LuaJIT' + }, + diagnostics = { + globals = {'vim'}, + disable = { 'unused-function' }, + }, + workspace = { + library = { + vim.env.VIMRUNTIME, + } + } + } + } + }) + + + end + +} -- cgit v1.2.3