summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-07-19 17:09:56 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-07-19 17:09:56 +0800
commit682614e0004472d485b834e3608bfa9c62a6fee6 (patch)
tree3d63e88ccacf237ddc6291de008c910c8842f58c
parent2431b557a125a609bdd8ccbf9e072b8cba4661e6 (diff)
downloadlua-language-server-682614e0004472d485b834e3608bfa9c62a6fee6.zip
check visible recursive
fix #2145
-rw-r--r--changelog.md3
-rw-r--r--script/vm/visible.lua21
-rw-r--r--test/hover/init.lua19
3 files changed, 40 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index 46d4a133..0d4ec8a6 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,6 +2,9 @@
## 3.6.24
* `FIX` shake of `codeLens`
+* `FIX` [#2145]
+
+[#2145]: https://github.com/LuaLS/lua-language-server/issues/2145
## 3.6.23
`2023-7-7`
diff --git a/script/vm/visible.lua b/script/vm/visible.lua
index e550280f..d4c1c710 100644
--- a/script/vm/visible.lua
+++ b/script/vm/visible.lua
@@ -7,9 +7,7 @@ local glob = require 'glob'
---@class parser.object
---@field package _visibleType? parser.visibleType
----@param source parser.object
----@return parser.visibleType
-function vm.getVisibleType(source)
+local function getVisibleType(source)
if source._visibleType then
return source._visibleType
end
@@ -56,6 +54,23 @@ function vm.getVisibleType(source)
end
---@param source parser.object
+---@return parser.visibleType
+function vm.getVisibleType(source)
+ if source._visibleType then
+ return source._visibleType
+ end
+ for _, def in ipairs(vm.getDefs(source)) do
+ local visible = getVisibleType(def)
+ if visible ~= 'public' then
+ source._visibleType = visible
+ return visible
+ end
+ end
+ source._visibleType = 'public'
+ return 'public'
+end
+
+---@param source parser.object
---@return vm.global?
function vm.getParentClass(source)
if source.type == 'doc.field' then
diff --git a/test/hover/init.lua b/test/hover/init.lua
index e77d8c98..d1d178fc 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -2383,6 +2383,25 @@ local obj: B {
TEST [[
---@class A
+local M = {}
+
+---@private
+M.x = 0
+
+---@private
+function M:init()
+ self.x = 1
+end
+
+---@type A
+local <?a?>
+]]
+[[
+local a: A
+]]
+
+TEST [[
+---@class A
---@field x fun(): string
---@type table<string, A>