summaryrefslogtreecommitdiff
path: root/server/src/core/definition.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-08 17:36:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-08 17:36:29 +0800
commita310232d2d873813023b099292efd9a78551e4d7 (patch)
tree1b2409de06813f0558f872954d780fe8b840a0fe /server/src/core/definition.lua
parentbdbe552e97098e617b8eecb5cd32ec229485fe8b (diff)
downloadlua-language-server-a310232d2d873813023b099292efd9a78551e4d7.zip
require相关
Diffstat (limited to 'server/src/core/definition.lua')
-rw-r--r--server/src/core/definition.lua77
1 files changed, 46 insertions, 31 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 6d5fe93e..2b476b92 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -1,4 +1,28 @@
-local function parseValueCrossFile(vm, value, lsp)
+local function parseValueSimily(vm, source, lsp)
+ local key = source[1]
+ if not key then
+ return nil
+ end
+ local positions = {}
+ for _, other in ipairs(vm.sources) do
+ if other == source then
+ break
+ end
+ if other[1] == key and not other:bindLocal() and other:bindValue() and other:action() == 'set' then
+ positions[#positions+1] = {
+ other.start,
+ other.finish,
+ }
+ end
+ end
+ if #positions == 0 then
+ return nil
+ end
+ return positions
+end
+
+local function parseValueCrossFile(vm, source, lsp)
+ local value = source:bindValue()
local positions = {}
value:eachInfo(function (info)
if info.type == 'local' and info.source.uri == value.uri then
@@ -32,6 +56,18 @@ local function parseValueCrossFile(vm, value, lsp)
}
return positions
end
+
+ local result = parseValueSimily(destVM, source, lsp)
+ if result then
+ for _, position in ipairs(result) do
+ positions[#positions+1] = position
+ position[3] = value.uri
+ end
+ end
+ if #positions > 0 then
+ return positions
+ end
+
local main = destVM.main
local mainValue = main:getFunction()
local mainSource = mainValue.source
@@ -46,10 +82,11 @@ local function parseValueCrossFile(vm, value, lsp)
return positions
end
-local function parseLocal(vm, loc, lsp)
- local value = loc:getValue()
+local function parseLocal(vm, source, lsp)
+ local loc = source:bindLocal()
+ local value = source:bindValue()
if value.uri ~= vm.uri then
- return parseValueCrossFile(vm, value, lsp)
+ return parseValueCrossFile(vm, source, lsp)
end
local positions = {}
positions[#positions+1] = {
@@ -62,9 +99,10 @@ local function parseLocal(vm, loc, lsp)
return positions
end
-local function parseValue(vm, value, lsp)
+local function parseValue(vm, source, lsp)
+ local value = source:bindValue()
if value.uri ~= vm.uri then
- return parseValueCrossFile(vm, value, lsp)
+ return parseValueCrossFile(vm, source, lsp)
end
local positions = {}
value:eachInfo(function (info)
@@ -81,29 +119,6 @@ local function parseValue(vm, value, lsp)
return positions
end
-local function parseValueSimily(vm, source, lsp)
- local key = source[1]
- if not key then
- return nil
- end
- local positions = {}
- for _, other in ipairs(vm.sources) do
- if other == source then
- break
- end
- if other[1] == key and not other:bindLocal() and other:bindValue() and other:action() == 'set' then
- positions[#positions+1] = {
- other.start,
- other.finish,
- }
- end
- end
- if #positions == 0 then
- return nil
- end
- return positions
-end
-
local function parseLabel(vm, label, lsp)
local positions = {}
label:eachInfo(function (info)
@@ -134,10 +149,10 @@ return function (vm, source, lsp)
return nil
end
if source:bindLocal() then
- return parseLocal(vm, source:bindLocal(), lsp)
+ return parseLocal(vm, source, lsp)
end
if source:bindValue() then
- return parseValue(vm, source:bindValue(), lsp)
+ return parseValue(vm, source, lsp)
or parseValueSimily(vm, source, lsp)
end
if source:bindLabel() then