# Zls not working with imported raylib

**URL:** <https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986>\
**Category:** Help\
**Tags:** c, raylib, zls\
**Created:** [April 17, 2024, 4:29am UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986 "2024-04-17T04:29:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eirik](https://ziggit.dev/user_avatar/ziggit.dev/eirik/32/2189_2.png) [@Eirik](https://ziggit.dev/u/Eirik)\
**Post date:** [April 17, 2024, 4:29am UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/1 "2024-04-17T04:29:23Z")

</div>

I cannot get auto complete to work for raylib using this method. Zls works fine for zig but it does not give me anything for the included c headers. I have tried both in nvmim and vscode, does this still work for you?

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [April 17, 2024, 8:16am UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/2 "2024-04-17T08:16:04Z")

</div>

Welcome to ziggit @Eirik!

Overall zls isn’t really an issue related to the zigraylib project (I think it just may be an issue with cImports with certain versions / configurations of zls in general), if the zls doesn’t provide completions, but the project compiles, it is most likely some issue with how zls is setup. So for more extended trouble shooting of zls, I moved this to a separate topic.

* * *

What is your zls and zig version?  
My guess would be that it is the zls release, which seems to give you only partial functionality (probably because it is old / still 0.11). I think cloning zls and following the instructions in the readme to build it work best, if you are configuring it for neovim.

For vscode it should just download the recent versions and build them automatically, I don’t know whether those may be broken sometimes, if there maybe is a bug on their dev branch. I also don’t know whether there is some command to trigger a reinstall, probably there is, but you have to look that up. I rarely use (vs)code.

For neovim I am using LazyVim here is my zls config.  
`lua/plugins/zig.lua`:

```zig
return {
  {
    "neovim/nvim-lspconfig",
    init = function()
      require("lspconfig")["zls"].setup({
        settings = {
          zls = {
            path = "/home/sze/development/workspace/zig/active/current/zig",
            Zls = {
              path = "/home/sze/development/workspace/zig/active/zls/zig-out/bin/zls",
              enableAutofix = true,
              enable_snippets = true,
              enable_ast_check_diagnostics = true,
              enable_autofix = true,
              enable_import_embedfile_argument_completions = true,
              warn_style = true,
              enable_semantic_tokens = true,
              enable_inlay_hints = true,
              inlay_hints_hide_redundant_param_names = true,
              inlay_hints_hide_redundant_param_names_last_token = true,
              operator_completions = true,
              include_at_in_builtins = true,
              max_detail_length = 1048576,
            },
          },
        },
      })
    end,
  },
}

```

The first path is the path to my current zig executable. (Actually current is a symlink so that I can switch zig versions by changing one symlink, I am on linux)  
The second path is the path to the zls executable (which I rebuilt when I change zig versions).  
I also have a zls config `~/.config/zls.json`:

```zig
{
    "$schema": "https://raw.githubusercontent.com/zigtools/zls/master/schema.json",
    "zig_exe_path": "/home/sze/development/workspace/zig/active/current/zig",
    "enable_snippets": true,
    "enable_ast_check_diagnostics": true,
    "enable_autofix": true,
    "enable_import_embedfile_argument_completions": true,
    "warn_style": true,
    "enable_semantic_tokens": true,
    "enable_inlay_hints": true,
    "inlay_hints_hide_redundant_param_names": true,
    "inlay_hints_hide_redundant_param_names_last_token": true,
    "operator_completions": true,
    "include_at_in_builtins": true,
    "max_detail_length": 1048576
}

```

But I think that is only relevant when I use zls from some editor that doesn’t configure zls directly.

---

<div class="post-metadata">

**Author:** ![felpafel](https://ziggit.dev/letter_avatar_proxy/v4/letter/f/ecae2f/32.png) [@felpafel](https://ziggit.dev/u/felpafel)\
**Post date:** [April 17, 2024, 10:46am UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/3 "2024-04-17T10:46:52Z")

</div>

Hello, I started learning zig last weekend and ran into this same problem.

I manage to solve the issue and it is not a ZLS fault. There are some useful information that is not present in the main thread that I had to discover myself.

First, Zig’s APIs tend to break/change due to the fast development/iteration. So, to get Raylib working you have to have a compatible Zig version that you can find on their [build.zig](https://github.com/raysan5/raylib/blob/master/build.zig). On today’s date the supported/tested version is `zig 0.12.0-dev.3632+7fb5a0b18` and I’m running the last release `zig 0.12.0-dev.3666+a2b834e8c`.

To have a working ZLS you just have to clone their repo and build it using `zig build -Doptimize=ReleaseSafe` then you put the binary, found in `zig-out/bin/zls`, into your path.

Now the important part. Grab the Raylib’s commit you want to use, for example the latest one `4491ff04262d11cf8f66e1bd6145c1a8d30bb503` and use `zig fetch` to compose your `build.zig.zon`, like: `zig fetch https://github.com/raysan5/raylib/archive/4491ff04262d11cf8f66e1bd6145c1a8d30bb503.tar.gz --save=raylib`. This way zig will generate the correct hash for you.

Finally, for reasons unknown to me, some files don’t get update in zig’s global cache (edit: if you have already tried other commit), resulting in ZLS not providing completion. But if you just delete the folder’s content and rebuild your project, the completion will start working. On windows the global cache is in `C:\Users\USERNAME\AppData\Local\zig`.

---

<div class="post-metadata">

**Author:** ![msw](https://ziggit.dev/user_avatar/ziggit.dev/msw/32/2986_2.png) [@msw](https://ziggit.dev/u/msw)\
**Post date:** [April 17, 2024, 12:26pm UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/4 "2024-04-17T12:26:34Z")

</div>

`enableAutofix` and `enable_autofix` – are these really both present?  
… at least in the `zls.json` it’s the latter. Is the former for nvim?

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [April 17, 2024, 1:33pm UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/5 "2024-04-17T13:33:16Z")

</div>

My guess is that `enableAutofix` doesn’t exist and gets ignored in the nvim lspconfig.

---

<div class="post-metadata">

**Author:** ![Eirik](https://ziggit.dev/user_avatar/ziggit.dev/eirik/32/2189_2.png) [@Eirik](https://ziggit.dev/u/Eirik)\
**Post date:** [April 17, 2024, 4:31pm UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/6 "2024-04-17T16:31:24Z")

</div>

Thanks for the suggestions guys, appreciate it. I tried everything but still no go, seems like zls can’t resolve the headers in raylib.zig. Might be a Windows issue? I can compile and run the project fine with zig build.

![image](https://ziggit.dev/uploads/default/original/2X/7/78b3cd3da92e21657f56ffeeb9330b123ccc8b22.png)

```zig
E:\dev\zig\game [master ≡ +1 ~2 -0 !]> zig version
0.12.0-dev.3653+e45bdc6bd
E:\dev\zig\game [master ≡ +1 ~2 -0 !]> zls --version
0.12.0-dev.513+172c8f2

```

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [April 17, 2024, 4:45pm UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/7 "2024-04-17T16:45:56Z")

</div>

Can you post your `build.zig`?

---

<div class="post-metadata">

**Author:** ![biggest\_endian](https://ziggit.dev/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@biggest\_endian](https://ziggit.dev/u/biggest_endian)\
**Post date:** [April 17, 2024, 4:57pm UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/8 "2024-04-17T16:57:26Z")

</div>

This seems to be a recent regression. It stopped working a few days ago for me with no changes to my project except updating zig & zls. Zig compiles the project just fine but zls cannot find the header files. Issue is being tracked here: [https://github.com/zigtools/zls/issues/1851](https://github.com/zigtools/zls/issues/1851)

---

<div class="post-metadata">

**Author:** ![castholm](https://ziggit.dev/user_avatar/ziggit.dev/castholm/32/1330_2.png) [@castholm](https://ziggit.dev/u/castholm)\
**Post date:** [April 17, 2024, 5:13pm UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/9 "2024-04-17T17:13:52Z")

</div>

Whenever ZLS stops working, I usually first check the output of the language server process to see if it has anything useful to say. In VS Code, you can do this by bringing up the Output pane and selecting “Zig Language Server” in the drop-down to its top right. Different editors likely expose some similar means of accessing the output or logs. Usually, there will be some kind of compile error in there, which might either point to your build.zig script (suggesting a problem in your code) or ZLS’s custom build runner (suggesting a mismatch between the ZLS and Zig compiler versions you’re using).

---

<div class="post-metadata">

**Author:** ![Eirik](https://ziggit.dev/user_avatar/ziggit.dev/eirik/32/2189_2.png) [@Eirik](https://ziggit.dev/u/Eirik)\
**Post date:** [April 21, 2024, 8:16pm UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/10 "2024-04-21T20:16:00Z")

</div>

I didn’t find anything useful in the lsp logs. I am using build.zig similar to the example here [zigraylib/build.zig at main · SimonLSchlee/zigraylib · GitHub](https://github.com/SimonLSchlee/zigraylib/blob/main/build.zig).  
What I suspect is that its missing a .AddIncludePath for the raylib source. But when importing from a dependency I dont know what the path is.

I actually managed to get zls working with raylib by using a submodule instead of the package manager. Working example here: [GitHub - everystone/raylib-zig-template](https://github.com/everystone/raylib-zig-template)

---

<div class="post-metadata">

**Author:** ![Flokkq](https://ziggit.dev/user_avatar/ziggit.dev/flokkq/32/4634_2.png) [@Flokkq](https://ziggit.dev/u/Flokkq)\
**Post date:** [February 20, 2025, 12:57am UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/11 "2025-02-20T00:57:35Z")

</div>

A bit late to the party but I have the same issue here when installing `zig-imgui` with the package manager. Has anyone made progress yet or is using git submodules still the way to go?

---

<div class="post-metadata">

**Author:** ![JacobCrabill](https://ziggit.dev/user_avatar/ziggit.dev/jacobcrabill/32/1316_2.png) [@JacobCrabill](https://ziggit.dev/u/JacobCrabill)\
**Post date:** [February 20, 2025, 3:05am UTC](https://ziggit.dev/t/zls-not-working-with-imported-raylib/3986/12 "2025-02-20T03:05:30Z")

</div>

ZLS should work out of the box with Raylib and other packages, so long as the following conditions are met:

1. Identical versions of `zig` and `zls`,
2. The package is included in your `build.zig.zon`,
3. It is added as an imported module to a Compile step that is part of your default `zig build` command, and
4. Related to #3, the Compile step that uses the module is not guarded by an option flag.

I ran into issues with `raylib` myself, but discovered it was because I only used the `raylib` module in my build.zig when I set the command-line option `-Denable-raylib`. If you’re following a similar pattern of only using a dependency when some options are set, you can use the [per-build config](https://zigtools.org/zls/configure/per-build/) of ZLS, for example (`zls.build.json`):

```json
{
  "build_options": [
    {
      "name": "enable-raylib",
      "value": "true"
    }
  ]
}

```
