Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua 5.2 label syntax error when using binary built all features enabled #407

Open
Feez opened this issue Mar 12, 2022 · 5 comments
Open
Labels
external This issue relies on an external factor
Milestone

Comments

@Feez
Copy link

Feez commented Mar 12, 2022

I was experimenting with using StyLua on minified Lua, and found that StyLua fails to parse this valid Lua when minified.

source:

local function test()
    goto end_thing

    local x = 1

    ::end_thing::
end

-> minified:

local function a()goto b;local c=1::b::end

with error:

error: could not format file minified.lua: error parsing: unexpected token `end`. (starting from line 1, character 40 
and ending on line 1, character 43)
additional information: expected identifier after `::`

If I add a semicolon after local c = 1 in the minified Lua then it parses as expected.

@JohnnyMorganz
Copy link
Owner

I assume this is through downloading the binaries from GitHub releases? This is unfortunately because the binary is currently built with both Lua 5.2 and Luau parsing enabled, which causes this conflict. This was actually reported before too: #309 (comment)

The only option right now is to install the binary using cargo cargo install stylua --features lua52

@Feez
Copy link
Author

Feez commented Mar 12, 2022

Sure, I'll have to do some setup of cargo.

I believe the output of this should probably be a feature request in being able to enable/disable these features at runtime for the ones that are installed, with the addition of having this error message (and others if they exist) to ask the user to provide the parser feature they intend to use.

@JohnnyMorganz
Copy link
Owner

I definitely agree with having a runtime flag to do this, that is the ideal scenario.

Unfortunately though the issue is upstream in our parser dependency, so it needs to be solved there

@Feez
Copy link
Author

Feez commented Mar 13, 2022

Maybe in the meantime, could provide additional binaries in the GitHub releases with the respective features compiled into them individually, as well as the default one for all. There seems to be quite a lot that goes into installing Cargo on a system like Windows (in terms of dependencies) and I can imagine some developers would have already stopped trying at this point.

Edit:
Installing the lua52 parsing worked on the original issue :)

@JohnnyMorganz
Copy link
Owner

I also agree on your second point, having Github release binaries for all possible flags would be good (#103). But as I mentioned in #309 (comment), right now there is potentially an issue with toolchain managers where they don't know which binary to install.

I might test it out one release though, and publish all the binaries and see if anything breaks

@JohnnyMorganz JohnnyMorganz changed the title Error parsing valid Lua with label at end of function Lua 5.2 label syntax error when using binary built all features enabled Mar 13, 2022
@JohnnyMorganz JohnnyMorganz added the external This issue relies on an external factor label Mar 16, 2022
@JohnnyMorganz JohnnyMorganz added this to the 2.0 milestone Dec 7, 2022
Julian added a commit to Julian/lean.nvim that referenced this issue Nov 13, 2023
Given the latter (that these still error), we can't yet add this to
pre-commit either.

It seems there's no current way to get a reliable install for using
stylua with neovim (especially via pre-commit) -- see
JohnnyMorganz/StyLua#407 which basically says using --all-features is
broken at the minute for labels, and requires specifically compiling
only for 5.2. There doesn't seem to be a way to do this via the
pre-commit install.

The same seems true of Homebrew's stylua, which compiles with
--all-features.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This issue relies on an external factor
Projects
None yet
Development

No branches or pull requests

2 participants