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

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

Open
schungx opened this issue Aug 6, 2022 · 8 comments
Open
Labels
A-HIR Area: HIR A-LSP Area: LSP E-Medium enhancement P-Low Priority: Low T-Types Related to the type system

Comments

@schungx
Copy link
Collaborator

schungx commented Aug 6, 2022

@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
Copy link
Member

tamasfe commented Aug 6, 2022

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.

@tamasfe tamasfe added enhancement A-LSP Area: LSP E-Medium A-HIR Area: HIR P-Low Priority: Low labels Aug 6, 2022
@tamasfe tamasfe changed the title Function pointer short-hand Recognize function pointers as functions (Fn("foo") => fn foo(...)) Aug 6, 2022
@tamasfe tamasfe changed the title Recognize function pointers as functions (Fn("foo") => fn foo(...)) Recognize function pointers as functions (Fn("foo") => fn foo(...)) Aug 6, 2022
@schungx
Copy link
Collaborator Author

schungx commented Aug 6, 2022

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
Copy link
Member

tamasfe commented Aug 6, 2022

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

It should, otherwise it's a bug.

@schungx
Copy link
Collaborator Author

schungx commented Aug 6, 2022

It should, otherwise it's a bug.

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

@tamasfe
Copy link
Member

tamasfe commented Aug 6, 2022

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
Copy link
Collaborator Author

schungx commented Aug 7, 2022

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

@schungx
Copy link
Collaborator Author

schungx commented Aug 7, 2022

Popup works:

image

Pressing F12

image

Pressing Shift-F12

image

@schungx
Copy link
Collaborator Author

schungx commented Aug 7, 2022

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.

@tamasfe tamasfe added the T-Types Related to the type system label Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: HIR A-LSP Area: LSP E-Medium enhancement P-Low Priority: Low T-Types Related to the type system
Projects
None yet
Development

No branches or pull requests

2 participants