Improve generic pattern to support optional, union, array. Fixed regression.#3031
Merged
sumneko merged 3 commits intoLuaLS:masterfrom Jan 14, 2025
Merged
Improve generic pattern to support optional, union, array. Fixed regression.#3031sumneko merged 3 commits intoLuaLS:masterfrom
sumneko merged 3 commits intoLuaLS:masterfrom
Conversation
…y and comment without a space. Fixed regression.
Collaborator
|
感谢你的工作!不过关于泛型的改动可能影响会比较大,你是否在大型工程中做过测试? |
Thank you for your work! However, changes to generics may have a greater impact. Have you tested them in large projects? |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



I examined the original generic pattern code in more detail and realized that it incorrectly handles cases when it cannot parse further. We need to partially successfully parse, not cancel it by
return nil.T.*-" #3015 whereparseCodewas replaced withparseCodePatternThe signs
<>are also correctly recognized, but the generics don't support it at all.My complete test
I'm checking the
protoNode (self.proto)ingeneric:resolve. This node is created inserver\script\vm\compiler.lua:1753in: case 'function.return'wherertn (proto)has optional butvm.createGenericis not.lua-language-server/script/vm/compiler.lua
Lines 1751 to 1756 in cb964c6
Well, I think
generic:resolveis the best place.lua-language-server/script/vm/generic.lua
Lines 139 to 142 in 5f0efc4
But there is some change here. Previously the optional unresolved generic was
unknown, but now it chooses betweenunknown|nilso becomesnilI think its OK, otherwise its different issue.
Minor changes
m.R('__')fromnameparsing because it the same asm.S('_'), so nothing changed.nextvariable tonextTpto avoid names conflict.booleanpeek, not a string'peek'.