From 8c8fe059c935312c8a62361c823de04491094b91 Mon Sep 17 00:00:00 2001 From: speedie Date: Sun, 28 Jan 2024 02:04:41 +0100 Subject: [PATCH] speedie-nvim | Add new config --- .config/nvim/init.lua | 4 -- .config/nvim/lua/lsp_config.lua | 101 +++++++++++++++++++++++++++++--- install.ps1 | 0 3 files changed, 92 insertions(+), 13 deletions(-) mode change 100644 => 100755 install.ps1 diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 6a4f89b..10a1b48 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -57,10 +57,6 @@ Plugins = { -- Plugins to use { 'williamboman/mason.nvim', dependencies = { 'williamboman/mason-lspconfig.nvim', - }, - }, -- Server auto-install - { 'VonHeikemen/lsp-zero.nvim', branch = 'v3.x', - dependencies = { 'neovim/nvim-lspconfig', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/nvim-cmp', diff --git a/.config/nvim/lua/lsp_config.lua b/.config/nvim/lua/lsp_config.lua index 8fde1ca..82ad960 100644 --- a/.config/nvim/lua/lsp_config.lua +++ b/.config/nvim/lua/lsp_config.lua @@ -3,15 +3,98 @@ -- https://git.speedie.site/speedie/speedie-nvim -- ]]-- -if vim.fn.has('nvim-0.8') == 1 or vim.fn.has('nvim-0.9') == 1 or vim.fn.has('nvim-1') == 1 then - local lsp_zero = require('lsp-zero') - lsp_zero.on_attach(function(client, bufnr) lsp_zero.default_keymaps({buffer = bufnr}) end) +local kindIcons = { + Text = "󰉿", + Method = "󰆧", + Function = "󰊕", + Constructor = "", + Field = "󰜢", + Variable = "󰀫", + Class = "󰠱", + Interface = "", + Module = "", + Property = "󰜢", + Unit = "󰑭", + Value = "󰎠", + Enum = "", + Keyword = "󰌋", + Snippet = "", + Color = "󰏘", + File = "󰈙", + Reference = "󰈇", + Folder = "󰉋", + EnumMember = "", + Constant = "󰏿", + Struct = "󰙅", + Event = "", + Operator = "󰆕", + TypeParameter = "", +} - require('mason').setup({}) +vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function(event) + local opts = { buffer = event.buf } - if next(LanguageServers) == nil then - require('mason-lspconfig').setup({handlers = { lsp_zero.default_setup }}) - else - require('mason-lspconfig').setup({handlers = { lsp_zero.default_setup }, ensure_installed = LanguageServers}) - end + 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) + vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set({'n', 'x'}, '', 'lua vim.lsp.buf.format({async = true})', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) + end +}) + +local defaultSetup = function(server) + require('lspconfig')[server].setup({ + capabilities = require('cmp_nvim_lsp').default_capabilities(), + }) end + +require('mason').setup({}) + +if next(LanguageServers) == nil then + require('mason-lspconfig').setup({handlers = { defaultSetup }}) +else + require('mason-lspconfig').setup({handlers = { defaultSetup }, ensure_installed = LanguageServers}) +end + +local cmp = require('cmp') + +cmp.setup({ + sources = { + { name = 'nvim_lsp' }, + }, + + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.confirm({select = true}), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.confirm({select = true}), + }), + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + formatting = { + format = function(entry, vim_item) + vim_item.kind = string.format('%s %s', kindIcons[vim_item.kind], vim_item.kind) + vim_item.menu = ({ + buffer = "Buffer", + nvim_lsp = "LSP", + luasnip = "LuaSnip", + nvim_lua = "Lua", + latex_symbols = "LaTeX", + })[entry.source.name] + + return vim_item + end, + }, + experimental = { + ghost_text = true, + }, +}) diff --git a/install.ps1 b/install.ps1 old mode 100644 new mode 100755