alefragnani / vscode-separators

Separators Extension for Visual Studio Code
GNU General Public License v3.0
40 stars 6 forks source link

[FEATURE] - Lua - separators.functions.ignoreCallbackInline #50

Closed CarlosLeyvaAyala closed 3 years ago

CarlosLeyvaAyala commented 3 years ago

Hi. I'd like to ask if it is possible to add support for Lua for the functions.ignoreCallbackInline setting.

Here are some sample functions with inlines:

separators-inline-lua

And their respective structure in the outline:

separators-inline-lua-outline

alefragnani commented 3 years ago

Hi @CarlosLeyvaAyala ,

Could you please update the outline picture with the whole line content, so I could better understand how VS Code/Lua Language Server describes a callback function?

Thanks in advance

CarlosLeyvaAyala commented 3 years ago

Like this?

2021-08-22 13_30_25-__test lua

BTW, I also found some kinda real code that use more inline anonymous functions that get detected. I hope this also helps :)

2021-08-22 13_31_21

2021-08-22 13_33_28-__test lua

alefragnani commented 3 years ago

I guess so 😄

Only those described as <Anonymous>, with a -> function detail are Callback Inline, right?

CarlosLeyvaAyala commented 3 years ago

There's also a named inline function called me2 in the second screen I took (typo), but correctly named meh2 in my first message. It belongs to meh:

meh2

That function is the equivalent to having a void => void signature, or something; that's why it's so easy to overlook.

alefragnani commented 3 years ago

But this one is not a callback right? It seems just an inline/anonymous declaration.

I never worked with Lua, so I can't say for sure. I'm just comparing to other languages I play with.

CarlosLeyvaAyala commented 3 years ago

That's right. It's not a callback.

In Lua all functions that can be declared both as a variable and as a function statement:

2021-08-24 15_00_56-__test lua - Max-Sick-Gains-src - Visual Studio Code

2021-08-24 15_14_04-

Those functions can only be used inside the function where it were defined, as expected. Look at how this is actually complaining that inlineVoid hasn't been defined:

2021-08-24 15_16_31-__test lua - Max-Sick-

If I take out that problematic line and run the code above, I get this:

Printed 5
Anon printed    5
Printed 5
Anon printed    15
Printed 5
Anon printed    25

When you evaluate the resulting anonymous function:
Result print    5

I could have declared all those inlines in a single line like I did with addAnon, by the way. Sadly (fortunately to you, so you don't have to take so many cases into account? xD), in vanilla Lua there's nothing like lambda notation, "fat arrows", or whatever, to make one liners more succint. If you want to declare a one line function, it ought to have the whole body declaration, like this:

function OneLiner() end
OneLinerAnon = function() end
alefragnani commented 3 years ago

That's great!

BTW, which Lua extension are you using, and how it does identify Lua files? Simply lua?

I need to know this, to properly identify the files and to filter the symbols.

Thank you

CarlosLeyvaAyala commented 3 years ago

I use Lua.

I'm not sure how it recognizes files, other than the *.lua extension. As far as I know, that's the only extension for Lua files and searching for other extensions gave me nothing.

BTW, I'm the one that should thank you for your patience.

alefragnani commented 3 years ago

It's not the file extension, but how the extension declares the language Id (lua). Looking at extension's source I'm able to find.

I don't have a setup to try out, but I hope the details you provided (and my interpretation) will be enough. It should be available next month, right after VSCode release.

BTW, I'm the one that should thank you for your patience.

Thank you too for providing the details. Without that, the feature wouldn't be released (at least, not by me) 😬

Thank you

CarlosLeyvaAyala commented 3 years ago

Thank you so much! If more info is needed, I hope I can provide it. Don't hesitate to ask me.

alefragnani commented 3 years ago

Let's hope it works out of the box, otherwise will be you asking me, for a fix 😆

It should be available next week.

Stay tuned

ypnos commented 3 years ago

I tried this option and unfortunately, it seems it doesn't do the trick for me:

image

Purple lines are from Separators plugin v2.3.0. The setting is set:

    "separators.functions.ignoreCallbackInline": true,

Happy to help with debugging.

alefragnani commented 3 years ago

Hi @ypnos ,

As described in the comment above (https://github.com/alefragnani/vscode-separators/issues/50#issuecomment-903334676) these are not considered callbacks.

These ones are just inline/anonymous functions.

Hope this helps

ypnos commented 3 years ago

Ok so I just misunderstood, I thought "ignoreCallbackInline" means "ignore callback and inline". I understand it better now.

Here is example code to confirm that it works: image

alefragnani commented 3 years ago

No problem. If you misunderstood, it means the setting is not so clear, and the documentation needs improvement.

Anyway, if you miss the possibility to ignore inline/anonymous functions, this could be accomplished with a new setting. Feel free to open a new issue for that, providing the details to identify/differentiate inline / anonymous functions.

Hope this helps

alefragnani commented 3 years ago

BTW, thank you for the confirmation the current setting is working 👍