From 9b7c73d9b1b4d8889ef9bfc38c29cd1a9e988d35 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Mon, 29 Aug 2022 22:55:25 +0200 Subject: [PATCH] add JSON Schema --- schema.json | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/Config.zig | 4 ++- src/setup.zig | 1 + 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 schema.json diff --git a/schema.json b/schema.json new file mode 100644 index 0000000..a00cec9 --- /dev/null +++ b/schema.json @@ -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" + } + } +} diff --git a/src/Config.zig b/src/Config.zig index e54c479..5767a10 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -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; }; diff --git a/src/setup.zig b/src/setup.zig index 71d20fd..a25de9b 100644 --- a/src/setup.zig +++ b/src/setup.zig @@ -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,