summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/definition.lua70
-rw-r--r--server/src/core/implementation.lua69
2 files changed, 87 insertions, 52 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 60038724..cd44f94f 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -1,3 +1,32 @@
+local function findFieldBySource(positions, source, obj, result)
+ if source.type == 'name' and source[1] == result.key then
+ if obj.type == 'field' then
+ for _, info in ipairs(obj) do
+ if info.type == 'set' and info.source == source then
+ positions[#positions+1] = {
+ source.start,
+ source.finish,
+ source.uri,
+ }
+ end
+ end
+ end
+ end
+end
+
+local function findFieldByName(positions, vm, result)
+ for source, obj in pairs(vm.results.sources) do
+ if source.type == 'multi-source' then
+ for i = 1, #obj do
+ findFieldBySource(positions, source, obj[i], result)
+ end
+ else
+ findFieldBySource(positions, source, obj, result)
+ end
+ end
+end
+
+
local function parseResultAcrossUri(positions, vm, result)
-- 跨越文件时,遍历的是值的绑定信息
for _, info in ipairs(result.value) do
@@ -28,35 +57,23 @@ local function parseResultAcrossUri(positions, vm, result)
end
end
-local function findFieldBySource(positions, source, obj, result)
- if source.type == 'name' and source[1] == result.key then
- if obj.type == 'field' then
- for _, info in ipairs(obj) do
- if info.type == 'set' and info.source == source then
- positions[#positions+1] = {
- source.start,
- source.finish,
- source.uri,
- }
- end
- end
- end
+local function findFieldCrossUriByName(positions, vm, result, lsp)
+ if not lsp then
+ return
end
-end
-
-local function findFieldByName(positions, vm, result)
- for source, obj in pairs(vm.results.sources) do
- if source.type == 'multi-source' then
- for i = 1, #obj do
- findFieldBySource(positions, source, obj[i], result)
- end
- else
- findFieldBySource(positions, source, obj, result)
+ local parentValue = result.parentValue
+ if not parentValue then
+ return
+ end
+ if parentValue.uri ~= vm.uri then
+ local destVM = lsp:loadVM(parentValue.uri)
+ if destVM then
+ findFieldByName(positions, destVM, result)
end
end
end
-local function parseResult(vm, result)
+local function parseResult(vm, result, lsp)
local positions = {}
local tp = result.type
if tp == 'local' then
@@ -88,6 +105,7 @@ local function parseResult(vm, result)
end
if #positions == 0 then
findFieldByName(positions, vm, result)
+ findFieldCrossUriByName(positions, vm, result, lsp)
end
end
elseif tp == 'label' then
@@ -110,10 +128,10 @@ local function parseResult(vm, result)
return positions
end
-return function (vm, result)
+return function (vm, result, lsp)
if not result then
return nil
end
- local positions = parseResult(vm, result)
+ local positions = parseResult(vm, result, lsp)
return positions
end
diff --git a/server/src/core/implementation.lua b/server/src/core/implementation.lua
index c10cfaf9..f6593cf2 100644
--- a/server/src/core/implementation.lua
+++ b/server/src/core/implementation.lua
@@ -1,3 +1,31 @@
+local function findFieldBySource(positions, source, obj, result)
+ if source.type == 'name' and source[1] == result.key then
+ if obj.type == 'field' then
+ for _, info in ipairs(obj) do
+ if info.type == 'set' and info.source == source then
+ positions[#positions+1] = {
+ source.start,
+ source.finish,
+ source.uri,
+ }
+ end
+ end
+ end
+ end
+end
+
+local function findFieldByName(positions, vm, result)
+ for source, obj in pairs(vm.results.sources) do
+ if source.type == 'multi-source' then
+ for i = 1, #obj do
+ findFieldBySource(positions, source, obj[i], result)
+ end
+ else
+ findFieldBySource(positions, source, obj, result)
+ end
+ end
+end
+
local function parseResultAcrossUri(positions, vm, result)
-- 跨越文件时,遍历的是值的绑定信息
for _, info in ipairs(result.value) do
@@ -28,35 +56,23 @@ local function parseResultAcrossUri(positions, vm, result)
end
end
-local function findFieldBySource(positions, source, obj, result)
- if source.type == 'name' and source[1] == result.key then
- if obj.type == 'field' then
- for _, info in ipairs(obj) do
- if info.type == 'set' and info.source == source then
- positions[#positions+1] = {
- source.start,
- source.finish,
- source.uri,
- }
- end
- end
- end
+local function findFieldCrossUriByName(positions, vm, result, lsp)
+ if not lsp then
+ return
end
-end
-
-local function findFieldByName(positions, vm, result)
- for source, obj in pairs(vm.results.sources) do
- if source.type == 'multi-source' then
- for i = 1, #obj do
- findFieldBySource(positions, source, obj[i], result)
- end
- else
- findFieldBySource(positions, source, obj, result)
+ local parentValue = result.parentValue
+ if not parentValue then
+ return
+ end
+ if parentValue.uri ~= vm.uri then
+ local destVM = lsp:loadVM(parentValue.uri)
+ if destVM then
+ findFieldByName(positions, destVM, result)
end
end
end
-local function parseResult(vm, result)
+local function parseResult(vm, result, lsp)
local positions = {}
local tp = result.type
if tp == 'local' then
@@ -88,6 +104,7 @@ local function parseResult(vm, result)
end
if #positions == 0 then
findFieldByName(positions, vm, result)
+ findFieldCrossUriByName(positions, vm, result, lsp)
end
end
elseif tp == 'label' then
@@ -110,10 +127,10 @@ local function parseResult(vm, result)
return positions
end
-return function (vm, result)
+return function (vm, result, lsp)
if not result then
return nil
end
- local positions = parseResult(vm, result)
+ local positions = parseResult(vm, result, lsp)
return positions
end