zls icon indicating copy to clipboard operation
zls copied to clipboard

support nested config options

Open Techatrix opened this issue 1 year ago • 4 comments

If we were to support generating config options with structs then they could be structured like the following example for inlay hints.

inlay_hints: ?struct {
    /// Enable type hints for variable declarations.
    /// ```zig
    /// test {
    ///     fn foo() error{OutOfMemory}!u32 {}
    ///     var result<u32> = try foo();
    /// }
    /// ```
    variable_type: bool = true,
    /// Enable type hints for captures.
    /// ```zig
    /// test {
    ///     var some_optional: ?u32 = 5;
    ///     if (some_optional) |int<u32>| {}
    /// }
    /// ```
    capture_type: bool = true,
    /// Enable type hints for anonymous struct literals.
    /// ```zig
    /// test {
    ///     const foo: struct { alpha: u32 } = .{ .alpha<u32> = 5 };
    /// }
    /// ```
    anonymous_literal_field_type: bool = true,
    /// Enable name hints for parameter names.
    /// ```zig
    /// test {
    ///     fn foo(alpha: u32, beta: []const u8) void {}
    ///     foo(<alpha> 5, <beta> "some string");
    /// }
    /// ```
    parameter_name: ?struct {
        /// Enable inlay hints for builtin functions.
        /// ```zig
        /// test {
        ///     @mod(<numerator> 8, <denominator> 3)
        /// }
        /// ```
        builtin: bool = true,
        /// Enable inlay hints for single argument calls.
        /// ```zig
        /// fn foo(a: []const u8) void {}
        /// fn bar(a: []const u8, b: []const u8) void {}
        /// test {
        ///     // single_argument=true
        ///     foo(<a> "");
        ///     bar(<a> "", <b> "");
        ///     // single_argument=false
        ///     foo("");
        ///     bar(<a> "", <b> "");
        /// }
        /// ```
        single_argument: bool = true,
        /// Enable inlay hints for redundant parameter names.
        hide_redundant: enum {
            off,
            /// Hide parameter name when the argument is an identifier that matches the parameter name.
            /// ```zig
            /// fn func(alpha: u32) void {}
            /// test {
            ///     var alpha: u32 = 5;
            ///     func(alpha);
            ///     func(<alpha> 5);
            /// }
            /// ```
            same_name,
            /// Hide parameter name when last token of the argument matches the parameter name.
            /// ```zig
            /// fn func(alpha: u32) void {}
            /// test {
            ///     const alpha: u32 = 5;
            ///     const beta: u32 = 5;
            ///     const s = .{ .alpha = 5, .beta = 5 };
            ///
            ///     func(alpha);
            ///     func(<alpha> &beta);
            ///
            ///     func(foo.alpha);
            ///     func(<alpha> foo.beta);
            ///
            ///     func(&alpha);
            ///     func(<alpha> &beta);
            /// }
            /// ```
            same_last_token,
        } = .off,
    } = .{},
} = .{},

Techatrix avatar Feb 18 '24 02:02 Techatrix

same_name and same_last_token aren't mutually exclusive though, should be bools?

llogick avatar Feb 18 '24 02:02 llogick

same_name and same_last_token aren't mutually exclusive though, should be bools?

So could you give an example where same_name applies but same_last_token doesn't.

Techatrix avatar Feb 18 '24 03:02 Techatrix

same_name and same_last_token aren't mutually exclusive though, should be bools?

So could you give an example where same_name but same_last_token doesn't.

I were going off of the current implementation, but as proposed the only token could be considered the last token :)

Current: 'inlay_hints_hide_redundant_param_names_last_token' to 'true' others default inlay_off_if_last_token_match

llogick avatar Feb 18 '24 03:02 llogick

I should have checked this but the func(alpha) case just doesn't make any sense to me.

Techatrix avatar Feb 18 '24 04:02 Techatrix