lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Annotations `@enum` and `@enum (key)` in JSON output

Open AndreasMatthias opened this issue 1 year ago • 1 comments

Annotations @enum and @enum (key) produce very different JSON output.

Annotation @enum

---@enum level1
---Description of enum level1.
local level1 = {
   low = 1, --Low level.
   high = 2, --High level.
}

This enum creates the following JSON output:

    {
        "defines": [
            {
                "file": "file:///home/andreas/Projects/Code/luals2dox/test/./enum/enum-02.lua",
                "finish": 15,
                "start": 9,
                "type": "doc.enum"
            }
        ],
        "desc": "```lua\n{\n    low: integer = 1,\n    high: integer = 2,\n}\n```",
        "fields": [],
        "name": "level1",
        "rawdesc": "```lua\n{\n    low: integer = 1,\n    high: integer = 2,\n}\n```",
        "type": "type"
    },
    {
        "defines": [
            {
                "file": "file:///home/andreas/Projects/Code/luals2dox/test/./enum/enum-02.lua",
                "finish": 40007,
                "start": 40003,
                "type": "tablefield"
            }
        ],
        "desc": "High level.",
        "fields": [],
        "name": "level1.high",
        "rawdesc": "High level.",
        "type": "type"
    },
    {
        "defines": [
            {
                "file": "file:///home/andreas/Projects/Code/luals2dox/test/./enum/enum-02.lua",
                "finish": 30006,
                "start": 30003,
                "type": "tablefield"
            }
        ],
        "desc": "Low level.",
        "fields": [],
        "name": "level1.low",
        "rawdesc": "Low level.",
        "type": "type"
    },

Issues:

  • First block: start and finish numbers are wrong.
  • Description of enum Description of enum level1. is missing.

Just curious:

  • Why are there 3 separate blocks for this enum? I'd expected block 2 and 3 (enum items) to be sub-blocks of block 1 (enum). This would make it easier reading/postprocessing the JSON file.

Annotation @enum (key)

---@enum (key) level2
---Description of enum level2.
local level2 = {
   low = 1, --Low level.
   high = 2, --High level.
}

This enum create the following JSON output:

   {
        "defines": [
            {
                "file": "file:///home/andreas/Projects/Code/luals2dox/test/./enum/enum-02.lua",
                "finish": 70021,
                "start": 70015,
                "type": "doc.enum"
            }
        ],
        "desc": "```lua\n\"low\" | \"high\"\n```",
        "fields": [],
        "name": "level2",
        "rawdesc": "```lua\n\"low\" | \"high\"\n```",
        "type": "type"
    },

Issues:

  • Description of enum Description of enum level2. is missing.
  • Description of enum items Low level. and High level. are missing.

AndreasMatthias avatar Feb 18 '24 22:02 AndreasMatthias

One more question.

Here is a global definition:

---@enum level1
---Description of enum level1.
level1 = {
   low = 1, --Low level.
   high = 2, --High level.
}

Now I get a variable block in addition to the type blocks mentioned above. Is this expected?

    {
        "defines": [
            {
                "extends": {
                    "desc": "Description of enum level1.",
                    "finish": 50001,
                    "rawdesc": "Description of enum level1.",
                    "start": 20009,
                    "type": "table",
                    "view": "table"
                },
                "file": "file:///home/andreas/Projects/Code/luals2dox/test/./enum/enum-02.lua",
                "finish": 20006,
                "start": 20000,
                "type": "setglobal"
            }
        ],
        "desc": "Description of enum level1.",
        "name": "level1",
        "rawdesc": "Description of enum level1.",
        "type": "variable"
    },

AndreasMatthias avatar Feb 19 '24 00:02 AndreasMatthias