summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-22 17:13:40 +0800
committersumneko <sumneko@hotmail.com>2019-04-22 17:13:40 +0800
commitea693e88c314ed118dab0121524453b1ba3bea90 (patch)
tree03ee71526e2cbf7701be9b3877915d41a7be41c5
parent2523bad318880bf7547f5d095fce4a681fe24a54 (diff)
downloadlua-language-server-ea693e88c314ed118dab0121524453b1ba3bea90.zip
支持一种穿透模式
-rw-r--r--server/src/core/definition.lua48
-rw-r--r--server/test/definition/emmy.lua32
2 files changed, 65 insertions, 15 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 8370e7a0..7d97bdee 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -25,30 +25,48 @@ local function parseLocal(callback, vm, source, lsp)
callback(locSource)
end
+local function parseValueByValue(callback, vm, source, value, isGlobal)
+ value:eachInfo(function (info, src)
+ if info.type == 'set' or info.type == 'local' or info.type == 'return' then
+ if vm.uri == src:getUri() then
+ if isGlobal or source.id > src.id then
+ callback(src)
+ end
+ elseif value.uri == src:getUri() then
+ callback(src)
+ end
+ end
+ end)
+end
+
local function parseValue(callback, vm, source, lsp)
local value = source:bindValue()
local isGlobal
if value then
isGlobal = value:isGlobal()
- value:eachInfo(function (info, src)
- if info.type == 'set' or info.type == 'local' or info.type == 'return' then
- if vm.uri == src:getUri() then
- if isGlobal or source.id > src.id then
- callback(src)
- end
- elseif value.uri == src:getUri() then
- callback(src)
- end
+ parseValueByValue(callback, vm, source, value, isGlobal)
+ local emmy = value:getEmmy()
+ if emmy and emmy.type == 'emmy.type' then
+ local class = emmy:getClass()
+ if class and class:getValue() then
+ parseValueByValue(callback, vm, source, class:getValue(), isGlobal)
end
- end)
+ end
end
local parent = source:get 'parent'
- if parent then
- parent:eachInfo(function (info, src)
- if info.type == 'set child' and info[1] == source[1] then
- callback(src)
+ for _ = 1, 3 do
+ if parent then
+ local ok = parent:eachInfo(function (info, src)
+ if info.type == 'set child' and info[1] == source[1] then
+ callback(src)
+ return true
+ end
+ end)
+ if ok then
+ break
end
- end)
+ parent = parent:getMetaMethod('__index')
+ end
end
return isGlobal
end
diff --git a/server/test/definition/emmy.lua b/server/test/definition/emmy.lua
index 73a5440c..82bac7a8 100644
--- a/server/test/definition/emmy.lua
+++ b/server/test/definition/emmy.lua
@@ -29,3 +29,35 @@ end
local <!obj!>
<?obj?>:cast()
]]
+
+TEST [[
+---@type A
+local <?obj?>
+
+---@class A
+local <!mt!>
+]]
+
+TEST [[
+---@type A
+local obj
+obj:<?func?>()
+
+---@class A
+local mt
+function mt:<!func!>()
+end
+]]
+
+TEST [[
+---@type A
+local obj
+obj:<?func?>()
+
+local mt = {}
+mt.__index = mt
+function mt:<!func!>()
+end
+---@class A
+local obj = setmetatable({}, mt)
+]]