Skip to content

Parser. Long string doesn't contain leading spaces #3034

Description

@TIMONz1535

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

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

local function resolveLongString(finishMark)
skipNL()

local function skipNL()
local token = Tokens[Index + 1]
if NLMap[token] then
if Index >= 2 and not NLMap[Tokens[Index - 1]] then
LastTokenFinish = getPosition(Tokens[Index - 2] + #Tokens[Index - 1] - 1, 'right')
end
Line = Line + 1
LineOffset = Tokens[Index] + #token
Index = Index + 2
State.lines[Line] = LineOffset
return true
end
return false
end

изображение

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

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

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

{914609FD-8D0E-4A1C-9AB8-9915CBB28D91}

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions