Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Cannot reference functions of modules if the dependencies are loaded conditionally #472

@Logickin-Lambda

Description

@Logickin-Lambda

Background

When I was working on a backend of a gui library, upgrading some c based backend into the relative zig implementation (e.g.: c based raylib libarary -> raylib-zig), to ensure backward compatibility, I have conditionally included the c and zig based backend into the build file, branched by an option; however, this cause a problem of any dependencies that is skipped by the condition will never be referenced, losing the ability to auto complete for those modules, but using the correct option to compile the program, those modules works without any issue.

Zig version:

0.15.1

Extension version:

0.6.15

How to Reproduce the Issue

It can be reproduced with the simplest form of the project as long as you have imported a few dependencies along with an conditional branch (usually, the build options), but before showing the issue, I am going to show the control test first by loading two dependencies of choice into the project:

const raylib_dep = b.dependency("raylib_zig", .{
	.target = target,
	.optimize = optimize,
});

const raylib = raylib_dep.module("raylib"); // main raylib module
const raygui = raylib_dep.module("raygui"); // raygui module
const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library

exe.linkLibrary(raylib_artifact);
exe.root_module.addImport("raylib", raylib);
exe.root_module.addImport("raygui", raygui);

const zglfw = b.dependency("zglfw", .{});
exe.root_module.addImport("zglfw", zglfw.module("root"));

b.installArtifact(exe);

The set up above is the normal usual set up, and by restarting the ZLS server, all of the dependencies are referenced as usual:

Image

However, when I apply an option and branch the dependency based on the newly added option arbitrary_option, as shown:

const arbitrary_option = b.option(bool, "toggle", "just a random toggle that load dependencies conditionally") orelse false;

if (arbitary_option) {
	const raylib_dep = b.dependency("raylib_zig", .{
		.target = target,
		.optimize = optimize,
	});

	const raylib = raylib_dep.module("raylib"); // main raylib module
	const raygui = raylib_dep.module("raygui"); // raygui module
	const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library

	exe.linkLibrary(raylib_artifact);
	exe.root_module.addImport("raylib", raylib);
	exe.root_module.addImport("raygui", raygui);
} else {
	const zglfw = b.dependency("zglfw", .{});
	exe.root_module.addImport("zglfw", zglfw.module("root"));
}

Only the branch that fulfill the condition can be referenced which is the default value for arbitrary_option (false):

Image

Because of this issue, I can't use the auto complete to fetch the function names and the constants in the dependencies that is not a part in the default build, but compiling them with the correct option is not a problem. Is this an intended design? And what I should do instead if the design is intended? Please also let me know if this problem is related ZLS so that I could refer this problem if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lspIssue with language server integration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions