summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-02-25 18:08:05 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-02-25 18:08:05 +0800
commit4508b4018dced01fe5420e008e813199d0ce856f (patch)
tree4c1938a91270f91945be20a5e0bd489ff08a3994
parent674eb3f23cc00d2f679281abe16634f6b1663d31 (diff)
downloadlua-language-server-4508b4018dced01fe5420e008e813199d0ce856f.zip
update
-rw-r--r--script/vm/node/compiler.lua35
-rw-r--r--test/definition/special.lua36
2 files changed, 48 insertions, 23 deletions
diff --git a/script/vm/node/compiler.lua b/script/vm/node/compiler.lua
index 6c51db86..dbfc54d1 100644
--- a/script/vm/node/compiler.lua
+++ b/script/vm/node/compiler.lua
@@ -179,6 +179,15 @@ local compilerMap = util.switch()
if source.dummy then
m.setNode(source, m.compileNode(source.method.node))
end
+ -- function x.y(self, ...) --> function x:y(...)
+ if source[1] == 'self'
+ and source.parent.type == 'funcargs'
+ and source.parent[1] == source then
+ local setfield = source.parent.parent.parent
+ if setfield.type == 'setfield' then
+ m.setNode(source, m.compileNode(setfield.node))
+ end
+ end
end)
: case 'getlocal'
: call(function (source)
@@ -228,20 +237,32 @@ local compilerMap = util.switch()
: getMap()
---@param source parser.object
----@return vm.node
-function m.compileNode(source)
- if source._node ~= nil then
- return source._node
- end
- source._node = false
+local function compileByNode(source)
local compiler = compilerMap[source.type]
if compiler then
compiler(source)
end
- localMgr.subscribeLocal(source, source._node)
+end
+
+---@param source parser.object
+local function compileByGlobal(source)
if source._globalNode then
m.setNode(source, source._globalNode)
end
+end
+
+---@param source parser.object
+---@return vm.node
+function m.compileNode(source)
+ if source._node ~= nil then
+ return source._node
+ end
+ source._node = false
+ compileByNode(source)
+ compileByGlobal(source)
+
+ localMgr.subscribeLocal(source, source._node)
+
return source._node
end
diff --git a/test/definition/special.lua b/test/definition/special.lua
index 3f0d076a..531c5d93 100644
--- a/test/definition/special.lua
+++ b/test/definition/special.lua
@@ -32,24 +32,28 @@ local obj = setmetatable({}, { __index = mt })
obj:<?method1?>()
]]
-TEST [[
-local mt
-function mt:<!method1!>()
-end
-
-setmetatable(api, { __index = mt })
-api:<?method1?>()
-]]
+-- 不再支持在变量的引用中使用 setmetatable 操作。
+-- 这会将引用转换为定义,为了搜索定义去检查引用性价比太差了。
+-- 如果有必要,请使用 ---@class 系统。
-TEST [[
-local mt
-local api
-function mt:<!method1!>()
-end
+--TEST [[
+--local mt
+--function mt:<!method1!>()
+--end
+--
+--setmetatable(api, { __index = mt })
+--api:<?method1?>()
+--]]
-setmetatable(api, { __index = mt })
-api:<?method1?>()
-]]
+--TEST [[
+--local mt
+--local api
+--function mt:<!method1!>()
+--end
+--
+--setmetatable(api, { __index = mt })
+--api:<?method1?>()
+--]]
-- TODO 不支持从方法内部找外部的赋值
--TEST [[