From 9bbe0077104e5e0dab8b1a8f197f7ce9bb240be4 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 7 Nov 2023 13:39:23 +0100 Subject: nvim: Make LSP config more minimal --- .config/nvim/after/plugin/lsp.lua | 84 +++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 39 deletions(-) (limited to '.config/nvim/after/plugin/lsp.lua') diff --git a/.config/nvim/after/plugin/lsp.lua b/.config/nvim/after/plugin/lsp.lua index dcf98f1..12e1025 100644 --- a/.config/nvim/after/plugin/lsp.lua +++ b/.config/nvim/after/plugin/lsp.lua @@ -1,40 +1,46 @@ -local lsp = require('lsp-zero') -local lib = require('mango.lib') - -lsp.preset('recommended') -lsp.ensure_installed({ - 'clangd', - 'gopls', - 'rust_analyzer', -}) - -lsp.nvim_workspace() - -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(), -}) - -lsp.set_preferences({ - suggest_lsp_servers = false, - sign_icons = {} +local conf = require('lspconfig') + +conf.clangd.setup {} +conf.gopls.setup {} +conf.rust_analyzer.setup {} +conf.lua_ls.setup { + settings = { + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + globals = { + 'vim', + 'require', + }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file('', true), + }, + telemetry = { + enable = false, + }, + }, + }, +} + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('MangoLspConfig', {}), + callback = function(ev) + local function remap(mode, map, fn) + vim.keymap.set(mode, map, fn, { buffer = ev.buf }) + end + + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + remap('n', 'K', vim.lsp.buf.hover) + remap('n', 'gd', vim.lsp.buf.definition) + remap('n', 'gi', vim.lsp.buf.implementation) + remap('n', 'gr', vim.lsp.buf.rename) + remap('n', 'gt', vim.lsp.buf.type_definition) + remap('n', 'g=', function() vim.lsp.buf.format { async = true } end) + remap('n', ']d', vim.diagnostic.goto_prev) + remap('n', '[d', vim.diagnostic.goto_next) + remap('n', 'la', vim.lsp.buf.code_action) + end, }) - -lsp.setup_nvim_cmp({ - mapping = cmp_mappings -}) - -lsp.on_attach(function(_, bufnr) - local opts = { buffer = bufnr, remap = false } - - lib.remap('n', 'gd', vim.lsp.buf.definition, opts) - lib.remap('n', 'la', vim.lsp.buf.code_action, opts) - lib.remap('n', 'lr', vim.lsp.buf.rename, opts) - lib.remap('n', 'l=', vim.lsp.buf.format, opts) -end) - -lsp.setup() -- cgit v1.2.3