rhaiscript / lsp

Language server for Rhai.
Apache License 2.0
43 stars 4 forks source link

Add definitions for built-in functions. #56

Closed schungx closed 2 years ago

schungx commented 2 years ago

@tamasfe These are definitions for all the built-in functions.

tamasfe commented 2 years ago

Thanks! There are some decisions we'll have to make regarding types, I left some comments about those, otherwise LGTM.

schungx commented 2 years ago

@tamasfe I've changed all &str to String for the time being, and INT to i64.

Also, a couple of additions for ?? and ?. to the syntax highlighting.

schungx commented 2 years ago

@tamasfe If you're ok with this, then I'll press the "Merge" button. :-)

Or maybe better you do it!

tamasfe commented 2 years ago

@schungx Sorry, sure, looks good. There are 2 things I'm concerned about, none of which block this PR:

schungx commented 2 years ago

Agree on both counts. As for ?, I guess it is as good as anything else. In the actual docs generated in JSON, the catch-all type will be Dynamic, which is a mouthful. It is a much better syntax to use ?.

As for ..., that is because Rhai has no variable-parameter functions (all functions have fixed number of parameters). However, a number of built-in functions do take variable number of parameters (such as curry and call). Thus, it sort of needs a way to document this fact... or we can leave off the signature for curry and call.

Thus, a solution is to have syntax for marking types and var-args that is not supported by Rhai itself - in that case using ? to replace Dynamic would be ok. Also the spread operator can be used for func definitions, but not supported by Rhai itself.

tamasfe commented 2 years ago

Thus, it sort of needs a way to document this fact... or we can leave off the signature for curry and call.

They should be a part of the definitions for sure, I'll implement the spread syntax and we can restrict it to some blessed built-in functions on the HIR level.

tamasfe commented 2 years ago

I added the missing ? for the time being since the parser expects a type. I'll have to also change the function return syntax from : to -> as well.