GNU Emacs

In Editor Configuration: Supported

Author’s Notice

This Documentation is incomplete.

Eglot

  1. Install Melpa
  2. Install zig mode

To apply in-editor-configuration or manually specify the path to zig or zls, add the following:

(with-eval-after-load 'eglot
  (add-to-list 'eglot-server-programs
    '(zig-mode . (
      ;; Use `zls` if it is in your PATH
      "/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 `initializationOptions` field below.
      ;;
      ;; Further information on how to configure ZLS:
      ;; https://zigtools.org/zls/configure/
      ;;
      ;; Support for `initializationOptions` in Emacs requires at least ZLS `0.14.0-dev.22+a263b8dc6`.
      :initializationOptions 
        (;; Whether to enable build-on-save diagnostics
         ;;
         ;; Further information about build-on save:
         ;; https://zigtools.org/zls/guides/build-on-save/
         ;;enable_build_on_save t
         
         ;; omit the following line if `zig` is in your PATH
         :zig_exe_path "/path/to/zig_executable"
         )))))

Eglot also supports Project-specific or User-specific server configuration.

Use M-x eglot in a zig-mode buffer to start the server or add a hook:

(add-hook 'zig-mode-hook 'eglot-ensure)

Code Actions

source.fixAll

Add the following to run source.fixAll code action on save:

(add-hook 'zig-mode-hook
  (lambda ()
    (add-hook 'before-save-hook
      (lambda ()
        (eglot-code-actions nil nil "source.fixAll" t)))))

source.organizeImports

Note

The source.organizeImports code action is available since ZLS 0.14.0-dev.188+2be424de5.

Use M-x eglot-code-action-organize-imports to manually execute the code action.

lsp-mode