diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-22 17:13:40 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-22 17:13:40 +0800 |
commit | ea693e88c314ed118dab0121524453b1ba3bea90 (patch) | |
tree | 03ee71526e2cbf7701be9b3877915d41a7be41c5 | |
parent | 2523bad318880bf7547f5d095fce4a681fe24a54 (diff) | |
download | lua-language-server-ea693e88c314ed118dab0121524453b1ba3bea90.zip |
支持一种穿透模式
-rw-r--r-- | server/src/core/definition.lua | 48 | ||||
-rw-r--r-- | server/test/definition/emmy.lua | 32 |
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) +]] |