|
12 | 12 | ---
|
13 | 13 |
|
14 | 14 | 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` |
18 | 19 |
|
19 | 20 | ```json
|
| 21 | +// coc-settings.json |
20 | 22 | {
|
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 | + }, |
27 | 39 |
|
28 | 40 | "languageserver": {
|
29 | 41 | "zls": {
|
|
44 | 56 | // "zls.enable_build_on_save": true,
|
45 | 57 |
|
46 | 58 | // 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" |
48 | 60 | }
|
49 |
| - }, |
| 61 | + } |
50 | 62 | }
|
51 | 63 | }
|
52 | 64 | ```
|
53 | 65 |
|
54 |
| -## Setup format on save |
55 |
| - |
56 | 66 | ```lua
|
| 67 | +-- init.lua |
| 68 | + |
57 | 69 | -- don't show parse errors in a separate window
|
58 | 70 | vim.g.zig_fmt_parse_errors = 0
|
59 | 71 | -- disable format-on-save from `ziglang/zig.vim`
|
60 | 72 | 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 |
| -}) |
70 | 73 | ```
|
71 | 74 |
|
72 | 75 | ```vim
|
73 |
| -" disable format-on-save from `ziglang/zig.vim` |
74 |
| -let g:zig_fmt_autosave = 0 |
| 76 | +" init.vim or .vimrc |
| 77 | + |
75 | 78 | " don't show parse errors in a separate window
|
76 | 79 | 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 |
84 | 82 | ```
|
85 | 83 |
|
86 | 84 | ## Code Actions on save
|
|
0 commit comments