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 error when writing the "#" singleton type in a multi-line union annotation #1608

Closed
goldenstein64 opened this issue Oct 2, 2022 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@goldenstein64
Copy link

goldenstein64 commented Oct 2, 2022

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Annotations, Hover

Expected Behaviour

image

Actual Behaviour

image

Reproduction steps

  1. Open a new Lua file
  2. Type in this snippet:
---@alias someType
---| "#"

---@type someType
local someValue
  1. The hover type info for someType will contain miscellaneous characters -- "

image

Additional Notes

This issue goes away when omitting the last quotation mark:

---@alias someTypeHack
---| "#

---@type someTypeHack
local someValue

image

I haven't been able to reproduce this with any other special character.

This also pushes anything after the # character into a comment to the side.

---@alias someType
---| "#tag" -- comment

---@type someType
local someValue

image

Disabling all libraries did not remove the issue, and I have no plugins enabled.

Log File

No response

@carsakiller
Copy link
Collaborator

This appears to be due to the # character being used to force the start of a description:

---@return integer # Some info about this

---@alias myType
---| false # Descripton

I am assuming the parsing is just taking everything after the # as the description value.

What are you trying to do here? Do you want the # as a string?

@goldenstein64
Copy link
Author

goldenstein64 commented Oct 2, 2022

What are you trying to do here? Do you want the # as a string?

I'm trying to type a union of string literals under an alias. I came across this while in the process of writing Penlight's type annotation library:

---@alias PLUnOpString -- for PL unary operator string
---| "#"
---| "()"
---| "{}"
---| ""
local len1, len2, len3 = {1}, {1, 2}, {1, 2, 3}

local collection = { len2, len3, len1 }

-- arg #2 is substituted as 'function(t) return #t end'
tablex.map(collection, "#") --> {2, 3, 1}

When hovering over the e.g. tablex.map function, I want to display and enumerate what you can put for arg #2 by using the PLUnOpString alias. The hover type info displays the "#" string with miscellaneous text as "#" -- ", which is a little distracting.

@carsakiller
Copy link
Collaborator

I see. The below syntax should work, but appears to be parsed incorrectly, leading to this error.

---@alias myType
---| '"#"'
---| "{}"

As a hack, if you just need this working temporarily, this seems to work:

---@alias hash "#"

---@alias myType
---| hash
---| "{}"

---@param a myType
local function(a) end

@carsakiller carsakiller added the bug Something isn't working label Oct 2, 2022
@sumneko sumneko added this to the 3.6.0 milestone Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants