From c9ca8a09dc3a5e421c50dc3cfa16c573a3e87135 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 1 Nov 2026 22:51:04 +0200 Subject: feat(nvim): Implement nvim config Latest version from https://git.syndamia.com/conf/anderson (and formerly https://gitlab.com/Syndamia/anderson). Not edited in 7 months. --- nvim/.nvim/lua/plugins/lsp.lua | 138 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 nvim/.nvim/lua/plugins/lsp.lua (limited to 'nvim/.nvim/lua/plugins/lsp.lua') diff --git a/nvim/.nvim/lua/plugins/lsp.lua b/nvim/.nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..176bd84 --- /dev/null +++ b/nvim/.nvim/lua/plugins/lsp.lua @@ -0,0 +1,138 @@ +-- Thanks https://stackoverflow.com/a/70760302/12036073 +vim.o.updatetime = 600 +vim.diagnostic.config({ + virtual_text = false, + float = { focus = false }, +}) +vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { callback = function(ev) + vim.diagnostic.open_float(nil) +end}) + +return { + -- Syntax parsing (for highlighting) + { + "nvim-treesitter/nvim-treesitter", + branch = "master", + lazy = false, + build = ":TSUpdate", + opts = { + ensure_installed = "all", + ignore_install = { "liquidsoap", "tlaplus", "yaml", "ipkg" }, -- Can't compile + highlight = { enable = true }, + incremental_selection = { enable = true }, + textobjects = { enable = true }, + }, + config = function(_, opts) + require("nvim-treesitter.configs").setup(opts) + end, + }, + -- LSP server utilisation + { + "neovim/nvim-lspconfig", + dependencies = { 'VonHeikemen/lsp-zero.nvim', 'williamboman/mason-lspconfig.nvim' }, + lazy = false, + opts = { -- :h lspconfig-all + -- awk_ls = { }, + bashls = { }, + lua_ls = { }, + rust_analyzer = { }, + }, + config = function(_, opts) + for k,v in pairs(opts) do + vim.lsp.config(k, v) + end + end, + }, + -- Auto-completion + { + 'hrsh7th/cmp-nvim-lsp', + config = true, + lazy = true + }, + { + 'hrsh7th/nvim-cmp', + dependencies = { 'hrsh7th/vim-vsnip' }, + lazy = false, + opts = { + sources = { { name = 'nvim_lsp' } }, + snippet = { + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) + end, + }, + }, + config = function(_, opts) + local cmp = require('cmp') + opts.mapping = cmp.mapping.preset.insert({ + -- -- `Enter` key to confirm completion + [''] = cmp.mapping.confirm({select = false}), + -- + -- -- Ctrl+Space to trigger completion menu + [''] = cmp.mapping.complete(), + -- + -- -- Navigate between snippet placeholder + -- [''] = cmp_action.vim_snippet_jump_forward(), + -- [''] = cmp_action.vim_snippet_jump_backward(), + -- + -- -- Scroll up and down in the completion documentation + -- [''] = cmp.mapping.scroll_docs(-4), + -- [''] = cmp.mapping.scroll_docs(4), + }) + cmp.setup(opts) + end, + }, + -- Helper functions + { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v3.x', + lazy = true, + dependencies = { 'hrsh7th/cmp-nvim-lsp' }, + opts = { + sign_text = true, + capabailities = "", + lsp_attach = function(event) + local opts = { silent = true, buffer = event.buf } + + 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, + }, + config = function(_, opts) + opts.capabilities = require('cmp_nvim_lsp').default_capabilities() + vim.api.nvim_create_autocmd('LspAttach', { + desc = 'Lsp Actions', + callback = opts.lsp_attach, + }) + require("lsp-zero").extend_lspconfig(opts) + end, + }, + -- Download plugins automatically + { + 'williamboman/mason-lspconfig.nvim', + dependencies = { 'neovim/nvim-lspconfig' }, + lazy = true, + opts = { + automatic_installation = true, + handlers = { + function(server_name) + vim.lsp.config(server_name, {}) + end, + }, + }, + }, + { + 'williamboman/mason.nvim', + lazy = false, + opts = { + PATH = "append", + }, + }, +} -- cgit v1.3.1-26-gb76a