Skip to content

Feature request: scope parsing for table/turple declaration #3041

Closed
@TIMONz1535

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?

Annotations

Expected Behaviour

I want to create a generic class with a private field, but this is not supported.

---@class Array<T>: { [integer]: T }
---@field private length integer

length field refers to an Array class, not an Array<T>, well the signs (generic class) are not good at this moment.

But I can do table/turple declaration

---@class Array<T>: { [integer]: T, length: integer }

unfortunately I can't specify the scope result.visible (private, protected, public, package).

Actual Behaviour

It's easy to add this for parsing in luadoc, what about this syntax?

---@class Array<T>: { [integer]: T, (private) length: integer }  -- OK
---@class Array<T>: { [integer]: T, private length: integer } -- OK
---@class Array<T>: { [integer]: T, (private length: integer) } -- OK
---@class Array<T>: { [integer]: T, ((private) length: integer) } -- wrong?

or

---@class Array<T>: { [integer]: T, (private) length: integer }  -- OK
---@class Array<T>: { [integer]: T, private length: integer } -- wrong
---@class Array<T>: { [integer]: T, (private length: integer) } -- wrong
---@class Array<T>: { [integer]: T, ((private) length: integer) } -- OK

References:

parseTable

if checkToken('symbol', '(', 1) then
nextToken()
needCloseParen = true
end
field.name = parseName('doc.field.name', field)
or parseIndexField(field)

result.visible

try(function ()
local tp, value = nextToken()
if tp == 'name' then
if value == 'public'
or value == 'protected'
or value == 'private'
or value == 'package' then
local tp2 = peekToken(1)
local tp3 = peekToken(2)
if tp2 == 'name' and not tp3 then
return false
end
result.visible = value
result.start = getStart()
return true
end
end
return false
end)

I want to hear someone's opinion.

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