135 lines
4.7 KiB
Lua
Executable File
135 lines
4.7 KiB
Lua
Executable File
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", "<Plug>(coc-diagnostic-prev)", opts)
|
|
|
|
opts.desc = "Jump to next diagnostics"
|
|
keymap.set("n", "]d", "<Plug>(coc-diagnostic-next)", opts)
|
|
|
|
opts.desc = "Show LSP references"
|
|
keymap.set("n", "gR", "<cmd>CocAction('editor.action.showReferences')<CR>", opts)
|
|
|
|
opts.desc = "Go to declaration"
|
|
keymap.set("n", "gD", ":CocCommand editor.action.goToDeclaration<CR>", opts)
|
|
|
|
opts.desc = "Show LSP definitions"
|
|
keymap.set("n", "gd", "<cmd>CocAction('editor.action.goToDefinition')<CR>", opts)
|
|
|
|
opts.desc = "Show LSP implementations"
|
|
keymap.set("n", "gi", "<cmd>CocAction('editor.action.goToImplementation')<CR>", opts)
|
|
|
|
opts.desc = "Show LSP type definitions"
|
|
keymap.set("n", "gt", "<cmd>CocAction('editor.action.goToTypeDefinition')<CR>", opts)
|
|
|
|
opts.desc = "See available code actions"
|
|
keymap.set({ "n", "v" }, "<leader>ca", "<cmd>CocAction('editor.action.quickFix')<CR>", opts)
|
|
|
|
opts.desc = "Format current file"
|
|
keymap.set("n", "<leader>gf", "<cmd>CocCommand editor.action.formatDocument<CR>", opts)
|
|
|
|
opts.desc = "Smart rename"
|
|
keymap.set("n", "<leader>n", "<cmd>CocCommand editor.action.rename<CR>", opts)
|
|
|
|
opts.desc = "Show buffer diagnostics"
|
|
keymap.set("n", "ga", "<cmd>CocList diagnostics<CR>", opts)
|
|
|
|
opts.desc = "Show line diagnostics"
|
|
keymap.set("n", "gA", "<cmd>CocAction('diagnostic.showLineDiagnostics')<CR>", opts)
|
|
|
|
opts.desc = "Go to previous diagnostic"
|
|
keymap.set("n", "[d", "<cmd>CocAction('diagnostic.gotoPrev')<CR>", opts)
|
|
|
|
opts.desc = "Go to next diagnostic"
|
|
keymap.set("n", "]d", "<cmd>CocAction('diagnostic.gotoNext')<CR>", opts)
|
|
|
|
opts.desc = "Show documentation for what is under cursor"
|
|
keymap.set("n", "<leader>k", "<cmd>CocAction('editor.action.showHover')<CR>", opts)
|
|
|
|
opts.desc = "Restart LSP"
|
|
keymap.set("n", "<leader>rs", "<cmd>CocRestart<CR>", opts)
|
|
|
|
-- CMP replacement
|
|
|
|
-- Mapping for next suggestion
|
|
opts.desc = "Next suggestion"
|
|
vim.keymap.set("i", "<C-j>", "<Cmd>coc#select_next()<CR>", opts)
|
|
|
|
-- Mapping for previous suggestion
|
|
opts.desc = "Previous suggestion"
|
|
vim.keymap.set("i", "<C-k>", "<Cmd>coc#select_prev()<CR>", opts)
|
|
|
|
-- Mapping for scrolling documentation forward
|
|
opts.desc = "Scroll docs forward"
|
|
vim.keymap.set("i", "<C-S-j>", "<Cmd>CocScrollFloat -4<CR>", opts)
|
|
|
|
-- Mapping for scrolling documentation backward
|
|
opts.desc = "Scroll docs back"
|
|
vim.keymap.set("i", "<C-S-k>", "<Cmd>CocScrollFloat 4<CR>", opts)
|
|
|
|
-- Mapping to show completion suggestions
|
|
opts.desc = "Show completion suggestions"
|
|
vim.keymap.set("i", "<C-Space>", "<C-r>=coc#refresh()<CR>", opts)
|
|
|
|
-- Mapping for Tab key (with snippet expansion and fallback)
|
|
opts.desc = "Complete or expand snippet"
|
|
keymap.set('i', '<TAB>', 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "<TAB>" : coc#refresh()', opts)
|
|
|
|
-- Mapping for jumping to the next placeholder in snippets
|
|
opts.desc = "Jump to next placeholder in snippet"
|
|
vim.keymap.set("i", "<C-p>", function()
|
|
if vim.fn["coc#snippets#jumpable"]() == 1 then
|
|
vim.fnkeys(vim.api.nvim_replace_termcodes("<Tab>", 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", "<C-S-p>", function()
|
|
if vim.fn["coc#snippets#jumpable"]() == 1 then
|
|
vim.fn["coc#snippets#jump"](-1)
|
|
else
|
|
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-P>", true, true, true), "n")
|
|
end
|
|
end, opts)
|
|
end,
|
|
}
|