return { "neoclide/coc.nvim", branch = "release", config = function() -- Completion support and diagnostics vim.cmd("set completeopt=menuone,noinsert,noselect") -- Diagnostics settings vim.cmd("set updatetime=300") vim.cmd('autocmd CursorHold * silent! CocAction("diagnosticRefresh")') -- Snippet support vim.g.coc_user_snippets = vim.fn.expand("~/.config/nvim/snippets") -- Signature help (popup) vim.cmd('autocmd CursorHold,CursorHoldI * silent! CocAction("showSignatureHelp")') -- Enable some coc extensions vim.g.coc_global_extensions = { "coc-snippets", -- Snippets support "coc-pyright", -- Python LSP "coc-tsserver", -- JavaScript/TypeScript LSP "coc-json", -- JSON LSP "coc-html", -- HTML LSP "coc-css", -- CSS LSP "coc-lua", -- Lua LSP "coc-diagnostic", -- Diagnostics "coc-syntax", -- Syntax highlighting "coc-eslint", -- ESLint (null-ls replacement for JS/TS) "coc-prettier", -- Prettier formatting "coc-java", } -------------- -- KEYBINDS -- -------------- local keymap = vim.keymap local opts = { noremap = true, silent = true, desc = "" } vim.opt.signcolumn = 'yes' -- LSP actions opts.desc = "Jump to previous diagnostics" keymap.set("n", "[d", "(coc-diagnostic-prev)", opts) opts.desc = "Jump to next diagnostics" keymap.set("n", "]d", "(coc-diagnostic-next)", opts) opts.desc = "Show LSP references" keymap.set("n", "gR", "CocAction('editor.action.showReferences')", opts) opts.desc = "Go to declaration" keymap.set("n", "gD", ":CocCommand editor.action.goToDeclaration", opts) opts.desc = "Show LSP definitions" keymap.set("n", "gd", "CocAction('editor.action.goToDefinition')", opts) opts.desc = "Show LSP implementations" keymap.set("n", "gi", "CocAction('editor.action.goToImplementation')", opts) opts.desc = "Show LSP type definitions" keymap.set("n", "gt", "CocAction('editor.action.goToTypeDefinition')", opts) opts.desc = "See available code actions" keymap.set({ "n", "v" }, "ca", "CocAction('editor.action.quickFix')", opts) opts.desc = "Format current file" keymap.set("n", "gf", "CocCommand editor.action.formatDocument", opts) opts.desc = "Smart rename" keymap.set("n", "n", "CocCommand editor.action.rename", opts) opts.desc = "Show buffer diagnostics" keymap.set("n", "ga", "CocList diagnostics", opts) opts.desc = "Show line diagnostics" keymap.set("n", "gA", "CocAction('diagnostic.showLineDiagnostics')", opts) opts.desc = "Go to previous diagnostic" keymap.set("n", "[d", "CocAction('diagnostic.gotoPrev')", opts) opts.desc = "Go to next diagnostic" keymap.set("n", "]d", "CocAction('diagnostic.gotoNext')", opts) opts.desc = "Show documentation for what is under cursor" keymap.set("n", "k", "CocAction('editor.action.showHover')", opts) opts.desc = "Restart LSP" keymap.set("n", "rs", "CocRestart", opts) -- CMP replacement -- Mapping for next suggestion opts.desc = "Next suggestion" vim.keymap.set("i", "", "coc#select_next()", opts) -- Mapping for previous suggestion opts.desc = "Previous suggestion" vim.keymap.set("i", "", "coc#select_prev()", opts) -- Mapping for scrolling documentation forward opts.desc = "Scroll docs forward" vim.keymap.set("i", "", "CocScrollFloat -4", opts) -- Mapping for scrolling documentation backward opts.desc = "Scroll docs back" vim.keymap.set("i", "", "CocScrollFloat 4", opts) -- Mapping to show completion suggestions opts.desc = "Show completion suggestions" vim.keymap.set("i", "", "=coc#refresh()", opts) -- Mapping for Tab key (with snippet expansion and fallback) opts.desc = "Complete or expand snippet" keymap.set('i', '', 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh()', opts) -- Mapping for jumping to the next placeholder in snippets opts.desc = "Jump to next placeholder in snippet" vim.keymap.set("i", "", function() if vim.fn["coc#snippets#jumpable"]() == 1 then vim.fnkeys(vim.api.nvim_replace_termcodes("", true, true, true), "n") end end, opts) -- Mapping for jumping to the previous placeholder in snippets opts.desc = "Jump to previous placeholder in snippet" vim.keymap.set("i", "", function() if vim.fn["coc#snippets#jumpable"]() == 1 then vim.fn["coc#snippets#jump"](-1) else vim.fn.feedkeys(vim.api.nvim_replace_termcodes("", true, true, true), "n") end end, opts) end, }