pigpigyyy / Yuescript

A Moonscript dialect compiles to Lua.
http://yuescript.org
MIT License
443 stars 38 forks source link

Preserve comments preceding global declarations #126

Open Seirdy opened 1 year ago

Seirdy commented 1 year ago

Existing issues, such as #58 and #57, have requested support for static type annotations. A less extreme solution would be to preserve comments containing Sumneko's annotations for use with their Lua language server. This way, the resulting Lua code will be identical but still support type-checking. It could also improve interoperability with other documentation generators.

The Yuescript tool could expose an option to preserve comments directly before global declarations, e.g. those displayed by yue -g

pigpigyyy commented 1 year ago

added option yue -c to reserve some comments before statements, like

---@param a any
---@param b any
---@param c any
f = (a, b, c)->

But not sure if this works for the Lua LSP functions.

GokuHiki commented 1 year ago

I have custom script that use yue module to compile to lua. Can you make 'reserve_comment' support in yue module!

Thanks and regards!

pigpigyyy commented 1 year ago

'reserve_comment' was added in module. Should be available as

local yue = require("yue")
print yue.to_lua([[
-- a comment
f = ->
]], {reserve_comment = true})
SkyyySi commented 1 year ago

Shouldn't it be preserve_comment (with a p in the beginning)?

pigpigyyy commented 1 year ago

"preserve" and "reserve" both have the meaning of keeping something, while "reserve" is just for keeping something for future use, the "preserve" word has more meaning of keeping something from harm (protect). So I think using the "reserve" word could be better.