VS Code

Using ZLS in VS Code is as simple as installing the official Zig Language extension.

Configuration

The VS Code extension will automatically install Zig and ZLS. The extension is intended to provide the best possible experience Out-of-the-Box without extra configuration.

With that being said, there are some Zig specific settings that you may wish to apply:

// settings.json (open with `Preferences: Open User Settings (JSON)`)
{
  "zig.zls.enabled": "on",
  // You can add more Zig and ZLS options here

  // Whether to enable build-on-save diagnostics
  //
  // Further information about build-on save:
  // https://zigtools.org/zls/guides/build-on-save/
  // "zig.zls.enableBuildOnSave": true,

  // All nested settings will only affect Zig files.
  "[zig]": {
    // The Zig FAQ answers some common questions about Zig's formatter (`zig fmt`)
    // https://github.com/ziglang/zig/wiki/FAQ
    //
    // "editor.formatOnSave": false,

    // "editor.inlayHints.enabled": "off",

    // overwrite words when accepting completions
    "editor.suggest.insertMode": "replace",
    "editor.codeActionsOnSave": {
      // Run code actions that currently supports adding and removing discards.
      // "source.fixAll": "explicit",
      
      // Run code actions that sorts @import declarations.
      // "source.organizeImports": "explicit",
    }
  },
  "editor.semanticTokenColorCustomizations": {
    "rules": {
      "*.deprecated": {
        // highlight semantic tokens that are marked as "deprecated"
        "strikethrough": true
      }
    }
  }
}

For more information, checkout the VS Code docs about Settings.

Set outdated config options

The available config options in the VS Code extension match those that are offered by the latest nightly build of ZLS. Be aware that hey may be out of sync.

To set config options that are offered by older ZLS version (e.g. enable_autofix for ZLS 0.13.0) you can use the zig.zls.additionalOptions property:

// settings.json (open with `Preferences: Open User Settings (JSON)`)
{
  "zig.zls.additionalOptions": {
    // UNKNOWN CONFIG OPTIONS WILL BE SILENTLY IGNORED

    // Here are some examples of config options that have been REMOVED:
    "zig.zls.enableAutofix": true, // Will set the "enable_autofix" config option
    "zig.zls.buildOnSaveStep": "foo", // Will set the "build_on_save_step" config option

    // All values have to be converted to camelCase and get prefixed with `zig.zls`. 
  },
}

You can check the ZLS logs to see if the additional options have been set.