Skip to content

How to document @field values (description not shown when hovering the function) #3373

Closed as duplicate

Description

@ChillerDragon
Image
---@class Foo
---
---desc1
---@field dostuff fun(param1: integer) # desc2
foo = {}


function foo.dostuff(param1)
	print(param1)
end

I have an api defined in my meta file with functions the user can define. According to the documentation https://luals.github.io/wiki/annotations/#field

The syntax is this one: ---@field [scope] <name[?]> <type> [description]
A bit sad that the description has to come after the field and can not be above it. If the type is already a long callback the entire annotation line with long description will be super long :(

Anyways even that one I could not get to work. My editor would not show the description when hovering the function. Also I could not go to its definition to at least manually browse the type annotations.

Activity

  1. changed the title [-]How to document @field values[/-] [+]How to document @field values (description not shown when hovering the function)[/+] on Mar 10, 2026
  2. carsakiller commented on Mar 10, 2026

    @carsakiller
    Collaborator

    Interestingly enough, if the table is made local, it works as expected:

    Image

    Once it is made global, the description disappears:

    Image

    As for defining functions in a @field, there are various known limitations that could hopefully be fixed with a @function annotation.

  3. ChillerDragon commented on Mar 11, 2026

    @ChillerDragon
    Author

    Oh nice catch with it working as local. Sadly I can not use this workaround :/ because the type annotation comes from a meta file and is defined in C++ so without the global definition the instance of the table would not be in scope at all as far as I understand.

  4. carsakiller commented on Mar 18, 2026

    @carsakiller
    Collaborator

    Dropping by again to say that I found a workaround. Define the class first and then set the instance's @type:

    Image
    Code
    ---@class Actor
    ---A table that maps a MIME type to a serialization function.
    ---
    ---Each serialization function must accept `Actor` as a parameter and return
    ---a string representation of it.
    ---@field serializers table<string, fun(v: Actor): string>
    ---Execute the given action. A success boolean and error message will be returned
    ---
    ---See some documentation about it
    ---@field execute fun(action: string): boolean, string
    
    ---@type Actor
    myActor = {}
  5. carsakiller commented on Mar 18, 2026

    @carsakiller
    Collaborator

    Also, it looks like this issue of fields not being accessible on globals has already been reported, so I'm going to mark this as a duplicate.

  6. ChillerDragon commented on Mar 18, 2026

    @ChillerDragon
    Author

    Thanks for another workaround c:

    Sadly it did not work at all for me and made everything worse xd. Maybe because its in a meta file. Anyways I will survive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat/LuaCats AnnotationsRelated to Lua Language Server Annotations (LuaCats)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions