-- 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", }, }, }