Better zig build config
				
					
				
			This commit is contained in:
		
							parent
							
								
									67b5adc04e
								
							
						
					
					
						commit
						bf4f653bf9
					
				| @ -45,7 +45,6 @@ Then, you can use the `zls` executable in an editor of your choice that has a Zi | |||||||
| 
 | 
 | ||||||
| You can configure zls by providing a zls.json file.   | You can configure zls by providing a zls.json file.   | ||||||
| zls will look for a zls.json configuration file in multiple locations with the following priority:   | zls will look for a zls.json configuration file in multiple locations with the following priority:   | ||||||
| - In the folders open in your workspace (this applies for files in those folders)   |  | ||||||
| - In the local configuration folder of your OS (as provided by [known-folders](https://github.com/ziglibs/known-folders#folder-list))   | - In the local configuration folder of your OS (as provided by [known-folders](https://github.com/ziglibs/known-folders#folder-list))   | ||||||
| - In the same directory as the executable   | - In the same directory as the executable   | ||||||
| 
 | 
 | ||||||
| @ -58,7 +57,7 @@ The following options are currently available. | |||||||
| | `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. | | | `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. | | ||||||
| | `warn_style` | `bool` | `false` | Enables warnings for style *guideline* mismatches | | | `warn_style` | `bool` | `false` | Enables warnings for style *guideline* mismatches | | ||||||
| | `build_runner_path` | `?[]const u8` | `null` | Path to the build_runner.zig file provided by zls. This option must be present in one of the global configuration files to have any effect. `null` is equivalent to `${executable_directory}/build_runner.zig` | | | `build_runner_path` | `?[]const u8` | `null` | Path to the build_runner.zig file provided by zls. This option must be present in one of the global configuration files to have any effect. `null` is equivalent to `${executable_directory}/build_runner.zig` | | ||||||
| | `enable_semantic_tokens` | `bool` | `false` | Enables semantic token support when the client also supports it. | | | `enable_semantic_tokens` | `bool` | `true` | Enables semantic token support when the client also supports it. | | ||||||
| | `operator_completions` | `bool` | `true` | Enables `*` and `?` operators in completion lists. | | | `operator_completions` | `bool` | `true` | Enables `*` and `?` operators in completion lists. | | ||||||
| 
 | 
 | ||||||
| ## Features | ## Features | ||||||
|  | |||||||
							
								
								
									
										41
									
								
								build.zig
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								build.zig
									
									
									
									
									
								
							| @ -10,10 +10,46 @@ pub fn config(step: *std.build.Step) anyerror!void { | |||||||
|     @setEvalBranchQuota(2500); |     @setEvalBranchQuota(2500); | ||||||
|     std.debug.warn("Welcome to the ZLS configuration wizard! (insert mage emoji here)\n", .{}); |     std.debug.warn("Welcome to the ZLS configuration wizard! (insert mage emoji here)\n", .{}); | ||||||
| 
 | 
 | ||||||
|     const lib_path = try zinput.askDirPath(builder.allocator, "What is your Zig lib path (path that contains the 'std' folder)?", 512); |     var zig_exe_path: ?[]const u8 = null; | ||||||
|  |     std.debug.print("Looking for 'zig' in PATH...\n", .{}); | ||||||
|  |     find_zig: { | ||||||
|  |         const allocator = builder.allocator; | ||||||
|  |         const env_path = std.process.getEnvVarOwned(allocator, "PATH") catch |err| switch (err) { | ||||||
|  |             error.EnvironmentVariableNotFound => { | ||||||
|  |                 break :find_zig; | ||||||
|  |             }, | ||||||
|  |             else => return err, | ||||||
|  |         }; | ||||||
|  |         defer allocator.free(env_path); | ||||||
|  | 
 | ||||||
|  |         const exe_extension = @as(std.zig.CrossTarget, .{}).exeFileExt(); | ||||||
|  |         const zig_exe = try std.fmt.allocPrint(allocator, "zig{}", .{exe_extension}); | ||||||
|  |         defer allocator.free(zig_exe); | ||||||
|  | 
 | ||||||
|  |         var it = std.mem.tokenize(env_path, &[_]u8{std.fs.path.delimiter}); | ||||||
|  |         while (it.next()) |path| { | ||||||
|  |             const full_path = try std.fs.path.join(allocator, &[_][]const u8{ | ||||||
|  |                 path, | ||||||
|  |                 zig_exe, | ||||||
|  |             }); | ||||||
|  |             defer allocator.free(full_path); | ||||||
|  | 
 | ||||||
|  |             var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; | ||||||
|  |             zig_exe_path = try std.mem.dupe(allocator, u8, std.os.realpath(full_path, &buf) catch continue); | ||||||
|  |             break :find_zig; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (zig_exe_path == null) { | ||||||
|  |         std.debug.print("Could not find 'zig' in PATH\n", .{}); | ||||||
|  |         zig_exe_path = try zinput.askString(builder.allocator, "What is the path to the 'zig' executable you would like to use?", 512); | ||||||
|  |     } else { | ||||||
|  |         std.debug.print("Found zig executable '{}'\n", .{zig_exe_path.?}); | ||||||
|  |     } | ||||||
|     const snippets = try zinput.askBool("Do you want to enable snippets?"); |     const snippets = try zinput.askBool("Do you want to enable snippets?"); | ||||||
|     const style = try zinput.askBool("Do you want to enable style warnings?"); |     const style = try zinput.askBool("Do you want to enable style warnings?"); | ||||||
|     const semantic_tokens = try zinput.askBool("Do you want to enable semantic highlighting?"); |     const semantic_tokens = try zinput.askBool("Do you want to enable semantic highlighting?"); | ||||||
|  |     const operator_completions = try zinput.askBool("Do you want to enable .* and .? completions"); | ||||||
| 
 | 
 | ||||||
|     var dir = try std.fs.cwd().openDir(builder.exe_dir, .{}); |     var dir = try std.fs.cwd().openDir(builder.exe_dir, .{}); | ||||||
|     defer dir.close(); |     defer dir.close(); | ||||||
| @ -26,10 +62,11 @@ pub fn config(step: *std.build.Step) anyerror!void { | |||||||
|     std.debug.warn("Writing to config...\n", .{}); |     std.debug.warn("Writing to config...\n", .{}); | ||||||
| 
 | 
 | ||||||
|     const content = std.json.stringify(.{ |     const content = std.json.stringify(.{ | ||||||
|         .zig_lib_path = lib_path, |         .zig_exe_path = zig_exe_path, | ||||||
|         .enable_snippets = snippets, |         .enable_snippets = snippets, | ||||||
|         .warn_style = style, |         .warn_style = style, | ||||||
|         .enable_semantic_tokens = semantic_tokens, |         .enable_semantic_tokens = semantic_tokens, | ||||||
|  |         .operator_completions = operator_completions, | ||||||
|     }, std.json.StringifyOptions{}, out); |     }, std.json.StringifyOptions{}, out); | ||||||
| 
 | 
 | ||||||
|     std.debug.warn("Successfully saved configuration options!\n", .{}); |     std.debug.warn("Successfully saved configuration options!\n", .{}); | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ warn_style: bool = false, | |||||||
| build_runner_path: ?[]const u8 = null, | build_runner_path: ?[]const u8 = null, | ||||||
| 
 | 
 | ||||||
| /// Semantic token support | /// Semantic token support | ||||||
| enable_semantic_tokens: bool = false, | enable_semantic_tokens: bool = true, | ||||||
| 
 | 
 | ||||||
| /// Whether to enable `*` and `?` operators in completion lists | /// Whether to enable `*` and `?` operators in completion lists | ||||||
| operator_completions: bool = true, | operator_completions: bool = true, | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user