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 local cmp = require("cmp") cmp.setup({ snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. end, }, mapping = { [""] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. [""] = 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() -- The fallback function sends a already mapped key. In this case, it's probably ``. end end, { "i", "s" }), [""] = cmp.mapping(function() if cmp.visible() then cmp.select_prev_item() elseif vim.fn["vsnip#jumpable"](-1) == 1 then feedkey("(vsnip-jump-prev)", "") end end, { "i", "s" }), }, sources = cmp.config.sources({ { name = "nvim_lsp" }, { name = "vsnip" }, -- For vsnip users. }, { { name = "buffer" }, }), }) local capabilities = require("cmp_nvim_lsp").default_capabilities() --nvim-cmp require("lspconfig")["golangci_lint_ls"].setup({ on_attach = common_lsp_on_attach, flags = common_lsp_flags, }) util = require("lspconfig/util") require("lspconfig")["gopls"].setup({ cmd = { "gopls" }, filetypes = { "go", "gomod" }, root_dir = util.root_pattern("go.work", "go.mod", ".git"), on_attach = common_lsp_on_attach, flags = common_lsp_flags, capabilities = capabilities, settings = { gopls = { experimentalPostfixCompletions = true, analyses = { unusedparams = true, shadow = true, }, staticcheck = true, }, }, init_options = { usePlaceholders = true }, })