Skip to content

fix a specific case for getVisibleType #2755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 5 additions & 1 deletion script/vm/visible.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions test/diagnostics/invisible.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,43 @@ 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
Expand Down
Loading