LuaLS / LuaLS/lua-language-server

Incorrect folding range when a function with an inline comment follows an annotation

Open
#3,220 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

The folding chevron will be next to the function declaration and will fold the function.

### Actual Behaviour

The folding chevron is next to the annotation and will only fold the one line of the function, leaving the rest of the function unfolded.

![Image](https://github.com/user-attachments/assets/e81dd9d1-6df8-46e0-aa0c-0b3657f9b31b)
![Image](https://github.com/user-attachments/assets/68b1037c-7853-4426-b889-dd942eb433b3)

### Reproduction steps

This code reproduces it:
`
---@param bar integer
function foo(bar) -- comment
local whee = bar + 3
return whee
end
`

### Additional Notes

Removing the inline comment fixes it.
Putting a blank line between the annotation and the function declaration line, even if it still has the inline comment, fixes it.

![Image](https://github.com/user-attachments/assets/b752c9ea-ec01-47ab-b6ab-4d9e209acbf6)
![Image](https://github.com/user-attachments/assets/1cc90feb-a50b-493c-b9ab-149b9db67d43)

### Log File

I couldn't get the thing to upload it, I'm sorry :(

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 folding behavior with the Lua snippet in the issue, comparing it with the variants that remove the inline comment or add a blank line. Trace the folding-range handling for an annotation followed by a function declaration. Done means the folding chevron is beside the function declaration and folds the entire function body.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.