lemmy-help
lemmy-help copied to clipboard
Annotations not detected for wrapped function
Not sure if this is a missing feature or if I'm doing something wrong, but I have some functions that I create using a higher order function. For example:
local function wrap(arg1, arg2)
return function(...)
-- Do work
end
end
---@param foo string
---@param bar integer
M.exported_fn = wrap('a', 'b')
In this example, I can't get exported_fn
to be picked up by lemmy-help. Is there something else I should be doing to get it to detect properly?
Higher order functions are not supported as the parser doesn't know that M.exported_fn
is actually a function. Currently, only these types of function signature are supported.
Got it. I'd like to leave this open as a feature request then
I am not sure how to parse it without the function
keyword in M.exported_fn
as the parser is top-down and doesn't analyse the AST like a LSP.
If you have any idea on how to implement this then i would love to hear that :)
With the caveat that I haven't looked at any of the code, it seems like this should be discoverable by searching for ---@param
and/or ---@return
annotations, ignoring the code entirely. I can't think of a case where those would be present and the annotated object is not a function.
I can't think of a case where those would be present, and the annotated object is not a function.
Yes, your assumption is right, but the problem is when tokenizer reaches M.exported_fn =<cursor>
it doesn't know whether the value is a function or an expression. So, to tokenize as a function it looks for function
keyword
https://github.com/numToStr/lemmy-help/blob/9ffda157f84e3045723482ce3032be6d4a5b0bcb/src/parser/emmy.rs#L251-L256
it seems like this should be discoverable by searching for
---@param
and/or---@return
annotations, ignoring the code entirely
Only parser knows the AST structure and to build the function's AST it needs that token (above) https://github.com/numToStr/lemmy-help/blob/9ffda157f84e3045723482ce3032be6d4a5b0bcb/src/parser/tags/func.rs#L56-L65