Skip to content

Commit 41316bc

Browse files
committed
added lua regular expression support for Lua.doc.<scope>Name
1 parent 4670739 commit 41316bc

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

script/config/template.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,10 @@ local template = {
402402
['Lua.doc.privateName'] = Type.Array(Type.String),
403403
['Lua.doc.protectedName'] = Type.Array(Type.String),
404404
['Lua.doc.packageName'] = Type.Array(Type.String),
405-
405+
['Lua.doc.regengine'] = Type.String >> 'glob' << {
406+
'glob',
407+
'lua',
408+
},
406409
-- VSCode
407410
["Lua.addonManager.enable"] = Type.Boolean >> true,
408411
['files.associations'] = Type.Hash(Type.String, Type.String),

script/vm/visible.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,33 @@ local function getVisibleType(source)
4242

4343
if type(fieldName) == 'string' then
4444
local uri = guide.getUri(source)
45+
local regengine = config.get(uri, 'Lua.doc.regengine')
46+
local function match(patterns)
47+
if regengine == "glob" then
48+
return glob.glob(patterns)(fieldName)
49+
else
50+
for i = 1, #patterns do
51+
if string.find(fieldName, patterns[i]) then
52+
return true
53+
end
54+
end
55+
end
56+
end
4557

4658
local privateNames = config.get(uri, 'Lua.doc.privateName')
47-
if #privateNames > 0 and glob.glob(privateNames)(fieldName) then
59+
if #privateNames > 0 and match(privateNames) then
4860
source._visibleType = 'private'
4961
return 'private'
5062
end
51-
63+
5264
local protectedNames = config.get(uri, 'Lua.doc.protectedName')
53-
if #protectedNames > 0 and glob.glob(protectedNames)(fieldName) then
65+
if #protectedNames > 0 and match(protectedNames) then
5466
source._visibleType = 'protected'
5567
return 'protected'
5668
end
57-
69+
5870
local packageNames = config.get(uri, 'Lua.doc.packageName')
59-
if #packageNames > 0 and glob.glob(packageNames)(fieldName) then
71+
if #packageNames > 0 and match(packageNames) then
6072
source._visibleType = 'package'
6173
return 'package'
6274
end

test/diagnostics/invisible.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ print(t2._id)
104104
]]
105105
config.set(nil, 'Lua.doc.protectedName', nil)
106106

107+
config.set(nil, 'Lua.doc.regengine', 'lua' )
108+
config.set(nil, 'Lua.doc.privateName', { '^_[%w_]*%w$' })
109+
config.set(nil, 'Lua.doc.protectedName', { '^_[%w_]*_$' })
110+
TEST [[
111+
---@class A
112+
---@field _id_ number
113+
---@field _user number
114+
115+
---@type A
116+
local t
117+
print(t.<!_id_!>)
118+
print(t.<!_user!>)
119+
120+
---@class B: A
121+
local t2
122+
print(t2._id_)
123+
print(t2.<!_user!>)
124+
]]
125+
config.set(nil, 'Lua.doc.privateName', nil)
126+
config.set(nil, 'Lua.doc.protectedName', nil)
127+
config.set(nil, 'Lua.doc.regengine', nil )
128+
107129
TEST [[
108130
---@class A
109131
---@field private x number

0 commit comments

Comments
 (0)