summaryrefslogtreecommitdiff
path: root/server/src/core/definition.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-29 14:40:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-29 14:40:58 +0800
commit95957a0e4f6167d23d73cbe0de1e984c41763699 (patch)
treec9b9ebb1fc8ae4fd41d7e928b3d08822f0d19bd1 /server/src/core/definition.lua
parent99a02cc42f1871f2d67965f076dd8268c7004ad7 (diff)
downloadlua-language-server-95957a0e4f6167d23d73cbe0de1e984c41763699.zip
调整self的策略
Diffstat (limited to 'server/src/core/definition.lua')
-rw-r--r--server/src/core/definition.lua32
1 files changed, 14 insertions, 18 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 806007b1..d7f0019d 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -1,7 +1,8 @@
-local function findFieldBySource(positions, source, obj, result)
+local function findFieldBySource(positions, source, vm, result)
if source.type == 'name' and source[1] == result.key then
+ local obj = source.object
if obj.type == 'field' then
- for _, info in ipairs(obj) do
+ vm:eachInfo(obj, function (info)
if info.type == 'set' and info.source == source then
positions[#positions+1] = {
source.start,
@@ -9,20 +10,14 @@ local function findFieldBySource(positions, source, obj, result)
source.uri,
}
end
- 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
+ for _, source in pairs(vm.results.sources) do
+ findFieldBySource(positions, source, vm, result)
end
end
@@ -82,8 +77,9 @@ local function parseResultAsVar(vm, result, lsp)
end
if result.value.uri ~= vm.uri then
parseResultAcrossUri(positions, vm, result)
- else
- for _, info in ipairs(result) do
+ elseif result.link then
+ result = result.link
+ vm:eachInfo(result, function (info)
if info.type == 'local' then
positions[#positions+1] = {
info.source.start,
@@ -91,7 +87,7 @@ local function parseResultAsVar(vm, result, lsp)
info.source.uri,
}
end
- end
+ end)
end
elseif tp == 'field' then
if result.value.lib then
@@ -100,7 +96,7 @@ local function parseResultAsVar(vm, result, lsp)
if result.value.uri ~= vm.uri then
parseResultAcrossUri(positions, vm, result)
else
- for _, info in ipairs(result) do
+ vm:eachInfo(result, function (info)
if info.type == 'set' then
positions[#positions+1] = {
info.source.start,
@@ -108,21 +104,21 @@ local function parseResultAsVar(vm, result, lsp)
info.source.uri,
}
end
- end
+ end)
if #positions == 0 then
findFieldByName(positions, vm, result)
findFieldCrossUriByName(positions, vm, result, lsp)
end
end
elseif tp == 'label' then
- for _, info in ipairs(result) do
+ vm:eachInfo(result, function (info)
if info.type == 'set' then
positions[#positions+1] = {
info.source.start,
info.source.finish,
}
end
- end
+ end)
end
return positions
end