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

Feature request: clearer visual for optional parameters #138

Open
saralain opened this issue Dec 27, 2023 · 4 comments
Open

Feature request: clearer visual for optional parameters #138

saralain opened this issue Dec 27, 2023 · 4 comments

Comments

@saralain
Copy link

saralain commented Dec 27, 2023

In Lua documentation I'm able to mark a parameter as optional by setting the type to be (type|nil) (like @param optionalNum (number|nil) -- Optional number, defaults to 0. Some parsers, including Luau and VSCode's language server for Lua, support a question mark to mark a parameter as optional. (like @param optionalNum number? -- Optional number, defaults to 0) I'd like to see moonwave support both of these in a clear way.

Moonwave currently renders the nil union option just as the user wrote it, which is reasonable. I'd find it more useful if it translated this to marking the parameter as optional in documentation, though.

My proposal:

  • If a parameter or return value type is postfixed with ?, it should be translated to (existing type[s] | nil)
  • If a parameter's type contains a union with nil, the parameter should be visually marked as optional. Nil should be removed from rendered type unions

Here's a quick mockup of what it might look like:

--- @within Zoo
--- @param name string -- The name of penguin
--- @param marbles number? -- How many marbles the penguin has. Defaults to 5.
function Zoo:createPenguin(name, marbles) 
    -- ...code here...
end

image

ps: Thanks for writing this! I'm really appreciating having a node-based documentation tool for lua, especially one I'll be able to theme.

Semi-related to #4

@evaera
Copy link
Owner

evaera commented Jan 3, 2024

Optional function arguments are already covered in the "Writing Types" page:
https://eryn.io/moonwave/docs/Types#optional-function-arguments

@saralain saralain changed the title Feature request: optional parameters Feature request: clearer visual for optional parameters Jan 3, 2024
@saralain
Copy link
Author

saralain commented Jan 3, 2024

Yes, I am currently writing them in the way described on that page as a union with nil.

My request is to change how they appear - I have updated the title to clarify.

For a seasoned lua veteran, it's obvious that a union with nil means a parameter can be excluded. For a newbie, the word optional is a lot clearer.

The ? postfix is a nice-to-have, and probably could have been a separate issue

@evaera
Copy link
Owner

evaera commented Jan 3, 2024

I think I find the (optional) text afterwards a little bit harder to parse quickly than a question mark after the parameter name. It might be valuable to normalize the types to one style though instead of having param?: string, param: string? and param: string | nil as possible options.

@saralain
Copy link
Author

saralain commented Jan 3, 2024

Normalizing would definitely help me. If whatever indication is used has a separate css class that would solve all of my problems.

I'll note that I found the Types page a tiny bit confusing when I was first looking - I think param?: string, param: string? are both luau syntax, right? I'm not using luau, so that left me with the union. Testing though, it does seem like I can also put a ? on the name/type in the @param tag, which passes through to the ui wherever I put it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants