Skip to content

Commit 491ad2f

Browse files
authored
Merge pull request #2755 from NeOzay/fixes-a-specific-case-for-getVisibleType
fix a specific case for getVisibleType
2 parents 3d88f33 + 8dd2710 commit 491ad2f

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
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+
* `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)
1011
* `NEW` added lua regular expression support for Lua.doc.<scope>Name [#2753](https://github.com/LuaLS/lua-language-server/pull/2753)
1112
* `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)
1213
* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`

script/vm/visible.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,14 @@ function vm.getParentClass(source)
110110
if source.type == 'setfield'
111111
or source.type == 'setindex'
112112
or source.type == 'setmethod'
113-
or source.type == 'tablefield'
114113
or source.type == 'tableindex' then
115114
return vm.getDefinedClass(guide.getUri(source), source.node)
116115
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
117121
return nil
118122
end
119123

test/diagnostics/invisible.lua

Lines changed: 34 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

0 commit comments

Comments
 (0)