LuaLS / LuaLS/lua-language-server

Feature Request/How-to: Inlined parameter annotation

Open
#2,250 10 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

I'd like to be able to do inlined type annotation for parameters. It doesn't currently seem to be possible. What I mean is, instead of this:

---@param key                       unknown
---@param callbackFn                fun(Hook, ...):any
---@param priority?                 number
---@param hostTableToHook?          table
---@param defaultNativeBehavior?    function
---@param hookedTableIsMetaTable?   boolean
function Hook.basic(key, callbackFn, priority, hostTableToHook, defaultNativeBehavior, hookedTableIsMetaTable)
    return Hook.add(key, callbackFn, priority, hostTableToHook, defaultNativeBehavior, hookedTableIsMetaTable, true)
end

I'd like to be able to do this:

function Hook.basic(
    key,                    ---@param unknown
    callbackFn,             ---@param fun(Hook, ...):any
    priority,               ---@param? number
    hostTableToHook,        ---@param? table
    defaultNativeBehavior,  ---@param? function
    hookedTableIsMetaTable  ---@param? boolean
)
    return Hook.add(key, callbackFn, priority, hostTableToHook, defaultNativeBehavior, hookedTableIsMetaTable, true)
end

This would cut down on the boilerplate a bit and make the code cleaner.

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 by locating the language server's parsing and tests for function parameters and existing inline annotations. Compare those paths with the two syntax examples in this issue; done means inline parameter annotations are accepted, interpreted with the shown optional and function types, and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.