#+TITLE: Zig layer

#+TAGS: general|layer|multi-paradigm|programming

* Table of Contents                     :TOC_5_gh:noexport:
- [[#description][Description]]
  - [[#features][Features:]]
- [[#install][Install]]
  - [[#layer][Layer]]
  - [[#choosing-a-backend][Choosing a backend]]
    - [[#lsp-zls][LSP (zls)]]
    - [[#zig-mode][zig-mode]]
- [[#key-bindings][Key bindings]]
  - [[#lsp][LSP]]

* Description
This layer adds support for the zig programming language [[https://ziglang.org/]]

** Features:
- Syntax Highlighting
- LSP support via =zls= (see [[#lsp-zls][LSP]])

* Install
** Layer
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =zig= to the existing =dotspacemacs-configuration-layers= list in this
file.

** Choosing a backend
You can choose between multiple language backends.
This choice defines mainly which kind of IDE features spacemacs
can deliver.

Alternatively, if non is set the =lsp= backend will be automatically
chosen if the layer =lsp= is used, otherwise =zig-mode= will be used.

For best results, make sure that the =auto-completion= and =syntax-checking=
layers are enabled as well.

*** LSP (zls)
You can use [[https://github.com/zigtools/zls][=zls=]] as a Language Server backend to add features like
auto-completion, code navigation, formatting etc.

To do so, make sure you have the =lsp= layer in your
=dotspacemacs-configuration-layers=. If necessary, upgrade the =lsp-mode=
package (support for Zig was added in version =20210318.923=). Install =zls=
following the [[https://github.com/zigtools/zls/wiki/Downloading-and-Building-ZLS#using-an-official-release][instructions on the Wiki]] and then configure the =zls= layer with
the appropriate variable:

#+BEGIN_SRC elisp
  (setq-default dotspacemacs-configuration-layers
    '((zig :variables
          zls-backend 'lsp)))
#+END_SRC

*** zig-mode
This mode provides support for the language with syntax highlighting,
indentation and custom commands for compilation and testing.

For more information check the [[https://github.com/ziglang/zig-mode][=zig-mode= repository]].

* Key bindings
** LSP
You can find an overview of all the key bindings on the [[https://github.com/syl20bnr/spacemacs/tree/develop/layers/%2Btools/lsp#key-bindings][lsp layer description]].
