summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/vm/visible.lua6
-rw-r--r--test/diagnostics/invisible.lua34
3 files changed, 40 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md
index 8ad44ec0..67e24e88 100644
--- a/changelog.md
+++ b/changelog.md
@@ -7,6 +7,7 @@
* `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
+* `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)
* `NEW` added lua regular expression support for Lua.doc.<scope>Name [#2753](https://github.com/LuaLS/lua-language-server/pull/2753)
* `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)
* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`
diff --git a/script/vm/visible.lua b/script/vm/visible.lua
index a085be08..518307a0 100644
--- a/script/vm/visible.lua
+++ b/script/vm/visible.lua
@@ -110,10 +110,14 @@ function vm.getParentClass(source)
if source.type == 'setfield'
or source.type == 'setindex'
or source.type == 'setmethod'
- or source.type == 'tablefield'
or source.type == 'tableindex' then
return vm.getDefinedClass(guide.getUri(source), source.node)
end
+
+ if source.type == 'tablefield' then
+ return vm.getDefinedClass(guide.getUri(source), source.node) or
+ vm.getDefinedClass(guide.getUri(source), source.parent.parent)
+ end
return nil
end
diff --git a/test/diagnostics/invisible.lua b/test/diagnostics/invisible.lua
index ed67df7e..4bb70fcc 100644
--- a/test/diagnostics/invisible.lua
+++ b/test/diagnostics/invisible.lua
@@ -85,11 +85,45 @@ local t2
print(t2.<!_id!>)
]]
+TEST [[
+---@class A
+local A = {
+ _id = 0
+}
+
+---@type A
+local t
+
+print(t.<!_id!>)
+
+---@class B: A
+local t2
+
+print(t2.<!_id!>)
+]]
+
config.set(nil, 'Lua.doc.privateName', nil)
config.set(nil, 'Lua.doc.protectedName', { '_*' })
TEST [[
---@class A
+local A = {
+ _id = 0
+}
+
+---@type A
+local t
+
+print(t.<!_id!>)
+
+---@class B: A
+local t2
+
+print(t2._id)
+]]
+
+TEST [[
+---@class A
---@field _id number
---@type A