Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zls cannot locate zls.json file #410

Closed
palash25 opened this issue Oct 30, 2021 · 3 comments
Closed

zls cannot locate zls.json file #410

palash25 opened this issue Oct 30, 2021 · 3 comments

Comments

@palash25
Copy link

hi, i was installing zls on a new machine and noticed this problem. this is what I did

built zls from source and than ran the configuration wizard. The config wizard successfully wrote the config to /etc/zls.json

after that I copied the zls binary that was built in zls-out directory to /usr/local/bin

then i installed the vscode extension for zls and set the following option in settings

"zigLanguageClient.path": "/usr/local/bin/zls"

and restarted zls from vscode and I get this in the logs

[info-main] No config file zls.json found.
[info-main] Server closing.

does zls not look for the config in the /etc directory?

@leecannon
Copy link
Member

zls uses https://github.com/ziglibs/known-folders to fetch locations for configuration.

below is the code that checks both the local configuration and global configuration folders for the file

zls/src/main.zig

Lines 1701 to 1726 in 80f0983

config_read: {
if (config_path) |path| {
defer allocator.free(path);
if (loadConfigFile(path)) |conf| {
config = conf;
break :config_read;
}
std.debug.print("Could not open configuration file '{s}'\n", .{path});
std.debug.print("Falling back to a lookup in the local and global configuration folders\n", .{});
}
if (try known_folders.getPath(allocator, .local_configuration)) |path| {
defer allocator.free(path);
if (loadConfigInFolder(path)) |conf| {
config = conf;
break :config_read;
}
}
if (try known_folders.getPath(allocator, .global_configuration)) |path| {
defer allocator.free(path);
if (loadConfigInFolder(path)) |conf| {
config = conf;
break :config_read;
}
}
logger.info("No config file zls.json found.", .{});
}

looking at known-folders shows global config to be defined as

.global_configuration = XdgFolderSpec{ .env = .{ .name = "XDG_CONFIG_DIRS", .user_dir = false, .suffix = null }, .default = "/etc" },

so unless you have the XDG_CONFIG_DIRS environment variable set to something it should default to /etc

@palash25
Copy link
Author

hey thanks for the quick response, i see the env var you mentioned is indeed set, so if I understand correctly if this env var is unset zls will look for the config in /etc/ ?

echo $XDG_CONFIG_DIRS
/etc/xdg/xdg-pop:/etc/xdg

@leecannon
Copy link
Member

Yea looking at known-folders's code it will check for the the environment variable and if not found will fallback to the default, in the case of global configuration they have the env variable as XDG_CONFIG_DIRS and the default as /etc

I dont know enough about XDG to know if that is correct, if you dont think it is quite right raise an issue over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants