Closed AndreasMatthias closed 1 year ago
I'm not familiar with the lpeg API, but does the pattern have to be userdata
? Can't you define a class for the pattern with the appropriate operators?
e.g.
---@class lpeg
local lpeg = {}
---@class lpeg_pattern
---@operator pow(number) : lpeg_pattern
---@param set string
---@return lpeg_pattern # Lpeg pattern.
function lpeg.S(set)
end
---@param patt lpeg_pattern # Lpeg pattern.
---@param subject string # String to be matched.
---@param start? integer # Index.
---@return integer | string | table
function lpeg.match(patt, subject, start)
end
By the way, it looks like there's already an addon/library for lpeg: https://github.com/LuaCATS/lpeg/blob/e4115543d25d72c3aeae87d36a100a4e7ff8eea0/library/lpeg.lua
Perhaps you can use it directly or as an inspiration.
I'm not familiar with the lpeg API, but does the pattern have to be
userdata
? Can't you define a class for the pattern with the appropriate operators?
This is very good idea. And now the tooltips display the name of the class instead of userdata
which is even better.
By the way, it looks like there's already an addon/library for lpeg: https://github.com/LuaCATS/lpeg/blob/e4115543d25d72c3aeae87d36a100a4e7ff8eea0/library/lpeg.lua
Oh, I guess this is exactly what I was looking for. Thank you.
How are you using the lua-language-server?
Other
Which OS are you using?
Linux
What is the issue affecting?
Type Checking
Expected Behaviour
In the example given below, variable
ab
shall have typeuserdata
.Actual Behaviour
Variable
ab
has typenumber
.Reproduction steps
I have this meta definition file:
And this is the actual lua file:
Now lsp-language-server reports a warning for function
match
sayingCannot assign 'number' to parameter 'userdata'
. Functionmatch
expects auserdata
as first argument, but lsp-language-server things that variableab
is of typenumber
.Additional Notes
No response
Log File
No response