Skip to content

Commit c6c4877

Browse files
committed
feat: add coc and ale configuration
Signed-off-by: Gamunu Balagalla <gamunu@fastcode.io>
1 parent 608ebf2 commit c6c4877

11 files changed

Lines changed: 319 additions & 411 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ You can also merge updates/changes from the repo back into your fork, to keep up
7878
### Docs
7979

8080
* [Git in Neovim (Neogit + Diffview)](doc/git.md)
81+
* [IDE setup (Coc.nvim + ALE)](doc/coc-ale.md)
8182

8283
#### Example: Adding an autopairs plugin
8384

coc-settings.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"diagnostic.displayByAle": true,
3+
"suggest.insertMode": "insert",
4+
"inlayHint.display": true,
5+
"inlayHint.enableParameter": true,
6+
"typescript.inlayHints.parameterNames.enabled": "all",
7+
"typescript.inlayHints.parameterTypes.enabled": true,
8+
"typescript.inlayHints.variableTypes.enabled": true,
9+
"typescript.inlayHints.propertyDeclarationTypes.enabled": true,
10+
"typescript.inlayHints.functionLikeReturnTypes.enabled": true,
11+
"typescript.inlayHints.enumMemberValues.enabled": true,
12+
"javascript.inlayHints.parameterNames.enabled": "all",
13+
"javascript.inlayHints.parameterTypes.enabled": true,
14+
"javascript.inlayHints.variableTypes.enabled": true,
15+
"javascript.inlayHints.propertyDeclarationTypes.enabled": true,
16+
"javascript.inlayHints.functionLikeReturnTypes.enabled": true,
17+
"javascript.inlayHints.enumMemberValues.enabled": true,
18+
"rust-analyzer.inlayHints": {
19+
"bindingModeHints": { "enable": true },
20+
"chainingHints": { "enable": true },
21+
"closingBraceHints": { "enable": true },
22+
"closureReturnTypeHints": { "enable": "always" },
23+
"lifetimeElisionHints": { "enable": "always", "useParameterNames": true },
24+
"parameterHints": { "enable": true },
25+
"typeHints": { "enable": true }
26+
},
27+
"go.goplsOptions": {
28+
"hints": {
29+
"assignVariableTypes": true,
30+
"compositeLiteralFields": true,
31+
"compositeLiteralTypes": true,
32+
"constantValues": true,
33+
"functionTypeParameters": true,
34+
"parameterNames": true,
35+
"rangeVariableTypes": true
36+
}
37+
}
38+
}

doc/coc-ale.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# IDE setup (Coc.nvim + ALE)
2+
3+
This config uses:
4+
5+
- **coc.nvim** for language servers, completion, code actions, rename, etc.
6+
- **ALE** for linting/fixing and displaying diagnostics (Coc sends diagnostics to ALE).
7+
8+
## Where things are configured
9+
10+
- Plugin + keymaps: `lua/coldboot/plugins/coc_ale.lua`
11+
- Coc settings (inlay hints, insert/replace mode, etc): `coc-settings.json`
12+
13+
## Keymaps (kept from the previous LSP setup)
14+
15+
Navigation / actions:
16+
17+
- `gd` definition
18+
- `gD` declaration
19+
- `gI` implementation
20+
- `gr` references
21+
- `K` hover
22+
- `<C-k>` signature help
23+
- `<leader>rn` rename
24+
- `<leader>ca` code action (normal/visual)
25+
- `<leader>D` type definition
26+
- `<leader>ds` document symbols (`:CocList outline`)
27+
- `<leader>ws` workspace symbols (`:CocList -I symbols`)
28+
29+
Formatting:
30+
31+
- `<leader>f` format buffer (Coc format, falls back to `:ALEFix`)
32+
- `:Format` same as above
33+
- `:ColdbootFormatToggle` toggles ALE fix-on-save
34+
35+
## Completion (IntelliJ-like)
36+
37+
In insert mode:
38+
39+
- `<C-n>` / `<C-p>`: if completion menu is visible, move selection; otherwise trigger completion.
40+
- `<CR>`: accept completion **without overwriting** text to the right of the caret (“insert”).
41+
- `<Tab>`: accept completion and **overwrite** the word to the right of the caret (“replace”).
42+
43+
## Inlay hints
44+
45+
Inlay hints are enabled via `coc-settings.json`.
46+
47+
- Toggle for the current buffer: `:CocCommand document.toggleInlayHint`
48+
49+
## Useful commands
50+
51+
- `:CocInfo` show Coc status
52+
- `:CocConfig` edit Coc settings
53+
- `:ALEInfo` show ALE status
54+
- `:Mason` install/update LSP binaries (this config auto-installs `gopls`, `rust-analyzer`, `pyright`)
55+
56+
## Notes on external tools
57+
58+
ALE fixers/linters call external binaries (e.g. `eslint`, `prettier`, `golangci-lint`, `rustfmt`, `black`, `ruff`).
59+
Install them per project (recommended) or globally so ALE can run them.

lua/coldboot/plugins/autoformat.lua

Lines changed: 0 additions & 74 deletions
This file was deleted.

lua/coldboot/plugins/coc_ale.lua

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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

Comments
 (0)