lua-language-server
lua-language-server copied to clipboard
[Feature Request] Support nonstandardSymbol for Lambda-Style Functions
I've been working on writing a definition file for Tabletop Simulator's Lua API.
The lua runtime used by Tabletop Simulator is a subset of Moonsharp (currently version 2.0.0.0). While it would be great if we could get support for Moonsharp as a runtime option, I realize the amount of effort that would require.
For the most part, it's straightforward to write definition files for the functionality added by Moonsharp.
However, Moonsharp adds additional syntax: the use of || for lambda style functions (aka closures).
It looks like this:
|[,args]| expression
Which is shorthand for
function(args) return expression end
Unfortunately, || is already used for the "or" nonstandard symbol, so I'm not sure how to mark this.
I'm working with a similar syntax, a,b -> expr.
I was able to disable warnings for the lines my expression is used on with a plugin, though this doesn't properly integrate with the language server. You might be able to transform your syntax into the regular Lua syntax, which the language server would work with.
function OnSetText(uri, text)
local diffs = {}
for line in text:gmatch("->[^\n]*()") do
diffs[#diffs+1] = {
start = line - 1,
finish = line - 1,
text = "--[[@diagnostic disable-line: undefined-global, unknown-symbol, redundant-parameter]]"
}
end
return diffs
end
I'm working with a similar syntax,
a,b -> expr.I was able to disable warnings for the lines my expression is used on with a plugin, though this doesn't properly integrate with the language server. You might be able to transform your syntax into the regular Lua syntax, which the language server would work with.
function OnSetText(uri, text) local diffs = {} for line in text:gmatch("->[^\n]*()") do diffs[#diffs+1] = { start = line - 1, finish = line - 1, text = "--[[@diagnostic disable-line: undefined-global, unknown-symbol, redundant-parameter]]" } end return diffs end
Yeah so I looked into this and realized it was the route I would have to take until this is supported. However, your precise solution is brittle from my perspective as it doesn't respect the precise syntax of lua expressions. (Stopping at a newline?). Also wouldn't support nested lambda expressions. I would need to hook into something like LPEG. From my point of view, if I can't give it full and proper support, it's better to give no support.