[feat] generics: capture types with backticks - #3149
Conversation
|
I think there is a big problem here: 😕
just using your example above PS: I am not maintainer of LuaLS, just one of the contributors. |
|
No problem, I will review that case and update the PR |
|
Hello @tomlau10 . I looked at this after your feeback. I would leave the PR as-is. This indeed can end up creating weird types, but when you are using string you can also do weird stuff, namely, you can call I have another variant of the code that works as follows: Meaning, Let me know which one would work best. I am fine either way. If not, what would you expect in such cases? My use case is, I am writing Lua bindings for a major ECS, we need a syntax as follows: Please let me know your thoughts. |
When using literal string, I don't think anyone would write Moreover, the current implementation would give inconsistent result in some of the following cases:
I personally think skipping Again I am not author of LuaLS, so this may need opinions from maintainers. 🤔 |
Maybe we could get something like: |
|
Since there is a And if |
|
I believe that too many peculiar syntaxes have been added to sumneko for various workarounds. This is neither consistent nor does it add cognitive burden. I think a better syntax would be to use built-in special generic classes based on supporting generics. Of course, this is just a suggestion. I understand that implementing this in LuaLS might be somewhat difficult. |
|
If there is no exact planning on the syntax of how
|
I agree this is the syntax that would make sense, but it is not how the backticks capture works right now unfortunately. @CppCXY @tomlau10 So I agree with @tomlau10 :
... but adding the extra that |
Yes, that's what I mean 😄
|
e1ac726 to
e40a933
Compare
This PR modifies the generics capture system to allow to capture types out of the type of the parameter passed, in addition to being able to pass the type as a string which is the way it currently works:
Currently:
Now, the following is also possible:
Therefore, it is possible to pass a literal string that happens to be a type name like before, or otherwise pass an expression that evaluates to a type and that type will be captured with backticks. This allows to construct typings for functions that return different types that depend on the type of the object passed.