summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-10-25 03:11:49 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-10-25 03:11:49 +0800
commit28dc2d3adce8729c90cf8abdaf5eb46efd39f2f1 (patch)
tree46bf83aa9f001f006e3ee42872838bea5a9a0660 /script
parent8f2dac8ba32271e45061128070063e0ddd0d73c4 (diff)
downloadlua-language-server-28dc2d3adce8729c90cf8abdaf5eb46efd39f2f1.zip
`---@private` and `---@protected`
#1316
Diffstat (limited to 'script')
-rw-r--r--script/parser/luadoc.lua22
-rw-r--r--script/vm/visible.lua27
2 files changed, 45 insertions, 4 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 71579fc4..bd631318 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -149,7 +149,7 @@ Symbol <- ({} {
---@field names? parser.object[]
---@field path? string
---@field bindComments? parser.object[]
----@field visible? 'public' | 'protected' | 'private'
+---@field visible? parser.visibleType
local function parseTokens(text, offset)
Ci = 0
@@ -1445,6 +1445,22 @@ local docSwitch = util.switch()
name.parent = result
return result
end)
+ : case 'private'
+ : call(function ()
+ return {
+ type = 'doc.private',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ end)
+ : case 'protected'
+ : call(function ()
+ return {
+ type = 'doc.protected',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ end)
local function convertTokens(doc)
local tp, text = nextToken()
@@ -1660,7 +1676,9 @@ local function bindDoc(source, binded)
or doc.type == 'doc.deprecated'
or doc.type == 'doc.version'
or doc.type == 'doc.module'
- or doc.type == 'doc.source' then
+ or doc.type == 'doc.source'
+ or doc.type == 'doc.private'
+ or doc.type == 'doc.protected' then
if source.type == 'function'
or isParam then
goto CONTINUE
diff --git a/script/vm/visible.lua b/script/vm/visible.lua
index 362bc568..f0b30a22 100644
--- a/script/vm/visible.lua
+++ b/script/vm/visible.lua
@@ -4,11 +4,13 @@ local guide = require 'parser.guide'
local config = require 'config'
local glob = require 'glob'
+---@alias parser.visibleType 'public' | 'protected' | 'private'
+
---@class parser.object
----@field _visibleType? 'public' | 'protected' | 'private'
+---@field _visibleType? parser.visibleType
---@param source parser.object
----@return 'public' | 'protected' | 'private'
+---@return parser.visibleType
function vm.getVisibleType(source)
if source._visibleType then
return source._visibleType
@@ -19,6 +21,20 @@ function vm.getVisibleType(source)
return source.visible
end
end
+
+ if source.bindDocs then
+ for _, doc in ipairs(source.bindDocs) do
+ if doc.type == 'doc.private' then
+ source._visibleType = 'private'
+ return 'private'
+ end
+ if doc.type == 'doc.protected' then
+ source._visibleType = 'protected'
+ return 'protected'
+ end
+ end
+ end
+
local fieldName = guide.getKeyName(source)
local uri = guide.getUri(source)
@@ -44,6 +60,13 @@ function vm.getParentClass(source)
if source.type == 'doc.field' then
return vm.getGlobalNode(source.class)
end
+ 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
return nil
end