Skip to content
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

Display parameters one of multiple functions when hover #352

Closed
serg3295 opened this issue Jan 16, 2021 · 4 comments
Closed

Display parameters one of multiple functions when hover #352

serg3295 opened this issue Jan 16, 2021 · 4 comments
Labels
enhancement New feature or request priority.normal A normal priority topic
Milestone

Comments

@serg3295
Copy link
Contributor

Describe the bug
I have three function definitions:

node = {}

---This behaves like math.random except that it uses true random numbers derived from the ESP8266 hardware. It returns uniformly distributed numbers in the required range.
---@param l integer the lower bound of the range
---@param u integer the upper bound of the range
---@return integer --a pseudo-random integer x such that l <= x <= u.
function node.random(l, u) end

---This behaves like math.random except that it uses true random numbers derived from the ESP8266 hardware. It returns uniformly distributed numbers in the required range.
---@param n? integer the number of distinct integer values that can be returned -- in the (inclusive) range 1 .. n
---@return integer --an integer random number x such that 1 <= x <= n.
function node.random(n) end

---This behaves like math.random except that it uses true random numbers derived from the ESP8266 hardware. It returns uniformly distributed numbers in the required range.
---@return number --a random real number with uniform distribution in the interval [0,1)
function node.random() end

In input mode, it is suggested to choose one function of three, as expected.
But when hover, shows only last defined function.

multiple functions

I tryed alternative method using @overload, but it doesn't works also.

---This behaves like math.random except that it uses true random numbers derived from the ESP8266 hardware. It returns uniformly distributed numbers in the required range.
---@param l integer the lower bound of the range
---@param u integer the upper bound of the range
---@return integer --a pseudo-random integer x such that l <= x <= u.
---@overload fun(l:integer, u:integer):integer --a pseudo-random integer x such that l <= x <= u.
---@param n? integer the number of distinct integer values that can be returned -- in the (inclusive) range 1 .. n
---@return integer --an integer random number x such that 1 <= x <= n.
---@overload fun(n?:integer):integer --an integer random number x such that 1 <= x <= n.
---@return number --a random real number with uniform distribution in the interval [0,1)
function node.random() end

Is it possible to display parameters of multiple functions when hover?

Environment :

  • OS: Windows
  • Client: VSCode
@sumneko sumneko added the enhancement New feature or request label Jan 18, 2021
sumneko added a commit that referenced this issue Feb 2, 2021
@sumneko
Copy link
Collaborator

sumneko commented Feb 2, 2021

multi-hover
I tried some, but it didn't work very well. The main reason is that the three functions will produce three labels and descriptions, but the hover box will put the three labels together and then put the three descriptions together.

@serg3295
Copy link
Contributor Author

serg3295 commented Feb 2, 2021

it seems to me the solution you suggested would work very well for displaying such a function:

---Unsubscribes from one or several topics.
---@param tbl table array of `topic, anything` pairs to unsubscribe from
---@overload fun(tbl: table, foo: function): boolean
---@param topic string a topic string
---@param foo? function|' function(client) end' optional callback fired when unsubscription(s) succeeded.
---@return boolean
function m:unsubscribe(topic, foo) end

-- instead of defining two functions=>

---Unsubscribes from one or several topics.
---@param topic string a topic string
---@param foo? function|' function(client) end' optional callback fired when unsubscription(s) succeeded.
---@return boolean
function MQTT:unsubscribe(topic, foo) end

---Unsubscribes from one or several topics.
---@param tbl table array of `topic, anything` pairs to unsubscribe from
---@param foo? function|' function(client) end' optional callback fired when unsubscription(s) succeeded.
---@return boolean
function MQTT:unsubscribe(tbl, foo) end

because only the type of one parameter changes.

However, the three node.random functions (param1, param2 | no_param) could be shown separately (not @overload).
(but, if I understood you correctly - three functions node.random with different parameters has the same labels, and hover box can't let choose one of them.)
IMO, anyway it is better to display all parameters than only one function parameters.

@serg3295
Copy link
Contributor Author

Now, on hover, the description of another function is shown and vice versa.

luasrvQ2
luasrvQ3

sdmmc = {}

---@class sdmmc
local card = {}

---@class SDmmcCfg
---@field cd_pin integer
---@field wp_pin integer
---@field fmax integer
---@field width  integer

---SDMMC Mode. Initialize the SDMMC and probe the attached SD card.
---@param slot integer|'sdmmc.HS1'|'sdmmc.HS2' SDMMC slot
---@param cfg? SDmmcCfg optional table containing slot configuration:
-- - **cd_pin** card detect pin, none if omitted
-- - **wp_pin** write-protcet pin, none if omitted
-- - **fmax** maximum communication frequency, defaults to 20  if omitted
-- - **width** bis width, defaults to sdmmc.W1BIT if omitted, one of:
--   - sdmmc.W1BIT
--   - sdmmc.W4BIT
--   - sdmmc.W8BIT, not supported yet
---@return sdmmc cardObj Card object. Error is thrown for invalid parameters or if SDMMC hardware or card cannot be initialized.
function sdmmc.init(slot, cfg) end

---@class SDspiCfg
---@field sck_pin integer
---@field mosi_pin integer
---@field miso_pin integer
---@field cs_pin integer
---@field cd_pin integer
---@field wp_pin integer
---@field fmax integer

---SD SPI Mode. Initialize the SDMMC and probe the attached SD card.
---@param slot integer|'sdmmc.HSPI'|'sdmmc.VSPI' SD SPI slot
---@param cfg SDspiCfg mandatory table containing slot configuration:
-- - **sck_pin** SPI SCK pin, mandatory
-- - **mosi_pin**, SPI MOSI pin, mandatory
-- - **miso_pin**, SPI MISO pin, mandatory
-- - **cs_pin**, SPI CS pin, mandatory
-- - **cd_pin** card detect pin, none if omitted
-- - **wp_pin** write-protcet pin, none if omitted
-- - **fmax** maximum communication frequency, defaults to 20  if omitted
---@return sdmmc cardObj Card object. Error is thrown for invalid parameters or if SDMMC hardware or card cannot be initialized.
function sdmmc.init(slot, cfg) end

@sumneko
Copy link
Collaborator

sumneko commented Mar 26, 2021

Thank you for reporting, please open a new issue, so that I can record and fix the bug separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority.normal A normal priority topic
Projects
None yet
Development

No branches or pull requests

2 participants