Skip to content

Commit df30d05

Browse files
authored
Merge branch 'master' into master
2 parents 74a3803 + 491ad2f commit df30d05

File tree

8 files changed

+108
-11
lines changed

8 files changed

+108
-11
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* `FIX` Respect `completion.showParams` config for local function completion
99
* `CHG` Improve performance of multithreaded `--check` and `undefined-field` diagnostic
1010
* `FIX` Addons can now self-recommend as expected. Fixed by correcting the `wholeMatch` function
11+
* `FIX` Now correctly evaluates the visibility of fields in a class when they are defined directly in the object. use for completion and invisible dianostic. [#2752](https://github.com/LuaLS/lua-language-server/issues/2752)
12+
* `NEW` added lua regular expression support for Lua.doc.<scope>Name [#2753](https://github.com/LuaLS/lua-language-server/pull/2753)
13+
* `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)
14+
* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`
1115

1216
## 3.9.3
1317
`2024-6-11`

script/config/template.lua

Lines changed: 4 additions & 1 deletion
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/core/diagnostics/inject-field.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ return function (uri, callback)
6868
if def.type == 'doc.field' then
6969
return
7070
end
71+
if def.type == 'tablefield' and not isExact then
72+
return
73+
end
7174
end
7275

7376
local howToFix = ''

script/core/hint.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ local function typeHint(uri, results, start, finish)
5959
end
6060
mark[src] = true
6161
results[#results+1] = {
62-
text = ':' .. view,
62+
text = ': ' .. view,
6363
offset = src.finish,
6464
kind = define.InlayHintKind.Type,
6565
where = 'right',

script/provider/provider.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,8 +1426,8 @@ m.register 'textDocument/inlayHint' {
14261426
},
14271427
position = converter.packPosition(state, res.offset),
14281428
kind = res.kind,
1429-
paddingLeft = res.kind == 1,
1430-
paddingRight = res.kind == 2,
1429+
paddingLeft = false,
1430+
paddingRight = res.kind == define.InlayHintKind.Parameter,
14311431
}
14321432
end
14331433
return hintResults

script/vm/visible.lua

Lines changed: 25 additions & 7 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'
@@ -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
@@ -96,10 +110,14 @@ function vm.getParentClass(source)
96110
if source.type == 'setfield'
97111
or source.type == 'setindex'
98112
or source.type == 'setmethod'
99-
or source.type == 'tablefield'
100113
or source.type == 'tableindex' then
101114
return vm.getDefinedClass(guide.getUri(source), source.node)
102115
end
116+
117+
if source.type == 'tablefield' then
118+
return vm.getDefinedClass(guide.getUri(source), source.node) or
119+
vm.getDefinedClass(guide.getUri(source), source.parent.parent)
120+
end
103121
return nil
104122
end
105123

test/diagnostics/inject-field.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,16 @@ function m:init() -- OK
8282
end
8383
end
8484
]]
85+
86+
TEST [[
87+
---@class Class
88+
local m = {
89+
xx = 1, -- OK
90+
}
91+
92+
---@type Class
93+
local m
94+
95+
m.xx = 1 -- OK
96+
m.<!yy!> = 1 -- Warning
97+
]]

test/diagnostics/invisible.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,43 @@ local t2
8585
8686
print(t2.<!_id!>)
8787
]]
88+
TEST [[
89+
---@class A
90+
local A = {
91+
_id = 0
92+
}
93+
94+
---@type A
95+
local t
96+
97+
print(t.<!_id!>)
98+
99+
---@class B: A
100+
local t2
101+
102+
print(t2.<!_id!>)
103+
]]
104+
88105
config.set(nil, 'Lua.doc.privateName', nil)
89106

90107
config.set(nil, 'Lua.doc.protectedName', { '_*' })
108+
TEST [[
109+
---@class A
110+
local A = {
111+
_id = 0
112+
}
113+
114+
---@type A
115+
local t
116+
117+
print(t.<!_id!>)
118+
119+
---@class B: A
120+
local t2
121+
122+
print(t2._id)
123+
]]
124+
91125
TEST [[
92126
---@class A
93127
---@field _id number
@@ -104,6 +138,28 @@ print(t2._id)
104138
]]
105139
config.set(nil, 'Lua.doc.protectedName', nil)
106140

141+
config.set(nil, 'Lua.doc.regengine', 'lua' )
142+
config.set(nil, 'Lua.doc.privateName', { '^_[%w_]*%w$' })
143+
config.set(nil, 'Lua.doc.protectedName', { '^_[%w_]*_$' })
144+
TEST [[
145+
---@class A
146+
---@field _id_ number
147+
---@field _user number
148+
149+
---@type A
150+
local t
151+
print(t.<!_id_!>)
152+
print(t.<!_user!>)
153+
154+
---@class B: A
155+
local t2
156+
print(t2._id_)
157+
print(t2.<!_user!>)
158+
]]
159+
config.set(nil, 'Lua.doc.privateName', nil)
160+
config.set(nil, 'Lua.doc.protectedName', nil)
161+
config.set(nil, 'Lua.doc.regengine', nil )
162+
107163
TEST [[
108164
---@class A
109165
---@field private x number

0 commit comments

Comments
 (0)