-
-
Notifications
You must be signed in to change notification settings - Fork 357
Feature request: scope parsing for table/turple declaration #3041
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
The bug related to generic class completion
There is indeed some bugs related to the generic class completion. ---@class Array<T>: { [integer]: T }
---@field length integer
---@type Array<string>
local t
t.<trigger completion>
--> it doesn't suggest `length` here So this is actually a bug related to generic class completion, and it is reported in this issue: #2945 My previous debugging journeyI have debugged it before, and found a fix in this comment: #2945 (comment) I just tested my patch, seems it can solve your issue as well 👀 From c2c96a15548ba1bdea86f426c377735e209fd675 Mon Sep 17 00:00:00 2001
From: Tom Lau <tomandfatboy@gmail.com>
Date: Sun, 10 Nov 2024 10:36:34 +0800
Subject: [PATCH] wip
---
script/vm/compiler.lua | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 92da538e..16a38a58 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -304,6 +304,17 @@ local searchFieldSwitch = util.switch()
end
end
end)
+ : case 'doc.type.sign'
+ : call(function (suri, source, key, pushResult)
+ if not source.node[1] then
+ return
+ end
+ local global = vm.getGlobal('type', source.node[1])
+ if not global then
+ return
+ end
+ vm.getClassFields(suri, global, key, pushResult)
+ end)
: case 'global'
: call(function (suri, node, key, pushResult)
if node.cate == 'variable' then
@@ -748,6 +759,7 @@ function vm.getNodesOfParentNode(source, key)
break
end
end
+ local skipDocTypeFieldRes = false
for node in parentNode:eachObject() do
if not hasClass
or (
@@ -761,6 +773,14 @@ function vm.getNodesOfParentNode(source, key)
if mark[res] then
return
end
+ if res.type == 'doc.type.field' and skipDocTypeFieldRes then
+ mark[res] = true
+ return
+ end
+ if node.type == 'global' or node.type == 'doc.type.sign' then
+ -- found definition from class, no need to search extended doc table fields
+ skipDocTypeFieldRes = true
+ end
mark[res] = true
if markDoc then
docedResults[#docedResults+1] = res
--
2.32.0.windows.1
demo of your use case with my patch
Just some more comment related to the suggested syntax. |
Actually, types can be written across multiple lines: ---@class Array<T>: {
--- [integer]: T,
--- length: integer,
---} |
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
I want to create a generic class with a private field, but this is not supported.
length
field refers to an Array class, not an Array<T>, well thesigns
(generic class) are not good at this moment.But I can do table/turple declaration
---@class Array<T>: { [integer]: T, length: integer }
unfortunately I can't specify the scope
result.visible
(private, protected, public, package).Actual Behaviour
It's easy to add this for parsing in luadoc, what about this syntax?
References:
parseTable
lua-language-server/script/parser/luadoc.lua
Lines 351 to 356 in 8a6d9db
result.visible
lua-language-server/script/parser/luadoc.lua
Lines 1169 to 1187 in 8a6d9db
I want to hear someone's opinion.
The text was updated successfully, but these errors were encountered: