Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support nested config options #1780

Open
Techatrix opened this issue Feb 18, 2024 · 4 comments
Open

support nested config options #1780

Techatrix opened this issue Feb 18, 2024 · 4 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@Techatrix
Copy link
Member

If we were to supported 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 Techatrix added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 18, 2024
@llogick
Copy link
Member

llogick commented Feb 18, 2024

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

@Techatrix
Copy link
Member Author

Techatrix commented Feb 18, 2024

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.

@llogick
Copy link
Member

llogick commented Feb 18, 2024

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

@Techatrix
Copy link
Member Author

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

Techatrix added a commit that referenced this issue Feb 19, 2024
"inlay_hints_hide_redundant_param_names_last_token" is now a strict
superset of "inlay_hints_hide_redundant_param_names".

This has been discussed in #1780
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants