local cmp_kinds = { Text = ' ', Method = ' ', Function = ' ', Constructor = ' ', Field = ' ', Variable = ' ', Class = ' ', Interface = ' ', Module = ' ', Property = ' ', Unit = ' ', Value = ' ', Enum = ' ', Keyword = ' ', Snippet = ' ', Color = ' ', File = ' ', Reference = ' ', Folder = ' ', EnumMember = ' ', Constant = ' ', Struct = ' ', Event = ' ', Operator = ' ', TypeParameter = ' ', } local border = { { "╭", "CmpBorder" }, { "─", "CmpBorder" }, { "╮", "CmpBorder" }, { "│", "CmpBorder" }, { "╯", "CmpBorder" }, { "─", "CmpBorder" }, { "╰", "CmpBorder" }, { "│", "CmpBorder" }, } function show_diagnostic() for _, winid in pairs(vim.api.nvim_tabpage_list_wins(0)) do if vim.api.nvim_win_get_config(winid).zindex then return end end -- THIS IS FOR BUILTIN LSP vim.diagnostic.open_float(0, { scope = "cursor", focusable = false, close_events = { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre", "WinLeave", }, }) end local has_words_before = function() local line, col = unpack(vim.api.nvim_win_get_cursor(0)) return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil end local feedkey = function(key, mode) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) end return { { 'VonHeikemen/lsp-zero.nvim', branch = 'v3.x', lazy = true, config = false, init = function() vim.g.lsp_zero_extend_cmp = 0 vim.g.lsp_zero_extend_lspconfig = 0 end, }, { 'williamboman/mason.nvim', lazy = false, config = true }, { 'hrsh7th/nvim-cmp', event = 'InsertEnter', dependencies = { 'L3MON4D3/LuaSnip', 'hrsh7th/cmp-vsnip', 'hrsh7th/vim-vsnip', 'onsails/lspkind.nvim', 'hrsh7th/cmp-nvim-lsp-signature-help' }, config = function() local lsp_zero = require('lsp-zero') lsp_zero.extend_cmp() local cmp = require('cmp') local cmp_action = lsp_zero.cmp_action() cmp.setup { --formatting = lsp_zero.cmp_format({ details = true }), formatting = { fields = { 'kind', 'abbr', 'menu' }, format = function(entry, vim_item) local lspkind = require('lspkind') local kind = lspkind.cmp_format({ mode = "symbol_text", maxwidth = 50 })(entry, vim_item) local strings = vim.split(kind.kind, "%s", { trimempty = true }) kind.kind = " " .. (strings[1] or "") .. " " kind.menu = " (" .. (strings[2] or "") .. ")" return kind end, }, sources = { { name = 'nvim_lsp' }, { name = 'vsnip' }, { name = 'neorg' }, { name = 'nvim_lsp_signature_help' } }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp_action.luasnip_jump_forward(), [''] = cmp_action.luasnip_jump_backward(), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif vim.fn["vsnip#available"](1) == 1 then feedkey("(vsnip-expand-or-jump)", "") --elseif has_words_before() then -- cmp.complete() else fallback() end end, { "i", "s" }), [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif vim.fn["vsnip#available"](1) == 1 then feedkey("(vsnip-jump-prev)", "") else fallback() end end, { "i", "s" }), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = false }), }), snippet = { expand = function(args) require('luasnip').lsp_expand(args.body) end }, sorting = { comparators = { cmp.config.compare.length, cmp.config.compare.offset, cmp.config.compare.exact, cmp.config.compare.score, cmp.config.compare.recently_used, cmp.config.compare.locality, cmp.config.compare.kind, cmp.config.compare.sort_text, cmp.config.compare.order, }, }, } end }, { 'neovim/nvim-lspconfig', cmp = { 'LspInfo', 'LspInstall', 'LspStart' }, event = { 'BufReadPre', 'BufNewFile' }, dependencies = { 'hrsh7th/cmp-nvim-lsp', 'williamboman/mason-lspconfig.nvim' }, config = function() local lsp_zero = require('lsp-zero') lsp_zero.extend_lspconfig() lsp_zero.on_attach(function(client, bufnr) lsp_zero.default_keymaps({ bufnr = bufnr }) end) local util = require('lspconfig.util') local capabilities = vim.tbl_deep_extend( 'force', vim.lsp.protocol.make_client_capabilities(), require('cmp_nvim_lsp').default_capabilities() ) capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = false vim.lsp.enable('clangd') vim.lsp.config('clangd', { root_dir = util.root_pattern('build'), capabilities = capabilities, init_options = { compilationDatabasePath = './build', highlight = { lsRanges = true } } }) vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("lsp", { clear = true }), callback = function (args) vim.api.nvim_create_autocmd("BufWritePre", { buffer = args.buf, callback = function () vim.lsp.buf.format { async = false, id = args.data.client_id } end, }) vim.api.nvim_create_autocmd("CursorHold", { pattern = '*', callback = show_diagnostic }) end }) end } }