From cfb7c16de053ae721e8420de102607ef909d89dd Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Sat, 24 Sep 2022 21:30:36 +0200 Subject: [PATCH] add `enable_autofix` option --- README.md | 1 + schema.json | 5 +++++ src/Config.zig | 4 ++++ src/requests.zig | 1 + src/setup.zig | 2 ++ 5 files changed, 13 insertions(+) diff --git a/README.md b/README.md index b2781dc..7dd57eb 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ The following options are currently available. | --- | --- | --- | --- | | `enable_snippets` | `bool` | `false` | Enables snippet completions when the client also supports them. | | `enable_ast_check_diagnostics` | `bool` | `true`| Whether to enable ast-check diagnostics | +| `enable_autofix` | `bool` | `false`| Whether to automatically fix errors on save. Currently supports adding and removing discards. | | `enable_import_embedfile_argument_completions` | `bool` | `false` | Whether to enable import/embedFile argument completions | | `zig_lib_path` | `?[]const u8` | `null` | zig library path, e.g. `/path/to/zig/lib/zig`, used to analyze std library imports. | | `zig_exe_path` | `?[]const u8` | `null` | 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. | diff --git a/schema.json b/schema.json index 79e3c33..b7a37cc 100644 --- a/schema.json +++ b/schema.json @@ -14,6 +14,11 @@ "type": "boolean", "default": "true" }, + "enable_autofix": { + "description": "Whether to automatically fix errors on save. Currently supports adding and removing discards.", + "type": "boolean", + "default": "false" + }, "enable_import_embedfile_argument_completions": { "description": "Whether to enable import/embedFile argument completions", "type": "boolean", diff --git a/src/Config.zig b/src/Config.zig index 6707eda..688c1f7 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -16,6 +16,10 @@ enable_snippets: bool = false, /// Whether to enable ast-check diagnostics enable_ast_check_diagnostics: bool = true, +/// Whether to automatically fix errors on save. +/// Currently supports adding and removing discards. +enable_autofix: bool = false, + /// Whether to enable import/embedFile argument completions (NOTE: these are triggered manually as updating the autotrigger characters may cause issues) enable_import_embedfile_argument_completions: bool = false, diff --git a/src/requests.zig b/src/requests.zig index 1dd7e46..522d5d1 100644 --- a/src/requests.zig +++ b/src/requests.zig @@ -289,6 +289,7 @@ pub const Configuration = struct { settings: struct { enable_snippets: ?bool, enable_ast_check_diagnostics: ?bool, + enable_autofix: ?bool, enable_import_embedfile_argument_completions: ?bool, zig_lib_path: ?[]const u8, zig_exe_path: ?[]const u8, diff --git a/src/setup.zig b/src/setup.zig index 40b058e..c32861e 100644 --- a/src/setup.zig +++ b/src/setup.zig @@ -171,6 +171,7 @@ pub fn wizard(allocator: std.mem.Allocator) !void { const editor = try askSelectOne("Which code editor do you use?", enum { VSCode, Sublime, Kate, Neovim, Vim8, Emacs, Doom, Spacemacs, Helix, Other }); const snippets = try askBool("Do you want to enable snippets?"); const ast_check = try askBool("Do you want to enable ast-check diagnostics?"); + const autofix = try askBool("Do you want to zls to automatically try to fix errors on save? (supports adding & removing discards)"); const ief_apc = try askBool("Do you want to enable @import/@embedFile argument path completion?"); const style = try askBool("Do you want to enable style warnings?"); const semantic_tokens = try askBool("Do you want to enable semantic highlighting?"); @@ -193,6 +194,7 @@ pub fn wizard(allocator: std.mem.Allocator) !void { .zig_exe_path = zig_exe_path, .enable_snippets = snippets, .enable_ast_check_diagnostics = ast_check, + .enable_autofix = autofix, .enable_import_embedfile_argument_completions = ief_apc, .warn_style = style, .enable_semantic_tokens = semantic_tokens,