|
| 1 | +return { |
| 2 | + { |
| 3 | + 'neoclide/coc.nvim', |
| 4 | + branch = 'release', |
| 5 | + init = function() |
| 6 | + vim.g.coc_global_extensions = { |
| 7 | + 'coc-tsserver', |
| 8 | + 'coc-eslint', |
| 9 | + 'coc-prettier', |
| 10 | + 'coc-json', |
| 11 | + 'coc-pyright', |
| 12 | + 'coc-go', |
| 13 | + 'coc-rust-analyzer', |
| 14 | + } |
| 15 | + |
| 16 | + local map = function(mode, lhs, rhs, desc, opts) |
| 17 | + opts = opts or {} |
| 18 | + opts.silent = opts.silent ~= false |
| 19 | + opts.remap = opts.remap ~= false |
| 20 | + opts.desc = desc |
| 21 | + vim.keymap.set(mode, lhs, rhs, opts) |
| 22 | + end |
| 23 | + |
| 24 | + local term = function(keys) |
| 25 | + return vim.api.nvim_replace_termcodes(keys, true, false, true) |
| 26 | + end |
| 27 | + |
| 28 | + local delete_keyword_suffix = function() |
| 29 | + local line = vim.api.nvim_get_current_line() |
| 30 | + local col = vim.fn.col '.' |
| 31 | + local suffix_len = 0 |
| 32 | + |
| 33 | + local i = col |
| 34 | + while i <= #line do |
| 35 | + local ch = line:sub(i, i) |
| 36 | + if ch:match '[%w_]' then |
| 37 | + suffix_len = suffix_len + 1 |
| 38 | + i = i + 1 |
| 39 | + else |
| 40 | + break |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + if suffix_len == 0 then |
| 45 | + return '' |
| 46 | + end |
| 47 | + |
| 48 | + return string.rep(term '<Del>', suffix_len) |
| 49 | + end |
| 50 | + |
| 51 | + map('n', 'gd', '<Plug>(coc-definition)', 'Goto definition') |
| 52 | + map('n', 'gD', '<Plug>(coc-declaration)', 'Goto declaration') |
| 53 | + map('n', 'gI', '<Plug>(coc-implementation)', 'Goto implementation') |
| 54 | + map('n', 'gr', '<Plug>(coc-references)', 'Goto references') |
| 55 | + map('n', '<leader>rn', '<Plug>(coc-rename)', 'Rename') |
| 56 | + map('n', '<leader>ca', '<Plug>(coc-codeaction)', 'Code action') |
| 57 | + map('x', '<leader>ca', '<Plug>(coc-codeaction-selected)', 'Code action (selection)') |
| 58 | + map('n', '<leader>D', '<Plug>(coc-type-definition)', 'Type definition') |
| 59 | + map('n', '<leader>ds', '<cmd>CocList outline<cr>', 'Document symbols', { remap = false }) |
| 60 | + map('n', '<leader>ws', '<cmd>CocList -I symbols<cr>', 'Workspace symbols', { remap = false }) |
| 61 | + |
| 62 | + map('n', 'K', function() |
| 63 | + if vim.fn.exists '*CocActionAsync' == 1 then |
| 64 | + vim.fn.CocActionAsync 'doHover' |
| 65 | + else |
| 66 | + vim.cmd 'normal! K' |
| 67 | + end |
| 68 | + end, 'Hover') |
| 69 | + |
| 70 | + map('n', '<C-k>', '<Plug>(coc-signature-help)', 'Signature help') |
| 71 | + |
| 72 | + -- Completion: IntelliJ-like acceptance |
| 73 | + -- - Enter: accept with "insert" behavior (doesn't overwrite suffix) |
| 74 | + -- - Tab: accept with "replace" behavior (delete suffix, then confirm) |
| 75 | + vim.keymap.set('i', '<CR>', [[coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"]], { |
| 76 | + silent = true, |
| 77 | + expr = true, |
| 78 | + }) |
| 79 | + |
| 80 | + vim.keymap.set('i', '<Tab>', function() |
| 81 | + if vim.fn['coc#pum#visible']() == 1 then |
| 82 | + return delete_keyword_suffix() .. vim.fn['coc#pum#confirm']() |
| 83 | + end |
| 84 | + return term '<Tab>' |
| 85 | + end, { silent = true, expr = true }) |
| 86 | + |
| 87 | + vim.keymap.set('i', '<S-Tab>', function() |
| 88 | + if vim.fn['coc#pum#visible']() == 1 then |
| 89 | + return vim.fn['coc#pum#prev'](1) |
| 90 | + end |
| 91 | + return term '<S-Tab>' |
| 92 | + end, { silent = true, expr = true }) |
| 93 | + |
| 94 | + vim.keymap.set('i', '<C-n>', function() |
| 95 | + if vim.fn['coc#pum#visible']() == 1 then |
| 96 | + return vim.fn['coc#pum#next'](1) |
| 97 | + end |
| 98 | + vim.fn['coc#refresh']() |
| 99 | + return '' |
| 100 | + end, { silent = true, expr = true }) |
| 101 | + |
| 102 | + vim.keymap.set('i', '<C-p>', function() |
| 103 | + if vim.fn['coc#pum#visible']() == 1 then |
| 104 | + return vim.fn['coc#pum#prev'](1) |
| 105 | + end |
| 106 | + vim.fn['coc#refresh']() |
| 107 | + return '' |
| 108 | + end, { silent = true, expr = true }) |
| 109 | + |
| 110 | + map('n', '<leader>f', function() |
| 111 | + if vim.fn.exists '*CocActionAsync' == 1 then |
| 112 | + vim.fn.CocActionAsync 'format' |
| 113 | + return |
| 114 | + end |
| 115 | + if vim.fn.exists ':ALEFix' == 2 then |
| 116 | + vim.cmd 'ALEFix' |
| 117 | + end |
| 118 | + end, 'Format buffer', { remap = false }) |
| 119 | + |
| 120 | + vim.api.nvim_create_user_command('Format', function() |
| 121 | + if vim.fn.exists '*CocActionAsync' == 1 then |
| 122 | + vim.fn.CocActionAsync 'format' |
| 123 | + return |
| 124 | + end |
| 125 | + if vim.fn.exists ':ALEFix' == 2 then |
| 126 | + vim.cmd 'ALEFix' |
| 127 | + end |
| 128 | + end, { desc = 'Format current buffer (Coc/ALE)' }) |
| 129 | + end, |
| 130 | + }, |
| 131 | + { |
| 132 | + 'dense-analysis/ale', |
| 133 | + init = function() |
| 134 | + vim.g.ale_disable_lsp = 1 |
| 135 | + vim.g.ale_use_neovim_diagnostics_api = 1 |
| 136 | + vim.g.ale_completion_enabled = 0 |
| 137 | + |
| 138 | + vim.g.ale_fix_on_save = 1 |
| 139 | + vim.g.ale_fixers = { |
| 140 | + go = { 'gofmt', 'goimports' }, |
| 141 | + javascript = { 'eslint', 'prettier' }, |
| 142 | + typescript = { 'eslint', 'prettier' }, |
| 143 | + javascriptreact = { 'eslint', 'prettier' }, |
| 144 | + typescriptreact = { 'eslint', 'prettier' }, |
| 145 | + rust = { 'rustfmt' }, |
| 146 | + python = { 'isort', 'black' }, |
| 147 | + } |
| 148 | + |
| 149 | + vim.g.ale_linters = { |
| 150 | + go = { 'golangci-lint' }, |
| 151 | + javascript = { 'eslint' }, |
| 152 | + typescript = { 'eslint' }, |
| 153 | + javascriptreact = { 'eslint' }, |
| 154 | + typescriptreact = { 'eslint' }, |
| 155 | + rust = { 'clippy' }, |
| 156 | + python = { 'ruff' }, |
| 157 | + } |
| 158 | + |
| 159 | + local format_is_enabled = vim.g.ale_fix_on_save == 1 |
| 160 | + vim.api.nvim_create_user_command('ColdbootFormatToggle', function() |
| 161 | + format_is_enabled = not format_is_enabled |
| 162 | + vim.g.ale_fix_on_save = format_is_enabled and 1 or 0 |
| 163 | + print('Setting autoformatting to: ' .. tostring(format_is_enabled)) |
| 164 | + end, {}) |
| 165 | + end, |
| 166 | + }, |
| 167 | +} |
0 commit comments