local Lsp = {} Lsp.setup = function() local luasnip = require("luasnip") local cmp = require("cmp") local has_words_before = function() if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then return false end local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil end cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, window = { completion = cmp.config.window.bordered(), documentation = cmp.config.window.bordered(), }, mapping = { [""] = function() if luasnip.jumpable(-1) then luasnip.jump(-1) else cmp.mapping.select_prev_item() end end, [""] = function() if luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else cmp.mapping.select_next_item() end end, [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete(), [""] = cmp.mapping.close(), [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true, }), [""] = function(fallback) if cmp.visible() and has_words_before() then cmp.select_next_item() else fallback() end end, [""] = function(fallback) if cmp.visible() and has_words_before() then cmp.select_prev_item() else fallback() end end, }, sources = { { name = "copilot", group_index = 2 }, { name = "nvim_lsp", group_index = 2 }, { name = "luasnip", group_index = 2 }, }, }) vim.o.completeopt = "menuone,noselect" vim.o.updatetime = 250 vim.cmd([[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]]) vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { virtual_text = { source = "if_many", }, }) vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { border = "rounded" }) vim.diagnostic.config({ float = { border = "rounded", zindex = 1 }, }) end Lsp.setup()