Skip to content

Commit 98372c9

Browse files
committed
simplify how format on save should be configured for CoC
1 parent c97eec3 commit 98372c9

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

content/zls/editors/vim/coc.smd

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,30 @@
1212
---
1313

1414
1. Install [CoC](https://github.com/neoclide/coc.nvim)
15-
1. Install [zig.vim](https://github.com/ziglang/zig.vim)
16-
2. Install [jsonc.vim](https://github.com/neoclide/jsonc.vim) (optional, so that comments in json are not highlighted as errors)
17-
3. Add ZLS in your `coc-settings.json` (open it using `:CocConfig`) like this:
15+
2. Install [zig.vim](https://github.com/ziglang/zig.vim)
16+
3. Install [jsonc.vim](https://github.com/neoclide/jsonc.vim) (optional, so that comments in json are not highlighted as errors)
17+
4. place the following snippet in your `coc-settings.json` (open it using `:CocConfig`)
18+
5. place the following snippet in your `init.lua` / `init.vim` / `.vimrc`
1819

1920
```json
21+
// coc-settings.json
2022
{
21-
// Show inlay hints in the editor. Inlay hints are short annotations within the code,
22-
// which show variable types or parameter names.
23-
// "inlayHint.enable": true,
24-
25-
// Use the language server to perform code highlighting
26-
"semanticTokens.enable": true,
23+
// All nested settings will only affect Zig files.
24+
"[zig]": {
25+
// enable format-on-save from CoC + ZLS
26+
//
27+
// Formatting with ZLS matches `zig fmt`.
28+
// The Zig FAQ answers some questions about `zig fmt`:
29+
// https://github.com/ziglang/zig/wiki/FAQ
30+
"coc.preferences.formatOnSave": true,
31+
32+
// Show inlay hints in the editor. Inlay hints are short annotations within the code,
33+
// which show variable types or parameter names.
34+
// "inlayHint.enable": true,
35+
36+
// Use the language server to perform code highlighting
37+
"semanticTokens.enable": true
38+
},
2739

2840
"languageserver": {
2941
"zls": {
@@ -44,43 +56,29 @@
4456
// "zls.enable_build_on_save": true,
4557

4658
// omit the following line if `zig` is in your PATH
47-
"zls.zig_exe_path": "/path/to/zig_executable",
59+
"zls.zig_exe_path": "/path/to/zig_executable"
4860
}
49-
},
61+
}
5062
}
5163
}
5264
```
5365

54-
## Setup format on save
55-
5666
```lua
67+
-- init.lua
68+
5769
-- don't show parse errors in a separate window
5870
vim.g.zig_fmt_parse_errors = 0
5971
-- disable format-on-save from `ziglang/zig.vim`
6072
vim.g.zig_fmt_autosave = 0
61-
-- enable format-on-save from coc.nvim + ZLS
62-
--
63-
-- Formatting with ZLS matches `zig fmt`.
64-
-- The Zig FAQ answers some questions about `zig fmt`:
65-
-- https://github.com/ziglang/zig/wiki/FAQ
66-
vim.api.nvim_create_autocmd('BufWritePre',{
67-
pattern = {"*.zig", "*.zon"},
68-
command = "call CocActionAsync('format')"
69-
})
7073
```
7174

7275
```vim
73-
" disable format-on-save from `ziglang/zig.vim`
74-
let g:zig_fmt_autosave = 0
76+
" init.vim or .vimrc
77+
7578
" don't show parse errors in a separate window
7679
let g:zig_fmt_parse_errors = 0
77-
78-
" enable format-on-save from coc.nvim + ZLS
79-
"
80-
" Formatting with ZLS matches `zig fmt`.
81-
" The Zig FAQ answers some questions about `zig fmt`:
82-
" https://github.com/ziglang/zig/wiki/FAQ
83-
autocmd BufWritePre *.zig,*.zon call CocActionAsync('format')
80+
" disable format-on-save from `ziglang/zig.vim`
81+
let g:zig_fmt_autosave = 0
8482
```
8583

8684
## Code Actions on save

content/zls/editors/vim/nvim-lspconfig.smd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ call plug#begin('~/.config/nvim/plugged')
7777
Plug 'ziglang/zig.vim' " https://github.com/ziglang/zig.vim
7878
call plug#end()
7979

80-
" disable format-on-save from `ziglang/zig.vim`
81-
let g:zig_fmt_autosave = 0
8280
" don't show parse errors in a separate window
8381
let g:zig_fmt_parse_errors = 0
82+
" disable format-on-save from `ziglang/zig.vim`
83+
let g:zig_fmt_autosave = 0
8484

8585
" enable format-on-save from nvim-lspconfig + ZLS
8686
"

0 commit comments

Comments
 (0)