LuaLS / LuaLS/lua-language-server
@constraint Annotation for types/aliases
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
I was working with Annotations for documenting my code and wanted to add a warning if the user used a function that didn't fall under a specific pattern (`"0x%x%x%x%x%x%x%x%x"`) and tried finding a workaround. I'm not 100% fluent with .lua and don't have the confidence to PR, so take my idea instead.
My idea for the annotation would be as follows:
```lua
--- @constraint con_color (string.find(T , "^0x%x%x%x%x%x%x%x%x$") or string.find(T , "^%x%x%x%x%x%x$"))
--- @alias color string
--- @param col1 color
--- @param col2 color
local function set_col(col1, col2)
...
end
```
Obviously syntax could use work, but the basic idea would be to add a constraint, and have `T` or whatever variable name be the entry. This way you can give a warning to users about unsupported string or a number being too low/high being used. If there is already something like this please enlighten me as I couldn't find anything
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the language server's existing annotation handling for @alias and @param, since the issue does not name specific files or tests. Determine how a proposed @constraint syntax could validate aliases and produce warnings, then define the syntax and expected behavior before implementation; done means documented constraints work for the color example and invalid values are diagnosed.
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
- Needs clarification
- Newbie friendliness
- 25/100