Add config option, fix config wizard, fix random crash and extern unused highlighting
This commit is contained in:
		
							parent
							
								
									43c61b3da6
								
							
						
					
					
						commit
						3b33750f59
					
				@ -101,6 +101,7 @@ The following options are currently available.
 | 
			
		||||
| --- | --- | --- | --- |
 | 
			
		||||
| `enable_snippets` | `bool` | `false` | Enables snippet completions when the client also supports them. |
 | 
			
		||||
| `enable_unused_variable_warnings` | `bool` | `false`| Enables warnings for local variables that aren't used. |
 | 
			
		||||
| `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. |
 | 
			
		||||
| `warn_style` | `bool` | `false` | Enables warnings for style *guideline* mismatches |
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,9 @@ enable_snippets: bool = false,
 | 
			
		||||
/// Whether to enable unused variable warnings
 | 
			
		||||
enable_unused_variable_warnings: 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,
 | 
			
		||||
 | 
			
		||||
/// zig library path
 | 
			
		||||
zig_lib_path: ?[]const u8 = null,
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								src/main.zig
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/main.zig
									
									
									
									
									
								
							@ -231,9 +231,16 @@ fn publishDiagnostics(arena: *std.heap.ArenaAllocator, handle: DocumentStore.Han
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (config.enable_unused_variable_warnings) {
 | 
			
		||||
        for (handle.document_scope.scopes) |scope| {
 | 
			
		||||
        scopes: for (handle.document_scope.scopes) |scope| {
 | 
			
		||||
            const scope_data = switch (scope.data) {
 | 
			
		||||
                .function => |f| f,
 | 
			
		||||
                .function => |f| b: {
 | 
			
		||||
                    var buf: [1]std.zig.Ast.Node.Index = undefined;
 | 
			
		||||
                    var proto = ast.fnProto(tree, f, &buf) orelse break :b f;
 | 
			
		||||
                    if (proto.extern_export_inline_token) |tok| {
 | 
			
		||||
                        if (std.mem.eql(u8, tree.tokenSlice(tok), "extern")) continue :scopes;
 | 
			
		||||
                    }
 | 
			
		||||
                    break :b f;
 | 
			
		||||
                },
 | 
			
		||||
                .block => |b| b,
 | 
			
		||||
                else => continue,
 | 
			
		||||
            };
 | 
			
		||||
@ -769,13 +776,13 @@ fn hoverSymbol(id: types.RequestId, arena: *std.heap.ArenaAllocator, decl_handle
 | 
			
		||||
    const resolved_type = try decl_handle.resolveType(&document_store, arena, &bound_type_params);
 | 
			
		||||
 | 
			
		||||
    const resolved_type_str = if (resolved_type) |rt|
 | 
			
		||||
        if (rt.type.is_type_val) "type" else switch (rt.type.data) {
 | 
			
		||||
        if (rt.type.is_type_val) "type" else switch (rt.type.data) { // TODO: Investigate random weird numbers like 897 that cause index of bounds
 | 
			
		||||
            .pointer,
 | 
			
		||||
            .slice,
 | 
			
		||||
            .error_union,
 | 
			
		||||
            .primitive,
 | 
			
		||||
            => |p| tree.getNodeSource(p),
 | 
			
		||||
            .other => |p| switch (tree.nodes.items(.tag)[p]) {
 | 
			
		||||
            => |p| if (p >= tree.nodes.len) "unknown" else tree.getNodeSource(p),
 | 
			
		||||
            .other => |p| if (p >= tree.nodes.len) "unknown" else switch (tree.nodes.items(.tag)[p]) {
 | 
			
		||||
                .container_decl,
 | 
			
		||||
                .container_decl_arg,
 | 
			
		||||
                .container_decl_arg_trailing,
 | 
			
		||||
@ -1587,6 +1594,8 @@ fn documentSymbol(arena: *std.heap.ArenaAllocator, id: types.RequestId, handle:
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn loadConfigFile(file_path: []const u8) ?Config {
 | 
			
		||||
    @setEvalBranchQuota(5000);
 | 
			
		||||
 | 
			
		||||
    const tracy_zone = tracy.trace(@src());
 | 
			
		||||
    defer tracy_zone.end();
 | 
			
		||||
 | 
			
		||||
@ -1855,6 +1864,9 @@ fn completionHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req:
 | 
			
		||||
        .enum_literal => try completeDot(arena, id, handle, config),
 | 
			
		||||
        .label => try completeLabel(arena, id, doc_position.absolute_index, handle, config),
 | 
			
		||||
        .import_string_literal, .embedfile_string_literal => |loc| {
 | 
			
		||||
            if (!config.enable_import_embedfile_argument_completions)
 | 
			
		||||
                return try respondGeneric(id, no_completions_response);
 | 
			
		||||
 | 
			
		||||
            const line_mem_start = @ptrToInt(doc_position.line.ptr) - @ptrToInt(handle.document.mem.ptr);
 | 
			
		||||
            const completing = handle.tree.source[line_mem_start + loc.start + 1 .. line_mem_start + loc.end];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -264,6 +264,7 @@ pub const Configuration = struct {
 | 
			
		||||
        settings: struct {
 | 
			
		||||
            enable_snippets: ?bool,
 | 
			
		||||
            enable_unused_variable_warnings: ?bool,
 | 
			
		||||
            enable_import_embedfile_argument_completions: ?bool,
 | 
			
		||||
            zig_lib_path: ?[]const u8,
 | 
			
		||||
            zig_exe_path: ?[]const u8,
 | 
			
		||||
            warn_style: ?bool,
 | 
			
		||||
 | 
			
		||||
@ -170,6 +170,8 @@ 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, Other });
 | 
			
		||||
    const snippets = try askBool("Do you want to enable snippets?");
 | 
			
		||||
    const unused_variables = try askBool("Do you want to enable unused variable warnings?");
 | 
			
		||||
    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?");
 | 
			
		||||
    const operator_completions = try askBool("Do you want to enable .* and .? completions?");
 | 
			
		||||
@ -188,6 +190,8 @@ pub fn wizard(allocator: std.mem.Allocator) !void {
 | 
			
		||||
    try std.json.stringify(.{
 | 
			
		||||
        .zig_exe_path = zig_exe_path,
 | 
			
		||||
        .enable_snippets = snippets,
 | 
			
		||||
        .enable_unused_variable_warnings = unused_variables,
 | 
			
		||||
        .enable_import_embedfile_argument_completions = ief_apc,
 | 
			
		||||
        .warn_style = style,
 | 
			
		||||
        .enable_semantic_tokens = semantic_tokens,
 | 
			
		||||
        .operator_completions = operator_completions,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user