diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-23 11:58:30 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-23 11:58:30 +0800 |
commit | 7e816a0cdd2c88361b25980b0890b8ac8da16ab7 (patch) | |
tree | 1f50a891b2ecc285dde219f6fcc607ce0285ff7c /server/src/core/definition.lua | |
parent | f4e491d45014f31ae8a181ae36a0a2fb23a72a21 (diff) | |
download | lua-language-server-7e816a0cdd2c88361b25980b0890b8ac8da16ab7.zip |
优化definition
Diffstat (limited to 'server/src/core/definition.lua')
-rw-r--r-- | server/src/core/definition.lua | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua index f096fb99..47a12c2e 100644 --- a/server/src/core/definition.lua +++ b/server/src/core/definition.lua @@ -32,10 +32,15 @@ end local function parseLocal(callback, vm, source) ---@type Local local loc = source:bindLocal() + callback(loc:getSource()) loc:eachInfo(function (info, src) if Mode == 'definition' then if info.type == 'set' or info.type == 'local' then - if src.id < source.id then + if vm.uri == src:getUri() then + if source.id >= src.id then + callback(src) + end + else callback(src) end end @@ -47,15 +52,22 @@ local function parseLocal(callback, vm, source) end) end -local function parseValueByValue(callback, vm, source, value, isGlobal) +local function parseValueByValue(callback, vm, source, value) value:eachInfo(function (info, src) if Mode == 'definition' then - if info.type == 'set' or info.type == 'local' or info.type == 'return' then + if info.type == 'set' or info.type == 'local' then if vm.uri == src:getUri() then - if isGlobal or source.id > src.id then + if source.id >= src.id then callback(src) end - elseif value.uri == src:getUri() then + else + callback(src) + end + end + if info.type == 'return' then + if src.type == 'function' + or (src.type == 'simple' and src[#src].type == 'call') + then callback(src) end end @@ -72,14 +84,14 @@ local function parseValue(callback, vm, source) local isGlobal if value then isGlobal = value:isGlobal() - parseValueByValue(callback, vm, source, value, isGlobal) + parseValueByValue(callback, vm, source, value) local emmy = value:getEmmy() if emmy and emmy.type == 'emmy.type' then ---@type EmmyType local emmyType = emmy emmyType:eachClass(function (class) if class and class:getValue() then - parseValueByValue(callback, vm, source, class:getValue(), isGlobal) + parseValueByValue(callback, vm, class:getValue():getSource(), class:getValue()) end end) end @@ -150,7 +162,20 @@ local function parseClass(callback, vm, source) end local function parseFunction(callback, vm, source) - if Mode == 'reference' then + if Mode == 'definition' then + callback(source:bindFunction():getSource()) + source:bindFunction():eachInfo(function (info, src) + if info.type == 'set' or info.type == 'local' then + if vm.uri == src:getUri() then + if source.id >= src.id then + callback(src) + end + else + callback(src) + end + end + end) + elseif Mode == 'reference' then callback(source:bindFunction():getSource()) source:bindFunction():eachInfo(function (info, src) if info.type == 'set' or info.type == 'local' or info.type == 'get' then |