-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
added lua regular expression support for Lua.doc.<scope>Name #2753
Conversation
I don't think there is a need to add support for {
"doc.protectedName": [
"_*[a-zA-Z0-9]*_" // prefix with at least 1 _, contains at least 1 char, then end with _
],
"doc.privateName": [
"_*", // prefix with at least 1 _, followed by anything
"!*_" // but must not end with _
]
}
---@class A
local A = {}
A._id_ = 0 -- protected
A._id_2_ = 0 -- protected
A.__a_ = 0 -- protected
A._user = "bob" -- private
A._id_3 = 1 -- private
A.__b = 0 -- private
A.test = 1 -- normal
A._ = 1 -- normal
A.__ = 1 -- normal
---@type A
local t = {}
print(t._id_) -- warning protected
print(t._id_2_) -- warning protected
print(t.__a_) -- warning protected
print(t._user) -- warning private
print(t._id_3) -- warning private
print(t.__b) -- warning private
print(t.test) -- ok
print(t._) -- ok
print(t.__) -- ok
---@class B: A
local t2 = {}
print(t2._id_) -- ok
print(t2._id_2_)-- ok
print(t2.__a_) -- ok
print(t2._user) -- warning private
print(t2._id_3) -- warning private
print(t.__b) -- warning private
print(t2.test) -- ok
print(t2._) -- ok
print(t2.__) -- ok I found that you have asked this question before in #2324, but seems that the reply doesn't actually answer your question directly 😂 |
(off topic) edit: With more testing of the custom built-in |
script/vm/visible.lua
Outdated
local regengine = config.get(uri, 'Lua.doc.regengine') | ||
local function match(patterns) | ||
if regengine == "glob" then | ||
return glob.glob(patterns)(fieldName) | ||
else | ||
for i = 1, #patterns do | ||
if string.find(fieldName, patterns[i]) then | ||
return true | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function should be declared in the outer scope. Otherwise each call to getVisibleType()
will create an unnecessary closure function object, and adds burden to garbage collection.
Maybe something like this:
- outer scope
local function globMatch(patterns, fieldName)
return glob.glob(patterns)(fieldName)
end
local function luaMatch(patterns, fieldName)
for i = 1, #patterns do
if string.find(fieldName, patterns[i]) then
return true
end
end
return false
end
- here
local regengine = config.get(uri, 'Lua.doc.regengine')
local match = regengine == "glob" and globMatch or luaMatch
...
if #privateNames > 0 and match(privateNames, fieldName) then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the advice. :)
Thank you! |
hi,
this PR add support for lua regular expressions for parameters:
Lua.doc.privateName
Lua.doc.packageName
Lua.doc.protectedName
it also adds a new
Lua.doc.regengine
(the name can be changed) parameter, which can be set toglob(default)
orlua