Open Jollywatt opened 5 months ago
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:)
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.
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?
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, https://github.com/typst-community/guidelines/pull/8.
Description
When you type an element function, like
text()
orimage()
, the editor shows a list of all the named and positional arguments. The same does not happen for functions likedatetime()
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.