LuaLS / LuaLS/lua-language-server

Parser. Long string doesn't contain leading spaces

Open
#3,034 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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?

Diagnostics/Syntax Checking

### Expected Behaviour

```lua
local a = " sss "
print('"' .. a .. '"')
local a = [[ sss ]] -- bug with a leading spaces
print('"' .. a .. '"')

local a = [[sss]]
print('"' .. a .. '"')
local a = [[
sss]]
print('"' .. a .. '"')
local a = [[
sss]] -- bug with a leading space
print('"' .. a .. '"')

local a = [[sss
]]
print('"' .. a .. '"')
local a = [[
sss
]]
print('"' .. a .. '"')
local a = [[
sss
]] -- bug with a leading space
print('"' .. a .. '"')
```

Parser should produce strings according to Lua rules - in a long string only the first line break is removed, but if it is the first

```
" sss "
" sss "
"sss"
"sss"
"
sss"
"sss
"
"sss
"
"
sss
"
```

### Actual Behaviour

The leading spaces were skipped, presumably due to the fact that these are not tokens. Or I don't know

https://github.com/LuaLS/lua-language-server/blob/cb964c600570e6258d3c0a3f3f424a35a3a4ef64/script/parser/compile.lua#L429-L430

https://github.com/LuaLS/lua-language-server/blob/cb964c600570e6258d3c0a3f3f424a35a3a4ef64/script/parser/compile.lua#L381-L394

![изображение](https://github.com/user-attachments/assets/92d8e762-01ae-4c2c-b198-bc45b00c4e4f)

### Reproduction steps

1. Try to parse long string `[[ sss ]]`
2. Now its `[[sss ]]`

### Additional Notes

This also breaks the colorization in addition to #3032, most likely because it breaks the start/finish positions #3028

```lua
--[===[@param a string?ComMMul]===]
local function new(a) end

--[===[ @param a string?ComMMS1]===]
local function new(a) end
```

![{914609FD-8D0E-4A1C-9AB8-9915CBB28D91}](https://github.com/user-attachments/assets/af51e49e-44e6-4acb-ae13-6f23886fa1bc)

### Log File

_No response_

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 with script/parser/compile.lua at the referenced lines 381-394 and 429-430, then reproduce the listed long-string cases. Compare parsed values and source ranges with the expected Lua outputs, including leading spaces and line breaks. Done means leading spaces are preserved and the affected colorization and start/finish positions no longer regress.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
compilers, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.