Skip to content
Auguste Rame edited this page Jan 25, 2024 · 30 revisions

Install ZLS

Note If you only intend to use Visual Studio Code, you don't need to install ZLS or Zig manually

Prebuilt Binaries

Latest

Note We currently recommend using the latest binaries as Zig and ZLS are fast-evolving.

You can find an index of all recent ZLS versions at https://zigtools-releases.nyc3.digitaloceanspaces.com/zls/index.json. Note that at this time, there is no direct link for getting the latest ZLS executable for a specific system and you'll just have to read through the index.

Release

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]

From Source

See this section in the README.

Install Editor Extension

Most extensions expect you to either manually specify the path to ZLS or add ZLS to your PATH

Visual Studio Code

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).

Sublime Text

  1. install the LSP and sublime-zig-language package (Package Control Usage)
  2. place the following snippet in the LSP.sublime-settings (Preferences -> Package Settings -> LSP -> Settings)
  3. place the following snippet in the Zig.sublime-settings (Preferences -> Package Settings -> Zig -> 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,
}

Sublime Text 4

// 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"
            }
        }
    }
}

Sublime Text 3

// LSP.sublime-settings
{
    "clients": {
        "zig": {
            "command": ["/path/to/zls_executable"],
            "enabled": true,
            "languageId": "zig",
            "scopes": ["source.zig"],
            "syntaxes": ["Packages/Zig Language/Syntaxes/Zig.tmLanguage"]
        }
    }
}

Neovim / Vim8

CoC

With Extension

Run :CocInstall coc-zls to install coc-zls. This extension supports the same functionality as the VS Code extension.

Manually

{
    "languageserver": {
        "zls" : {
            "command": "/path/to/zls_executable",
            "filetypes": ["zig"]
        }
    }
}

YouCompleteMe

  • 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' ]
    \\    }
    \\ ]

nvim-lspconfig

Requires Nvim 0.5 (HEAD)!

  • Install nvim-lspconfig from here.
  • Install zig.vim from here.

nvim-lspconfig already ships a configuration for zls. A simple init.vim might look like this:

call plug#begin('~/.config/nvim/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/completion-nvim'
Plug 'ziglang/zig.vim'
call plug#end()
:lua << EOF
    local lspconfig = require('lspconfig')
    local on_attach = function(_, bufnr)
        vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
        require('completion').on_attach()
    end
    local servers = {'zls'}
    for _, lsp in ipairs(servers) do
        lspconfig[lsp].setup {
            on_attach = on_attach,
        }
    end
EOF
" Set completeopt to have a better completion experience
set completeopt=menuone,noinsert,noselect
" Enable completions as you type
let g:completion_enable_auto_popup = 1

LanguageClient-neovim

  • 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

  • Install language support for Zig from here.
  • Enable LSP client plugin in Kate settings.
  • Add this snippet to LSP client's user settings (e.g. /$HOME/.config/kate/lspclient) (or paste it in LSP client's GUI settings)
{
    "servers": {
        "zig": {
            "command": ["/path/to/zls_executable"],
            "url": "https://github.com/zigtools/zls",
            "highlightingModeRegex": "^Zig$"
        }
    }
}

Emacs

;; 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")

Doom Emacs

  • Enable :tools lsp module.
  • Enable :lang (zig +lsp) module.
  • Run doom sync in a terminal.

Spacemacs

  • Add lsp and zig to dotspacemacs-configuration-layers in your .spacemacs file.
  • If you don't have zls in your PATH, add the following to dotspacemacs/user-config in your .spacemacs file:
(setq lsp-zig-zls-executable "/path/to/zls_executable")

Helix

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.

Clone this wiki locally