EmmyLua / IntelliJ-EmmyLua

Lua IDE/Debugger Plugin for IntelliJ IDEA
https://emmylua.github.io
Apache License 2.0
1.74k stars 293 forks source link

Unable to place inline comments in certain scenarios #397

Open pouwelsjochem opened 3 years ago

pouwelsjochem commented 3 years ago

Environment(环境)

name version
IDEA version 2020.3
EmmyLua version 1.3.5
OS macOS Big Sur

What are the steps to reproduce this issue?(重现步骤?)

Have a file with the following content and then reformat the code.

local t = {}
function t:a() -- this comment will stay the same
end
function t:b() -- this comment will be reformatted to the next line
    local randomNumber = math.random(10)
    if randomNumber < 2 then -- this comment will be reformatted to the next line
        return 1
    elseif randomNumber < 4 then -- this comment will stay the same

    else -- this comment will be reformatted to the next line
        local test = 1
    end
end
return t

What happens?(出现什么问题?)

Some comments will be reformatted to new lines.

What were you expecting to happen?(期望?)

Being able to configure the Lua Code Style to prevent the comments in mentioned file being located on new lines.

Any other comments?(其它说明)

I could be wrong, but it looks like comments want to 'stick' to their owner. Because the comments will only be reformatted when there's a line of code on the next line.

I'm willing to make a pull request myself, but I have no idea what part of the code makes these reformats, so if you could guide me into the right direction that would be great, I could add a settings to optionally disable this behaviour.

pouwelsjochem commented 3 years ago

Fixed this in #400