-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
Support for Operator type annotations #599
Comments
Considering performance issues, a new annotation should be provided for explicit marking. |
@sumneko but that is still something you can do inside of the LSP, right? |
My current assumption is this: ---@class A
---@operator add string
---@type A
local a
local r = a + 1 -- `r` is `string` here For performance reasons, you must define this explicitly, otherwise the cost performance from metatable search is too low. |
May I please instead suggest:
In order to cover: ---@class A
---@operator unm: A
---@operator add(A): A
---@operator add(number): number
---@type A
local a1
---@type A
local a2
local foo = a1 + a2 -- A
local bar = a1 + 1 -- number
local huzzah = -a1 -- A |
@Benjamin-Dobell This kind of generic support may bring a relatively large overhead, I don’t want to support it for the time being |
Sorry, just to to clarify, I'm not requesting you add all those operators or that you infer the right operand's type. Instead I'd like to try come up with a syntax that is at least future proof with respect to types, in order to avoid the pitfalls of LDoc. I'm the developer of Luanalysis. Luanalysis does not yet have this functionality but, when implemented, will use the right operand's type when inferring the resultant type of the expression. Even if you opt to ignore the right operand's type, it'd be ideal if we supported the same syntax. |
It looks good, and I will follow this format to implement it later (including compatibility and ignoring the type of operation object). |
@sumneko any news? :) |
Will support in 3.5.0 |
Done. |
@sumneko Will this also support extending current classes/types. For example, I've used penlight |
Please open a new issue and tell more details. |
How do I document an __index metamethod? I have a table which extends an arbitrary number of sub-elements via OriginalTableName.subElementName syntax. I have no idea how to tell the extension that the subElementNames are of type "blahBlahBlah" instead of it defaulting to "unknown". |
|
I have a question about the operator annotation. Is it also required if the operator metafunction is fully declared in the Lua file? Or is that detected separately? |
Operator annotation is required. |
Another question. What about the comparison operators? That is, eq / lt / le. Currently it reports those to be an unknown operator. |
Not supported yet. |
I'm also trying to type the
In the example above, |
class Example: {[number]: number} |
one can also use ---@class Example
---@operator call: string
---@field field fun(): number
---@field [any] number
local example = {}
local a = example.field() -- number
local b = example() -- string
local c = example[1] -- number
local d = example['2'] -- number |
It does not look like Emmy does have native support for Operator type annotations but I was wondering if it was possible to add it to the LSP?
The text was updated successfully, but these errors were encountered: