Conquer of Completion (CoC)
In Editor Configuration: Supported
Code Action On Save: Supported
- Install CoC
- Install zig.vim
- Install jsonc.vim (optional, so that comments in json are not highlighted as errors)
- place the following snippet in your
coc-settings.json
(open it using:CocConfig
) - place the following snippet in your
init.lua
/init.vim
/.vimrc
// coc-settings.json
{
// All nested settings will only affect Zig files.
"[zig]": {
// enable format-on-save from CoC + ZLS
//
// Formatting with ZLS matches `zig fmt`.
// The Zig FAQ answers some questions about `zig fmt`:
// https://github.com/ziglang/zig/wiki/FAQ
"coc.preferences.formatOnSave": true,
// Show inlay hints in the editor. Inlay hints are short annotations within the code,
// which show variable types or parameter names.
// "inlayHint.enable": true,
// Use the language server to perform code highlighting
"semanticTokens.enable": true
},
"languageserver": {
"zls": {
// use `"command": "zls"` if `zls` is in your PATH
"command": "/path/to/zls_executable",
"filetypes": [ "zig", "zon" ],
// There are two ways to set config options:
// - edit your `zls.json` that applies to any editor that uses ZLS
// - set in-editor config options with the `settings` field below.
//
// Further information on how to configure ZLS:
// https://zigtools.org/zls/configure/
"settings": {
// Whether to enable build-on-save diagnostics
//
// Further information about build-on save:
// https://zigtools.org/zls/guides/build-on-save/
// "zls.enable_build_on_save": true,
// omit the following line if `zig` is in your PATH
"zls.zig_exe_path": "/path/to/zig_executable"
}
}
}
}
-- init.lua
-- don't show parse errors in a separate window
vim.g.zig_fmt_parse_errors = 0
-- disable format-on-save from `ziglang/zig.vim`
vim.g.zig_fmt_autosave = 0
" init.vim or .vimrc
" don't show parse errors in a separate window
let g:zig_fmt_parse_errors = 0
" disable format-on-save from `ziglang/zig.vim`
let g:zig_fmt_autosave = 0
Code Actions on save
source.fixAll
vim.api.nvim_create_autocmd('BufWritePre',{
pattern = {"*.zig", "*.zon"},
command = "call CocActionAsync('fixAll')"
})
autocmd BufWritePre *.zig,*.zon call CocActionAsync('fixAll')
source.organizeImports
Note
The source.organizeImports
code action is available since ZLS 0.14.0-dev.188+2be424de5
.
vim.api.nvim_create_autocmd('BufWritePre',{
pattern = {"*.zig", "*.zon"},
command = "call CocActionAsync('organizeImport')"
})
autocmd BufWritePre *.zig,*.zon call CocActionAsync('organizeImport')