diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2024-07-15 14:16:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-15 14:16:46 +0800 |
commit | 491ad2f40b2e2b6285dfe88558e3d8dd0c8395bd (patch) | |
tree | f152c27a73a9623fe64601557fbcb2b8bb63b8c0 | |
parent | 3d88f3313263f316834b2e9e0de47485a4a8d3f3 (diff) | |
parent | 8dd27106bb3c07f0a63a18dba76ef4a66ea8bf74 (diff) | |
download | lua-language-server-491ad2f40b2e2b6285dfe88558e3d8dd0c8395bd.zip |
Merge pull request #2755 from NeOzay/fixes-a-specific-case-for-getVisibleType
fix a specific case for getVisibleType
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/vm/visible.lua | 6 | ||||
-rw-r--r-- | test/diagnostics/invisible.lua | 34 |
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 |