Skip to content

Commit 3d88f33

Browse files
authored
Merge pull request #2753 from NeOzay/luaReg
added lua regular expression support for Lua.doc.<scope>Name
2 parents 33ba775 + 9b26e22 commit 3d88f33

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* `NEW` Add support for lambda style functions, `|paramList| expr` is syntactic sugar for `function(paramList) return expr end`
88
* `FIX` Respect `completion.showParams` config for local function completion
99
* `CHG` Improve performance of multithreaded `--check` and `undefined-field` diagnostic
10+
* `NEW` added lua regular expression support for Lua.doc.<scope>Name [#2753](https://github.com./LuaLS/lua-language-server/pull/2753)
1011
* `FIX` Bad triggering of the `inject-field` diagnostic, when the fields are declared at the creation of the object [#2746](https://github.com./LuaLS/lua-language-server/issues/2746)
1112
* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`
1213

script/config/template.lua

+4-1
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

+20-6
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'
@@ -42,21 +55,22 @@ local function getVisibleType(source)
4255

4356
if type(fieldName) == 'string' then
4457
local uri = guide.getUri(source)
45-
58+
local regengine = config.get(uri, 'Lua.doc.regengine')
59+
local match = regengine == "glob" and globMatch or luaMatch
4660
local privateNames = config.get(uri, 'Lua.doc.privateName')
47-
if #privateNames > 0 and glob.glob(privateNames)(fieldName) then
61+
if #privateNames > 0 and match(privateNames, fieldName) then
4862
source._visibleType = 'private'
4963
return 'private'
5064
end
51-
65+
5266
local protectedNames = config.get(uri, 'Lua.doc.protectedName')
53-
if #protectedNames > 0 and glob.glob(protectedNames)(fieldName) then
67+
if #protectedNames > 0 and match(protectedNames, fieldName) then
5468
source._visibleType = 'protected'
5569
return 'protected'
5670
end
57-
71+
5872
local packageNames = config.get(uri, 'Lua.doc.packageName')
59-
if #packageNames > 0 and glob.glob(packageNames)(fieldName) then
73+
if #packageNames > 0 and match(packageNames, fieldName) then
6074
source._visibleType = 'package'
6175
return 'package'
6276
end

test/diagnostics/invisible.lua

+22
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)