summaryrefslogtreecommitdiff
path: root/server/src/core/definition.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-16 14:33:25 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-16 14:33:25 +0800
commitc44cdf61136a639138a8bcd69bdcd37432ea63db (patch)
treed9a09d961e4fd390891f4c99f5b856bb892db4b3 /server/src/core/definition.lua
parent9a3bc5ae5f34806cd887e4c5500609890c4ddcab (diff)
downloadlua-language-server-c44cdf61136a639138a8bcd69bdcd37432ea63db.zip
转到定义找不到结果时退化为找同义字段
Diffstat (limited to 'server/src/core/definition.lua')
-rw-r--r--server/src/core/definition.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 3ca27b89..60038724 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -28,6 +28,34 @@ 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
+ 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 parseResult(vm, result)
local positions = {}
local tp = result.type
@@ -58,6 +86,9 @@ local function parseResult(vm, result)
}
end
end
+ if #positions == 0 then
+ findFieldByName(positions, vm, result)
+ end
end
elseif tp == 'label' then
for _, info in ipairs(result) do