-
-
Notifications
You must be signed in to change notification settings - Fork 357
Generic pattern skips non-letter characters at the end #3014
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This seems due to how The token types
The parse
|
function parseTypeUnit(parent) | |
local result = parseFunction(parent) | |
or parseTable(parent) | |
or parseTuple(parent) | |
or parseString(parent) | |
or parseCode(parent) | |
or parseInteger(parent) | |
or parseBoolean(parent) | |
or parseParen(parent) | |
or parseCodePattern(parent) |
-
parseCode
: If the type starts with acode
token, then only a singlecode
token is allowed, nothing after it will be parsed as type
=> this explains why`T`.Base
doesn't work
lua-language-server/script/parser/luadoc.lua
Lines 723 to 737 in 3a39d06
local function parseCode(parent) local tp, content = peekToken() if not tp or tp ~= 'code' then return nil end nextToken() local code = { type = 'doc.type.code', start = getStart(), finish = getFinish(), parent = parent, [1] = content, } return code end -
parseCodePattern
: must start with aname
token first, in the middle should be acode
token, and after it can bename
token again
lua-language-server/script/parser/luadoc.lua
Lines 739 to 784 in 3a39d06
local function parseCodePattern(parent) local tp, pattern = peekToken() if not tp or tp ~= 'name' then return nil end local codeOffset local finishOffset local content for i = 2, 8 do local next, nextContent = peekToken(i) if not next or TokenFinishs[Ci+i-1] + 1 ~= TokenStarts[Ci+i] then if codeOffset then finishOffset = i break end ---不连续的name,无效的 return nil end if next == 'code' then if codeOffset and content ~= nextContent then -- 暂时不支持多generic return nil end codeOffset = i pattern = pattern .. "%s" content = nextContent elseif next ~= 'name' then return nil else pattern = pattern .. nextContent end end local start = getStart() for _ = 2, finishOffset do nextToken() end local code = { type = 'doc.type.code', start = start, finish = getFinish(), parent = parent, pattern = pattern, [1] = content, } return code end - BUT
‼️ since aname
can only starts with\w
, therefore currently you cannot haveBase.`T`.Base
, yetBase.`T`Base
will work
- BUT
An attempt to fix
I just want to use pointer
Class*
I tried to make this work by changing 2 places:
- Change the
name
rule to allow starting with a*
- Merge
parseCode
andparseCodePattern
such thatname
token after acode
can be parsed
diff --git forkSrcPrefix/script/parser/luadoc.lua forkDstPrefix/script/parser/luadoc.lua
index d108cebc26c64fb8506d525cce8ffcca3e085e1e..f12e26b4bdb485568c7265553e024dc313917029 100644
--- forkSrcPrefix/script/parser/luadoc.lua
+++ forkDstPrefix/script/parser/luadoc.lua
@@ -71,7 +71,7 @@ Symbol <- ({} {
er = '\r',
et = '\t',
ev = '\v',
- name = (m.R('az', 'AZ', '09', '\x80\xff') + m.S('_')) * (m.R('az', 'AZ', '__', '09', '\x80\xff') + m.S('_.*-'))^0,
+ name = (m.R('az', 'AZ', '09', '\x80\xff') + m.S('_*')) * (m.R('az', 'AZ', '__', '09', '\x80\xff') + m.S('_.*-'))^0,
Char10 = function (char)
---@type integer?
char = tonumber(char)
@@ -738,12 +738,17 @@ end
local function parseCodePattern(parent)
local tp, pattern = peekToken()
- if not tp or tp ~= 'name' then
+ if not tp or (tp ~= 'name' and tp ~= 'code') then
return nil
end
local codeOffset
local finishOffset
local content
+ if tp == 'code' then
+ codeOffset = 1
+ content = pattern
+ pattern = "%s"
+ end
for i = 2, 8 do
local next, nextContent = peekToken(i)
if not next or TokenFinishs[Ci+i-1] + 1 ~= TokenStarts[Ci+i] then
@@ -834,7 +839,7 @@ function parseTypeUnit(parent)
or parseTable(parent)
or parseTuple(parent)
or parseString(parent)
- or parseCode(parent)
or parseInteger(parent)
or parseBoolean(parent)
or parseParen(parent)
- So far this allow the following use case:
---@generic T
---@param a `T`*
---@return T
function ToPtrClass(a) end
local a = ToPtrClass('A') --> a: A*
But still it doesn't solve all the cases that you reported.
And I don't know if this would cause other side effects or not, since a name
(identifier) generally should not be allowed to start with a *
.
Still might be you or others would like to pick it up from here 😄 or even better ask opinions from maintainers first
…Pattern to support "`T`.*-", prevent crash with "`T``T`" and when tokens >= 8, fix wrong getStart of result.
…-" without name token before code. Added tests.
…`..`, added changelog.
I fixed it without messing up the name parsing. But I found a few edge cases ---@class MehClass-Sub
---@class MehClass..Sub
---@class MehClass...Sub
---@class MehClass--Sub
---@param t `T`-Sub -- ok
---@param t `T`..Sub -- ok
---@param t `T`...Sub -- doesn't work because `...` is an individual symbol and I don't want to support it.
---@param t `T`--Sub -- doesn't work because `--` becomes a comment! I also found an error with luadoc Parser - the token
upd. Well, I see that the if tp ~= 'name' then
pushWarning {
type = 'LUADOC_MISS_VERSION',
start = getStart(),
finish = getFinish(),
}
break
end
version.version = tonumber(text) or text |
…y and comment without a space. Fixed regression.
…y and comment without a space. Fixed regression.
Uh oh!
There was an error while loading. Please reload this page.
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
Expected Behaviour
feature #2484
Generic pattern can't recognize non-letter characters after `T` for example `T`.Base or `T`*
There is my example
Actual Behaviour
Reproduction steps
*
,.
or number after `T`Additional Notes
Your class name can be very weird, but it works.

I just want to use pointer
Class*
Log File
No response
The text was updated successfully, but these errors were encountered: