You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Sorry, just to to clarify, I'm not requesting you add all those operators. Instead I'd like to try come up with a syntax that is 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).
Reacted by Benjamin Staneck, Benjamin Dobell, Martin Paucot and Celtic Minstrel
@sumneko Will this also support extending current classes/types. For example, I've used penlight stringx.format_operator which allows "%d %d" % {2,3}. This shows up as a param-type-mismatch.
@sumneko Will this also support extending current classes/types. For example, I've used penlight stringx.format_operator which allows "%d %d" % {2,3}. This shows up as a param-type-mismatch.
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".
Reacted by Luiz Henrique Oliveira Martins and Konrad Kozubek
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?
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?
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".
---@class Cat: Animal
I'm also trying to type the index operator in my class, but I didn't quite understand what this means. As an example:
---@class Example
---@operator call: string
---@field field fun(): number
local example = setmetatable({}, {
__call = function(_, ...)
return "a"
end,
__index = function(_, key)
return 1
end,
field = function() return 2 end,
})
local a = example.field()
local b = example()
local c = example[1]
In the example above, a is correctly deduced as a number, and b is correctly deduced as a string, but c is unknown. Is it possible to make the LSP deduce c to be a number?
Activity
sumneko commentedon Jul 15, 2021
Considering performance issues, a new annotation should be provided for explicit marking.
Stanzilla commentedon Jul 15, 2021
@sumneko but that is still something you can do inside of the LSP, right?
sumneko commentedon Jul 16, 2021
My current assumption is this:
For performance reasons, you must define this explicitly, otherwise the cost performance from metatable search is too low.
Benjamin-Dobell commentedon Jul 17, 2021
May I please instead suggest:
In order to cover:
sumneko commentedon Jul 19, 2021
@Benjamin-Dobell This kind of generic support may bring a relatively large overhead, I don’t want to support it for the time being
Benjamin-Dobell commentedon Jul 19, 2021
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.
sumneko commentedon Jul 19, 2021
It looks good, and I will follow this format to implement it later (including compatibility and ignoring the type of operation object).
Stanzilla commentedon Jun 22, 2022
@sumneko any news? :)
sumneko commentedon Jun 23, 2022
Will support in 3.5.0
sumneko commentedon Jul 6, 2022
Done.
nathanpage-credo commentedon Jul 7, 2022
@sumneko Will this also support extending current classes/types. For example, I've used penlight
stringx.format_operatorwhich allows"%d %d" % {2,3}. This shows up as a param-type-mismatch.sumneko commentedon Jul 7, 2022
Please open a new issue and tell more details.
add: description for @operator LuaLS#599
BribeFromTheHive commentedon Nov 19, 2022
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".
sumneko commentedon Nov 21, 2022
---@class Cat: AnimalCelticMinstrel commentedon Feb 5, 2023
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?
sumneko commentedon Feb 6, 2023
Operator annotation is required.
CelticMinstrel commentedon Feb 6, 2023
Another question. What about the comparison operators? That is, eq / lt / le. Currently it reports those to be an unknown operator.
sumneko commentedon Feb 6, 2023
Not supported yet.
If you have other questions or feature requests, please open a new issue.
luiz00martins commentedon Nov 8, 2024
I'm also trying to type the
indexoperator in my class, but I didn't quite understand what this means. As an example:In the example above,
ais correctly deduced as a number, andbis correctly deduced as a string, butcis unknown. Is it possible to make the LSP deducecto be a number?BribeFromTheHive commentedon Nov 8, 2024
class Example: {[number]: number}
tomlau10 commentedon Nov 8, 2024
one can also use
---@field [KeyType] ValueTypeto define the index operation type