Skip to content

Commit e1c06d0

Browse files
committed
moves the match function outside of getVisibleType function
1 parent b09b057 commit e1c06d0

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

script/vm/visible.lua

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ local glob = require 'glob'
77
---@class parser.object
88
---@field package _visibleType? parser.visibleType
99

10+
local function globMatch(patterns, fieldName)
11+
return glob.glob(patterns)(fieldName)
12+
end
13+
14+
local function luaMatch(patterns, fieldName)
15+
for i = 1, #patterns do
16+
if string.find(fieldName, patterns[i]) then
17+
return true
18+
end
19+
end
20+
return false
21+
end
22+
1023
local function getVisibleType(source)
1124
if guide.isLiteral(source) then
1225
return 'public'
@@ -43,32 +56,21 @@ local function getVisibleType(source)
4356
if type(fieldName) == 'string' then
4457
local uri = guide.getUri(source)
4558
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
57-
59+
local match = regengine == "glob" and globMatch or luaMatch
5860
local privateNames = config.get(uri, 'Lua.doc.privateName')
59-
if #privateNames > 0 and match(privateNames) then
61+
if #privateNames > 0 and match(privateNames, fieldName) then
6062
source._visibleType = 'private'
6163
return 'private'
6264
end
6365

6466
local protectedNames = config.get(uri, 'Lua.doc.protectedName')
65-
if #protectedNames > 0 and match(protectedNames) then
67+
if #protectedNames > 0 and match(protectedNames, fieldName) then
6668
source._visibleType = 'protected'
6769
return 'protected'
6870
end
6971

7072
local packageNames = config.get(uri, 'Lua.doc.packageName')
71-
if #packageNames > 0 and match(packageNames) then
73+
if #packageNames > 0 and match(packageNames, fieldName) then
7274
source._visibleType = 'package'
7375
return 'package'
7476
end

0 commit comments

Comments
 (0)