From b47f21ba1b8be35ccc56bd4738084830c6ae072a Mon Sep 17 00:00:00 2001 From: saibotk Date: Fri, 16 Jun 2023 01:50:56 +0200 Subject: [PATCH] redo autocompletion setup --- nvim/lua/autocompletion.lua | 81 ++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 46 deletions(-) diff --git a/nvim/lua/autocompletion.lua b/nvim/lua/autocompletion.lua index 3a84ff5..eda2ded 100644 --- a/nvim/lua/autocompletion.lua +++ b/nvim/lua/autocompletion.lua @@ -10,8 +10,8 @@ cmp.setup({ mapping = { [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.select_next_item(), {'i','c'}), - [''] = cmp.mapping(cmp.mapping.select_prev_item(), {'i','c'}), + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. [''] = cmp.mapping({ @@ -26,42 +26,14 @@ cmp.setup({ { name = 'nvim_lsp', entry_filter = function(entry, ctx) return require('cmp.types').lsp.CompletionItemKind[entry:get_kind()] ~= 'Text' - end + end, }, { name = 'luasnip' }, - { name = 'buffer' }, - }) -}) - --- Use buffer source for `vimwiki` -cmp.setup.cmdline('vimwiki', { - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'buffer' } - } -}) - -cmp.setup.cmdline('md', { - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'buffer' } - } -}) - -cmp.setup.cmdline('tex', { - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - { name = 'buffer' } - } -}) - --- Use buffer source for `/` -cmp.setup.cmdline('/', { - sources = { - { name = 'buffer' } + { name = 'buffer', keyword_length = 5 }, + }), + experimental = { + native_menu = false, + ghost_text = true, } }) @@ -82,8 +54,7 @@ local on_attach = function(client, bufnr) local opts = { noremap = true, silent = true } buf_set_keymap("n", "gd", "Telescope lsp_definitions", opts) buf_set_keymap("n", "gD", "Telescope lsp_implementations", opts) - -- buf_set_keymap("n", "gr", "Telescope lsp_references", opts) - vim.keymap.set("n", "gf",vim.lsp.buf.format) + vim.keymap.set("n", "gf", vim.lsp.buf.format) vim.keymap.set("n", "gh", vim.lsp.buf.hover) vim.keymap.set("n", "ge", vim.diagnostic.open_float) vim.keymap.set("n", "gs", vim.lsp.buf.signature_help) @@ -91,16 +62,34 @@ local on_attach = function(client, bufnr) vim.keymap.set("n", "gH", vim.lsp.buf.code_action) end -local lsp_installer = require 'nvim-lsp-installer' -lsp_installer.on_server_ready(function(server) - local opts = {} - opts.on_attach = on_attach - opts.capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) +-- LSP INSTALLER +local lsp_installer = require "nvim-lsp-installer" +lsp_installer.setup { + automatic_installation = false, +} - server:setup(opts) - vim.cmd [[ do User LspAttachBuffers ]] -end) +local lspconfig = require "lspconfig" +for _, server in ipairs(lsp_installer.get_installed_servers()) do + lspconfig[server.name].setup { + on_attach = on_attach, + capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities()) + } +end + +-- EXTRA SETUP +lspconfig.sumneko_lua.setup { + settings = { + Lua = { + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { 'vim' }, + }, + }, + }, +} + +-- LSP SIGNATURE require "lsp_signature".setup { handler_opts = { border = "rounded"