add JSON Schema

This commit is contained in:
Techatrix 2022-08-29 22:55:25 +02:00
parent 2ac8ab6ce9
commit 9b7c73d9b1
3 changed files with 88 additions and 1 deletions

84
schema.json Normal file
View File

@ -0,0 +1,84 @@
{
"$schema": "http://json-schema.org/schema",
"title": "ZLS Config",
"description": "Configuration file for the zig language server (ZLS)",
"type": "object",
"properties": {
"enable_snippets": {
"description": "Enables snippet completions when the client also supports them",
"type": "boolean",
"default": "false"
},
"enable_unused_variable_warnings": {
"description": "Enables warnings for local variables that aren't used",
"type": "boolean",
"default": "false"
},
"enable_import_embedfile_argument_completions": {
"description": "Whether to enable import/embedFile argument completions",
"type": "boolean",
"default": "false"
},
"zig_lib_path": {
"description": "Zig library path, e.g. `/path/to/zig/lib/zig`, used to analyze std library imports",
"type": "string"
},
"zig_exe_path": {
"description": "Zig executable path, e.g. `/path/to/zig/zig`, used to run the custom build runner. If `null`, zig is looked up in `PATH`. Will be used to infer the zig standard library path if none is provided",
"type": "string"
},
"warn_style": {
"description": "Enables warnings for style guideline mismatches",
"type": "boolean",
"default": "false"
},
"build_runner_path": {
"description": "Path to the `build_runner.zig` file provided by zls. null is equivalent to `${executable_directory}/build_runner.zig`",
"type": "string"
},
"global_cache_path": {
"description": "Path to a directroy that will be used as zig's cache. null is equivalent to `${KnownFloders.Cache}/zls`",
"type": "string"
},
"enable_semantic_tokens": {
"description": "Enables semantic token support when the client also supports it",
"type": "boolean",
"default": "true"
},
"enable_inlay_hints": {
"description": "Enable inlay hints for builtin functions",
"type": "boolean",
"default": "false"
},
"inlay_hints_show_builtin": {
"description": "Don't show inlay hints for single argument calls",
"type": "boolean",
"default": "true"
},
"inlay_hints_exclude_single_argument": {
"description": "Enables inlay hint support when the client also supports it",
"type": "boolean",
"default": "true"
},
"operator_completions": {
"description": "Enables `*` and `?` operators in completion lists",
"type": "boolean",
"default": "true"
},
"include_at_in_builtins": {
"description": "Whether the @ sign should be part of the completion of builtins",
"type": "boolean",
"default": "false"
},
"max_detail_length": {
"description": "The detail field of completions is truncated to be no longer than this (in bytes)",
"type": "integer",
"default": "1048576"
},
"skip_std_references": {
"description": "When true, skips searching for references in std. Improves lookup speed for functions in user's code. Renaming and go-to-definition will continue to work as is",
"type": "boolean",
"default": "false"
}
}
}

View File

@ -1,4 +1,5 @@
//! Configuration options for zls.
//! Keep in sync with schema.json and zls-vscode's package.json!
const Config = @This();
@ -80,8 +81,9 @@ pub fn loadFromFile(allocator: std.mem.Allocator, file_path: []const u8) ?Config
const file_buf = file.readToEndAlloc(allocator, 0x1000000) catch return null;
defer allocator.free(file_buf);
@setEvalBranchQuota(3000);
const parse_options = std.json.ParseOptions{ .allocator = allocator, .ignore_unknown_fields = true };
// TODO: Better errors? Doesn't seem like std.json can provide us positions or context.
var config = std.json.parse(Config, &std.json.TokenStream.init(file_buf), std.json.ParseOptions{ .allocator = allocator }) catch |err| {
var config = std.json.parse(Config, &std.json.TokenStream.init(file_buf), parse_options) catch |err| {
logger.warn("Error while parsing configuration file: {}", .{err});
return null;
};

View File

@ -189,6 +189,7 @@ pub fn wizard(allocator: std.mem.Allocator) !void {
std.debug.print("Writing config to {s}/zls.json ... ", .{config_path});
try std.json.stringify(.{
.@"$schema" = "https://raw.githubusercontent.com/zigtools/zls/master/schema.json",
.zig_exe_path = zig_exe_path,
.enable_snippets = snippets,
.enable_unused_variable_warnings = unused_variables,