Skip to content

Saving after undo may unexpectedly modify code (lines removed or duplicated) #4

@Fringale

Description

@Fringale

First off, thank you for the EmmyLua extension and language server!

On my system (Zed 0.225.13 Flatpak on Linux), saving a Lua file can sometimes unexpectedly alter the code after an undo operation. In some cases, lines may be removed, duplicated, or previously deleted code may reappear.

Below is a minimal example where the issue is reproducible.

Tested with default Zed and EmmyLua configuration:

  • only HTML and EmmyLua extensions installed in Zed
  • empty settings.json in Zed
  • no .emmyrc.json, .luarc.json, editor.config or EmmyLua-specific settings

Also tested with today's Zed 0.226.4 version.


Steps to reproduce

  1. Type the following Lua code in a new file
if true then
	print(1)
end

print(2)

  1. Save as a .lua file and ensure that the EmmyLua language server is running
Image
  1. Select and delete the if block
Image Image
  1. Save the file: the EmmyLuaCodeStyle formatter removes the leading empty lines
Image
  1. Press Undo twice, to first restore the empty lines then the if block
Image
  1. Save the file again

Expected behaviour

Saving should not modify the code, as there is nothing left to format.

Actual behavior

The if statement is removed after saving.
Image


With additional edits, saves, and undo operations, the print(2) line ended up being duplicated and a previously deleted if block reappeared, however I could not yet found a reliable way to reproduce those cases consistently.

I suspect that this might be related to EmmyLuaCodeStyle, but I was unable to reproduce similar issues when using the LuaLS extension with the integrated EmmyLuaCodeStyle enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions