LuaLS / LuaLS/lua-language-server

Formatter deletes all code after certain syntax errors

Open
#1,907 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feat/formatter
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Windows

### What is the issue affecting?

Formatting

### Expected Behaviour

Code to be formatted without the rest of the code being deleted.

### Actual Behaviour

On certain errors, the formatter seems to delete everything past the point of error (though it occasionally saves a few lines).

https://user-images.githubusercontent.com/39929480/218354165-e1ea3e06-8bfe-49e0-a1dc-5709738d6721.mp4

### Reproduction steps

1. Create a test lua file
2. Write some lua code
3. At the very top, write `anything = ....` (I noticed just `anything =` will also cause issues)
4. Trigger a format run.
5. Watch your code disappear.

### Additional Notes

I'm not sure of all the errors that will trigger code deletion, but the ones I am aware of is:

- `anything = ....`
- `anything =`
- `anything = {x =}`

So my initial assumption is that it just affects errors with assignments.

### Log File

[file_d%3A_test%20directory.log](https://github.com/LuaLS/lua-language-server/files/10718039/file_d.3A_test.20directory.log)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the problem with the malformed assignments listed in the issue and inspect the attached log file. Trace the formatting path for syntax-error input; done means formatting preserves all code after the error while still applying formatting where possible.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.