-
-
Notifications
You must be signed in to change notification settings - Fork 302
Installation
Note If you only intend to use Visual Studio Code, you don't need to install ZLS or Zig manually
NOTE: The zls master is only compatible with the Zig master. Do not use it with tagged release of Zig and always update Zig and ZLS together.
LINUX: Zls is not executable by default, but that is needed to be functional. Run chmod +x zls
to make zls executable.
x86-64 | x86 | AArch64 | |
---|---|---|---|
Linux | x86-64 Linux | x86 Linux | AArch64 Linux |
Windows | x86-64 Windows | x86 Windows | - |
MacOS | x86 MacOS | - | AArch64 Macos |
A JSON Index of all recent ZLS versions is also available.
NOTE: A tagged release of zls is only compatible with the same release of Zig.
Head to the Releases
tab and select the right executable in the Assets
section at the bottom of the latest release.
tar -x --strip-components=1 -f [archive] [output_path]
Building zls requires a build of Zig master. The master branch cannot be build with a tagged release of Zig.
git clone https://github.com/zigtools/zls
cd zls
zig build -Doptimize=ReleaseSafe
Most extensions expect you to either manually specify the path to ZLS or add ZLS to your PATH
Note You don't need to install ZLS or Zig manually
Using ZLS in Visual Studio Code is as simple as installing the official Zig Language extension (open in VSCode).
- install the LSP and sublime-zig-language package (Package Control Usage)
- place the following snippet in the
LSP.sublime-settings
(Preferences -> Package Settings -> LSP -> Settings) - place the following snippet in the
Zig.sublime-settings
(Preferences -> Package Settings -> Zig -> Settings)
show Zig.sublime-settings
// Zig.sublime-settings
{
// ZLS will run format on save
"zig.fmt.on_save": false,
// automatically hide the build/fmt output panel
"zig.quiet": true,
}
show LSP.sublime-settings
// LSP.sublime-settings
{
// General settings
// Keep in mind that these settings apply to any language and not just Zig.
// ZLS uses `zig fmt` as the formatter.
// The Zig FAQ answers some questions about `zig fmt`:
// https://github.com/ziglang/zig/wiki/FAQ
"lsp_format_on_save": true,
"lsp_code_actions_on_save": {
// Enable code actions that currently supports adding and removing discards.
"source.fixAll": true,
},
// Show inlay hints in the editor. Inlay hints are short annotations within the code,
// which show variable types or parameter names.
//
// ZLS provides settings to customize inlay hints:
// https://github.com/zigtools/zls#configuration-options
"show_inlay_hints": true,
"semantic_highlighting": true,
"clients": {
"zig": {
// Enable or disable this client configuration.
"enabled": true,
// The command line required to run the server.
"command": ["/path/to/zls_executable"],
"selector": "source.zig",
// 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 ZLS config options:
// https://github.com/zigtools/zls#configuration-options
"settings": {
// // Whether to enable build-on-save diagnostics
// "enable_build_on_save": true,
// // Manually specify the Zig executable path if it isn't already in your `PATH`
// "zig_exe_path": "/path/to/zig_executable"
}
}
}
}
show LSP.sublime-settings
// LSP.sublime-settings
{
"clients": {
"zig": {
"command": ["/path/to/zls_executable"],
"enabled": true,
"languageId": "zig",
"scopes": ["source.zig"],
"syntaxes": ["Packages/Zig Language/Syntaxes/Zig.tmLanguage"]
}
}
}
Run :CocInstall coc-zls
to install coc-zls. This extension supports the same functionality as the VS Code extension.
{
"languageserver": {
"zls" : {
"command": "/path/to/zls_executable",
"filetypes": ["zig"]
}
}
}
- Install YouCompleteMe from here.
- Add these lines to your vimrc:
"ensure zig is a recognized filetype
autocmd BufNewFile,BufRead *.zig set filetype=zig
let g:ycm_language_server =
\\ [
\\{
\\ 'name': 'zls',
\\ 'filetypes': [ 'zig' ],
\\ 'cmdline': [ '/path/to/zls_executable' ]
\\ }
\\ ]
The following two configs only contain the necessary ZLS specific configuration. Please refer to nvim-lspconfig on how to setup everything else like keybindings or autocompletion.
Install vim-plug plugin manager from here.
init.lua
with vim-plug
show config
local vim = vim
local Plug = vim.fn['plug#']
vim.call('plug#begin')
Plug('neovim/nvim-lspconfig') -- https://github.com/neovim/nvim-lspconfig
Plug('ziglang/zig.vim') -- https://github.com/ziglang/zig.vim
vim.call('plug#end')
local lspconfig = require('lspconfig')
lspconfig.zls.setup {
-- Server-specific settings. See `:help lspconfig-setup`
-- the following line can be removed if ZLS is in your PATH
cmd = { '/path/to/zls_executable' },
-- 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 ZLS config options:
-- https://github.com/zigtools/zls#configuration-options
settings = {
zls = {
-- the following line can be removed if Zig is in your PATH
zig_exe_path = '/path/to/zig_executable',
}
}
}
init.vim
with vim-plug
show config
call plug#begin('~/.config/nvim/plugged')
Plug 'neovim/nvim-lspconfig' " https://github.com/neovim/nvim-lspconfig
Plug 'ziglang/zig.vim' " https://github.com/ziglang/zig.vim
call plug#end()
:lua << EOF
local lspconfig = require('lspconfig')
lspconfig.zls.setup {
-- Server-specific settings. See `:help lspconfig-setup`
-- the following line can be removed if ZLS is in your PATH
cmd = { '/path/to/zls_executable' },
-- 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 ZLS config options:
-- https://github.com/zigtools/zls#configuration-options
settings = {
zls = {
-- the following line can be removed if Zig is in your PATH
zig_exe_path = '/path/to/zig_executable',
}
}
}
EOF
- Install the LanguageClient-neovim from here.
- Edit your neovim configuration and add
zls
for zig filetypes:
let g:LanguageClient_serverCommands = {
\\ 'zig': ['/path/to/zls_executable'],
\\ }
Kate has builtin support for Zig and automatically asks you to enable ZLS if if is found in your $PATH
.
You can enable some LSP related settings like "Inlay Hints" or "Format on Save" under Settings -> LSP Client -> Client Settings
If you wish to manually specify the path to the ZLS executable, open Settings -> LSP Client -> User Server Settings
and add the following snippet:
{
"servers": {
"zig": {
"command": ["/path/to/zls_executable"],
"url": "https://github.com/zigtools/zls",
"highlightingModeRegex": "^Zig$"
}
}
}
;; Setup lsp-mode as desired.
;; See https://emacs-lsp.github.io/lsp-mode/page/installation/ for more information.
(require 'lsp-mode)
;; Either place zls in your PATH or add the following:
(setq lsp-zig-zls-executable "/path/to/zls_executable")
- Enable
:tools lsp
module. - Enable
:lang (zig +lsp)
module. - Run
doom sync
in a terminal.
- Add
lsp
andzig
todotspacemacs-configuration-layers
in your.spacemacs
file. - If you don't have
zls
in yourPATH
, add the following todotspacemacs/user-config
in your.spacemacs
file:
(setq lsp-zig-zls-executable "/path/to/zls_executable")
Add zls
to your PATH
or manually specify the path in <config_dir>/helix/languages.toml
with the following:
[language-server.zls]
command = "/path/to/zls_executable"
Further information on languages.toml files
Then run hx --health
to check if helix found zls
.
- Install the ZigBrains plugin from the marketplace
- Restart the IDE (necessary for the plugin to integrate itself correctly)
If you have both zig
and zls
on $PATH, then the plugin will automatically detect both.
If not, go to Settings | Languages & Frameworks
, and you can manually select the directory where the zig
binary is under the Zig
category, and the binary for zls
under the ZLS
category.
If everything is set up correctly, the status indicator in the bottom right corner should turn to green when you open a .zig file in the editor.
Questions not answered by this wiki? Join our Discord server or start a discussion!