Skip to content

Incorrect fix-indent behaviour when writing for loops at root scope #2799

@tomlau10

Description

@tomlau10

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

MacOS

What is the issue affecting?

Formatting

Expected Behaviour

The next line should be indented with the following code

  • example 1
for i = 1, 10 do<enter>
  • example 2
do
    for i = 1, 10 do<enter>

Actual Behaviour

The next line indented correctly initially (according to the indentationRules.increaseIndentPattern), but then it get removed by luals's "auto-fix-indent"...

Reproduction steps

  • create a new file
  • write the code snippet provided above
  • then press enter and observe the behaviour

Additional Notes

I disabled the fix-indent by modifying luals code locally, and this bug stopped. So it's related to the fix-indent function added recently.

I add a do return end here to disable it:

return function (uri, changes)
if not client.getOption('fixIndents') then


As discussed in here #2786, these new indentation behaviours are somewhat annoying and may not be applicable for all of us. Can this be made as optional please 🥲 ? Say an option which can be turned on/off.

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions