summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/definition.lua41
-rw-r--r--server/src/method/textDocument/definition.lua2
-rw-r--r--server/test/crossfile/definition.lua4
3 files changed, 36 insertions, 11 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
diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua
index d33fd739..20b2191f 100644
--- a/server/src/method/textDocument/definition.lua
+++ b/server/src/method/textDocument/definition.lua
@@ -14,7 +14,7 @@ local function findResult(lsp, params)
return nil
end
- local positions, isGlobal = core.definition(vm, position, 'definition', lsp)
+ local positions, isGlobal = core.definition(vm, position, 'definition')
if not positions then
return nil, isGlobal
end
diff --git a/server/test/crossfile/definition.lua b/server/test/crossfile/definition.lua
index 9310c323..cc06af11 100644
--- a/server/test/crossfile/definition.lua
+++ b/server/test/crossfile/definition.lua
@@ -112,7 +112,7 @@ TEST {
TEST {
{
path = 'a.lua',
- content = 'local <!t!> = 1; return <!t!>',
+ content = 'local <!t!> = 1; return t',
},
{
path = 'b.lua',
@@ -135,7 +135,7 @@ TEST {
TEST {
{
path = 'a.lua',
- content = 'local <!t!> = 1; return <!t!>',
+ content = 'local <!t!> = 1; return t',
},
{
path = 'b.lua',