summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-03-04 17:31:27 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-03-04 17:31:27 +0800
commit399c008ba189fe22716d46d2974de1569b1d39e8 (patch)
tree7ba2d3b7c4f5099a8fe5ea5a1e5c68e0a7861485
parent171ed306f84850be46620145358dcfdf37387de2 (diff)
downloadlua-language-server-399c008ba189fe22716d46d2974de1569b1d39e8.zip
update
-rw-r--r--script/parser/guide.lua33
-rw-r--r--script/vm/compiler.lua38
-rw-r--r--script/vm/getDef.lua27
-rw-r--r--script/vm/global-manager.lua18
-rw-r--r--test/definition/luadoc.lua2
5 files changed, 78 insertions, 40 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 10b2badb..730a099d 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -809,20 +809,25 @@ function m.getLineRange(state, row)
end
local isSetMap = {
- ['setglobal'] = true,
- ['local'] = true,
- ['setlocal'] = true,
- ['setfield'] = true,
- ['setmethod'] = true,
- ['setindex'] = true,
- ['tablefield'] = true,
- ['tableindex'] = true,
- ['tableexp'] = true,
- ['doc.class.name'] = true,
- ['doc.alias.name'] = true,
- ['doc.field.name'] = true,
- ['doc.field'] = true,
- ['doc.type.field'] = true,
+ ['setglobal'] = true,
+ ['local'] = true,
+ ['setlocal'] = true,
+ ['setfield'] = true,
+ ['setmethod'] = true,
+ ['setindex'] = true,
+ ['tablefield'] = true,
+ ['tableindex'] = true,
+ ['tableexp'] = true,
+ ['label'] = true,
+ ['doc.class'] = true,
+ ['doc.alias'] = true,
+ ['doc.field'] = true,
+ ['doc.type.function'] = true,
+ ['doc.type.table'] = true,
+ ['doc.class.name'] = true,
+ ['doc.alias.name'] = true,
+ ['doc.field.name'] = true,
+ ['doc.type.field'] = true,
}
function m.isSet(source)
local tp = source.type
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 84de7058..7053e61c 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -238,6 +238,13 @@ local function bindDocs(source)
m.setNode(source, m.compileNode(doc))
end
end
+ if doc.type == 'doc.class' then
+ if source.type == 'local'
+ or (source._globalNode and guide.isSet(source)) then
+ hasFounded = true
+ m.setNode(source, m.compileNode(doc))
+ end
+ end
if doc.type == 'doc.param' then
if isParam and source[1] == doc.param[1] then
hasFounded = true
@@ -360,26 +367,10 @@ local compilerMap = util.switch()
m.setNode(source, m.compileNode(typeUnit))
end
end)
- : case 'doc.type.name'
- : call(function (source)
- local name = source[1]
- local uri = guide.getUri(source)
- local type = globalMgr.declareGlobal('type', name, uri)
- type:addGet(uri, source)
- m.setNode(source, type)
- end)
: case 'doc.field'
: call(function (source)
m.setNode(source, m.compileNode(source.extends))
end)
- : case 'doc.extends.name'
- : call(function (source)
- local name = source[1]
- local uri = guide.getUri(source)
- local type = globalMgr.declareGlobal('type', name, uri)
- type:addGet(uri, source)
- m.setNode(source, type)
- end)
: case 'doc.param'
: call(function (source)
m.setNode(source, m.compileNode(source.extends))
@@ -410,6 +401,13 @@ local compilerMap = util.switch()
: call(function (source)
m.setNode(source, m.compileNode(source.overload))
end)
+ : case 'doc.see.name'
+ : call(function (source)
+ local type = globalMgr.getGlobal('type', source[1])
+ if type then
+ m.setNode(source, m.compileNode(type))
+ end
+ end)
: getMap()
---@param source parser.object
@@ -428,9 +426,11 @@ local function compileByGlobal(source)
end
if source._globalNode then
m.setNode(source, source._globalNode)
- for _, set in ipairs(source._globalNode:getSets()) do
- if set.value then
- m.setNode(source, m.compileNode(set.value))
+ if source._globalNode.cate == 'variable' then
+ for _, set in ipairs(source._globalNode:getSets()) do
+ if set.value then
+ m.setNode(source, m.compileNode(set.value))
+ end
end
end
return
diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua
index 9ba90eb1..b454ad48 100644
--- a/script/vm/getDef.lua
+++ b/script/vm/getDef.lua
@@ -127,14 +127,26 @@ local nodeMap = util.switch()
: case 'getindex'
: case 'setindex'
: call(function (source, pushResult)
- local node = compiler.compileNode(source.node)
- if not node then
+ local parentNode = compiler.compileNode(source.node)
+ if not parentNode then
return
end
local key = guide.getKeyName(source)
- for n in compiler.eachNode(node) do
- if searchFieldMap[n.type] then
- searchFieldMap[n.type](n, key, pushResult)
+ for pn in compiler.eachNode(parentNode) do
+ if searchFieldMap[pn.type] then
+ searchFieldMap[pn.type](pn, key, pushResult)
+ end
+ end
+ end)
+ : case 'doc.see.field'
+ : call(function (source, pushResult)
+ local parentNode = compiler.compileNode(source.parent.name)
+ if not parentNode then
+ return
+ end
+ for pn in compiler.eachNode(parentNode) do
+ if searchFieldMap[pn.type] then
+ searchFieldMap[pn.type](pn, source[1], pushResult)
end
end
end)
@@ -216,7 +228,10 @@ function vm.getDefs(source)
end
if not mark[src] then
mark[src] = true
- results[#results+1] = src
+ if guide.isSet(src)
+ or guide.isLiteral(src) then
+ results[#results+1] = src
+ end
end
end
diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua
index bda7b744..a225be87 100644
--- a/script/vm/global-manager.lua
+++ b/script/vm/global-manager.lua
@@ -141,6 +141,7 @@ local compilerGlobalMap = util.switch()
local name = guide.getKeyName(source)
local class = m.declareGlobal('type', name, uri)
class:addSet(uri, source)
+ source._globalNode = class
end)
: case 'doc.alias'
: call(function (source)
@@ -148,6 +149,23 @@ local compilerGlobalMap = util.switch()
local name = guide.getKeyName(source)
local alias = m.declareGlobal('type', name, uri)
alias:addSet(uri, source)
+ source._globalNode = alias
+ end)
+ : case 'doc.type.name'
+ : call(function (source)
+ local uri = guide.getUri(source)
+ local name = source[1]
+ local type = m.declareGlobal('type', name, uri)
+ type:addGet(uri, source)
+ source._globalNode = type
+ end)
+ : case 'doc.extends.name'
+ : call(function (source)
+ local uri = guide.getUri(source)
+ local name = source[1]
+ local class = m.declareGlobal('type', name, uri)
+ class:addGet(uri, source)
+ source._globalNode = class
end)
: getMap()
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index 118eff5e..58260849 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -192,7 +192,7 @@ y.<?a?>
TEST [[
---@class <!loli!>
-local <!unit!>
+local unit
function unit:pants()
end