From e1c06d0697a89dd4cc4af0987c5f642142b93ebb Mon Sep 17 00:00:00 2001 From: NeOzay Date: Sat, 13 Jul 2024 14:51:15 +0200 Subject: moves the match function outside of getVisibleType function --- script/vm/visible.lua | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'script/vm/visible.lua') diff --git a/script/vm/visible.lua b/script/vm/visible.lua index 11b6c8d6..a085be08 100644 --- a/script/vm/visible.lua +++ b/script/vm/visible.lua @@ -7,6 +7,19 @@ local glob = require 'glob' ---@class parser.object ---@field package _visibleType? parser.visibleType +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 + local function getVisibleType(source) if guide.isLiteral(source) then return 'public' @@ -43,32 +56,21 @@ local function getVisibleType(source) if type(fieldName) == 'string' then local uri = guide.getUri(source) 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 - + local match = regengine == "glob" and globMatch or luaMatch local privateNames = config.get(uri, 'Lua.doc.privateName') - if #privateNames > 0 and match(privateNames) then + if #privateNames > 0 and match(privateNames, fieldName) then source._visibleType = 'private' return 'private' end local protectedNames = config.get(uri, 'Lua.doc.protectedName') - if #protectedNames > 0 and match(protectedNames) then + if #protectedNames > 0 and match(protectedNames, fieldName) then source._visibleType = 'protected' return 'protected' end local packageNames = config.get(uri, 'Lua.doc.packageName') - if #packageNames > 0 and match(packageNames) then + if #packageNames > 0 and match(packageNames, fieldName) then source._visibleType = 'package' return 'package' end -- cgit v1.2.3