rhaiscript / lsp

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

Recognize function pointers as functions (`Fn("foo")` => `fn foo(...)`) #78

Open schungx opened 2 years ago

schungx commented 2 years ago

@tamasfe I have a new drop in the repo that implements a convenient shorthand to create function pointers.

fn fib(a) { ... }

let fp = Fn("fib");    // original syntax

let fp = fib;        // new syntax, de-sugars to Fn("fib")

The LSP may need to be aware of this, as it might flag fib as an undeclared variable.

tamasfe commented 2 years ago

Alright, I was under the assumption that it was already valid. Currently doing this is legal in the lsp's HIR already.

I will turn the issue around, Fn("foo") should be recognized as a reference to an existing function.

Although it will only make sense after the type system.

schungx commented 2 years ago

Alright, I was under the assumption that it was already valid. Currently doing this is legal in the lsp's HIR already.

If I press F12 on foo, would it jump to the function definition?

EDIT: Nope. It doesn't jump to the definition. However, it is recognized as a function with popup and everything. That is great. Only the jump-to-def doesn't work.

tamasfe commented 2 years ago

If I press F12 on foo, would it jump to the function definition?

It should, otherwise it's a bug.

schungx commented 2 years ago

It should, otherwise it's a bug.

Popups work correctly. However, references and definitions do not work.

tamasfe commented 2 years ago

Popups work correctly. However, references and definitions do not work.

I haven't been able to reproduce this, I see no reason for it not to work as there is not a lot of difference between functions and const/let definitions regarding this.

schungx commented 2 years ago

I'll test again and let you know...

schungx commented 2 years ago

Popup works:

image

Pressing F12

image

Pressing Shift-F12

image

schungx commented 2 years ago

OK. I found out the reason.

When definition files conflict, F12 and Shift+F12 seems to jump all over the place.

For example, when we have separate definition files under definitions/.rhai/definitions, but at the same time we have an all_in_one.d.rhai, then they conflict and it seems random.

Removing all_in_one.d.rhai resolves it.