From 41316bc8a5731a90c1dd5d9d05ee8a0b96cd6449 Mon Sep 17 00:00:00 2001 From: NeOzay Date: Fri, 12 Jul 2024 20:42:02 +0200 Subject: added lua regular expression support for Lua.doc.Name --- script/config/template.lua | 5 ++++- script/vm/visible.lua | 22 +++++++++++++++++----- test/diagnostics/invisible.lua | 22 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/script/config/template.lua b/script/config/template.lua index e74a9f9c..7b044d7a 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -402,7 +402,10 @@ local template = { ['Lua.doc.privateName'] = Type.Array(Type.String), ['Lua.doc.protectedName'] = Type.Array(Type.String), ['Lua.doc.packageName'] = Type.Array(Type.String), - + ['Lua.doc.regengine'] = Type.String >> 'glob' << { + 'glob', + 'lua', + }, -- VSCode ["Lua.addonManager.enable"] = Type.Boolean >> true, ['files.associations'] = Type.Hash(Type.String, Type.String), diff --git a/script/vm/visible.lua b/script/vm/visible.lua index 0f486d6b..11b6c8d6 100644 --- a/script/vm/visible.lua +++ b/script/vm/visible.lua @@ -42,21 +42,33 @@ 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 privateNames = config.get(uri, 'Lua.doc.privateName') - if #privateNames > 0 and glob.glob(privateNames)(fieldName) then + if #privateNames > 0 and match(privateNames) then source._visibleType = 'private' return 'private' end - + local protectedNames = config.get(uri, 'Lua.doc.protectedName') - if #protectedNames > 0 and glob.glob(protectedNames)(fieldName) then + if #protectedNames > 0 and match(protectedNames) then source._visibleType = 'protected' return 'protected' end - + local packageNames = config.get(uri, 'Lua.doc.packageName') - if #packageNames > 0 and glob.glob(packageNames)(fieldName) then + if #packageNames > 0 and match(packageNames) then source._visibleType = 'package' return 'package' end diff --git a/test/diagnostics/invisible.lua b/test/diagnostics/invisible.lua index 2fc6791e..ed67df7e 100644 --- a/test/diagnostics/invisible.lua +++ b/test/diagnostics/invisible.lua @@ -104,6 +104,28 @@ print(t2._id) ]] config.set(nil, 'Lua.doc.protectedName', nil) +config.set(nil, 'Lua.doc.regengine', 'lua' ) +config.set(nil, 'Lua.doc.privateName', { '^_[%w_]*%w$' }) +config.set(nil, 'Lua.doc.protectedName', { '^_[%w_]*_$' }) +TEST [[ +---@class A +---@field _id_ number +---@field _user number + +---@type A +local t +print(t.) +print(t.) + +---@class B: A +local t2 +print(t2._id_) +print(t2.) +]] +config.set(nil, 'Lua.doc.privateName', nil) +config.set(nil, 'Lua.doc.protectedName', nil) +config.set(nil, 'Lua.doc.regengine', nil ) + TEST [[ ---@class A ---@field private x number -- cgit v1.2.3 From b09b057857bd65a3caa324443ffce0850933f32c Mon Sep 17 00:00:00 2001 From: NeOzay Date: Fri, 12 Jul 2024 21:11:45 +0200 Subject: update changelog --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index 87ef33ef..8f835b3e 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,8 @@ * `NEW` Add support for lambda style functions, `|paramList| expr` is syntactic sugar for `function(paramList) return expr end` * `FIX` Respect `completion.showParams` config for local function completion * `CHG` Improve performance of multithreaded `--check` and `undefined-field` diagnostic +* `NEW` added lua regular expression support for Lua.doc.Name [#2753](https://github.com/LuaLS/lua-language-server/pull/2753) + ## 3.9.3 `2024-6-11` -- cgit v1.2.3 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(-) 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