-
-
Notifications
You must be signed in to change notification settings - Fork 351
Improvements to variable arguments and returns #1207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello 👋 For "fixing" the I can edit the wiki to make it more clear that Is it possible to add descriptions for the tags here: EDIT: I modified the wiki to make it more clear |
I have added a sample, you can edit the |
No problem! How can I test my changes? I am not familiar with how to get set up for development for this project. I can't seem to find anything about development and testing on the wiki. |
The fastest way is replacing your local files and restart server ( |
What is the purpose of the |
io.open('xxx') -- no
f = io.open('xxx') -- ok |
Would a better name be It would then make more sense if the warning said:
|
This name is come from C++ |
A few more questions:
|
Opened a PR to document all the tags and to better document the difference between I guess next is to work on fixing variable return values. I am not sure where to get started with fixing the parsing and type checking for that... |
|
Maybe we can only add a new syntax, such as |
"script\core\hover\description.lua:147" |
I still can't seem to get it to function. Can it only refer to libraries? Do you have some example code where it is used? |
---@class myClass
local mt = {}
function mt:open()
end
---@see myClass#open
function mt:close()
end |
I don't know the other usages of |
Ye it would be nice to be able to refer to other functions or classes in the project. |
It seems need to convert path to uri local furi = require 'file-uri'
local ws = require 'workspace'
local fullPath = ws.getAbsolutePath(fileUri, seePath)
if fullPath then
local fullUri = furi.encode(fullPath)
end |
Yeah that sounds like how it would need to be done |
|
I think the third option would be the most intuitive Is it not possible to fix the parsing so that the current syntax works? I haven't had much time lately to take a deep dive of the language server and attempt fixing this, sorry |
I can see a use case where you would like to name the variable returns, using one of the syntaxes you listed: ---@return string... nicknames The user's nicknames
function getNicknames() end But I also think the name could be unnecessary as usually the returns are all very similar: ---@return string ... The types of thing
function getTypes() end This way, the name is |
I agree w/ @carsakiller on supporting the standard format, where --- multiplies each number by a given factor
---
---@param c integer # the coefficient/factor
---@param ... integer # numbers to be multiplied by `c`
---@return integer ...
function multiply(c, ...) end I do think the
Maybe the language server could handle this as a special case and drop the
(this is a very small detail though) |
It's all done except |
Discussed in #1206
Originally posted by carsakiller June 14, 2022
Introduction
Currently, there are multiple ways to document a variable number of parameters passed to a function but I think they are causing confusion and conflicting with each other.
There is also only one way to document a variable number of return values, which I think is even more problematic.
Problems
@vararg
vs@param
@return
varargs@vararg
vs@param
You have two options when documenting a variable number of parameters passed to a function:
Use
@vararg
This means it can have a type, but no description
Example
Use
@param
This means it can have a name (
...
), type, and descriptionExample
The obvious choice is to use
@param
- which makes@vararg
completely useless.@return
varargsWhen returning a variable number of values from a function, there are two options:
Follow standard usage
The standard usage of
@return
is@return <type> [name] [description]
. However, this results in the name...
not being parsed correctly.Example
This doesn't look great and it only keeps track of the type for the first return value:


Inverted usage
Using
@return <name> <type> <description>
is a terrible idea... but it does at least parse...
correctly...Example
This comes at the cost of completely ruining any kind of type tracking:

Ambiguous enums
Should your function both receive and return a variable number of values and it uses an enum, it becomes a little ambiguous as to what the provided documentation is referring to.

I am aware that these values are also listed at the top next to the parameter, but (and especially with how variable returns are currently displayed) it appears that the enum at the bottom is also referring to the return values.
Proposed Solutions
Solution to
@vararg
vs@param
I think that
@vararg
should just be removed in favor of using@param
as it is able to do a better job at documenting variable parameters. It is confusing to have a tag for documenting parameters but then another tag to document multiple parameters and I feel it is more intuitive to only use@param
, like so:Solution to
@return
varargsThe current syntax of

@return <type> [name] [description]
should be kept and...
should be a valid return name that gets parsed as any other name does. This should result in:Solution to Ambiguous enums
As for this problem, I am not sure how it can best be solved, please do offer some ideas.
Maybe the enum reference appears immediately after the param/return that references it. This would probably require splitting the annotation that the user is providing in order to insert this info between

@
tags. This would definitely make it clear but it could lead to lots of spacing between params/returns should the enum have a lot of options.This seems like it could cause lots of problems.
Another possible solution could be to automatically label the parameter vararg
... (param)
and the return one... (return)
just so they cannot be confused.The text was updated successfully, but these errors were encountered: