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

Autocomplete named arguments of functions #372

Open
Jollywatt opened this issue Jun 10, 2024 · 4 comments
Open

Autocomplete named arguments of functions #372

Jollywatt opened this issue Jun 10, 2024 · 4 comments
Labels
editor Related to the text/markup editor. feature request New feature or request.

Comments

@Jollywatt
Copy link

Description

When you type an element function, like text() or image(), the editor shows a list of all the named and positional arguments. The same does not happen for functions like datetime() or any user-defined function.

Use Case

Autocompletion of named arguments on user-defined functions would in particular make learning how to use packages easier. For instance, fletcher has a diagram() function with many named arguments, but to discover them requires looking at package docs.

@Jollywatt Jollywatt added the feature request New feature or request. label Jun 10, 2024
@Jollywatt
Copy link
Author

I think this is worth adding, even if showing a docstring for each argument is not possible.

For added context, I bring this up because I am refactoring fletcher to give constructive error messages when unknown named arguments are given. Consider turning this:

#let my-function(a: 1, b: 2, c: 3, d: 4) = { .. }

…into this:

#let allowed = (a: 1, b: 2, c: 3, d: 4)
#let my-function(..args) = {
  for k in args.named().keys() {
    if k not in allowed.keys() {
      panic("Invalid named argument " + k + ". Allowed values are: " + allowed.keys().join(", "))
    }
  }
  let args-with-defaults = allowed + args.named()
  ..
}

This is a lot of boiler plate to achieve a slightly better onboarding experience for new users.

However, this refactoring is objectively worse if the web app ever gets an autocomplete feature for functions, since that wouldn't work with the argument sink. So it would be good to know if this is feasible:)

@Myriad-Dreamin
Copy link

this is already implemented in local LSP and will be contributed to official repo once the feature becomes mature. You could follow the forge discussing them https://discord.com/channels/1054443721975922748/1229699205786898485.

image

@Jollywatt
Copy link
Author

Yay, this is fantastic to hear!

I'm impressed that even the function's docstring is shown. Can the LS currently do the same for function arguments, too?

@Myriad-Dreamin
Copy link

I'm impressed that even the function's docstring is shown. Can the LS currently do the same for function arguments, too?

For the documentation of parameters, It should be difficult as we have no official format of documentation, but there is a unofficial guideline which LS might follow to extract the docs, typst-community/guidelines#8.

@laurmaedje laurmaedje added the editor Related to the text/markup editor. label Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor Related to the text/markup editor. feature request New feature or request.
Projects
None yet
Development

No branches or pull requests

3 participants