summaryrefslogtreecommitdiff
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
parent9a3bc5ae5f34806cd887e4c5500609890c4ddcab (diff)
downloadlua-language-server-c44cdf61136a639138a8bcd69bdcd37432ea63db.zip
转到定义找不到结果时退化为找同义字段
-rw-r--r--server/src/core/definition.lua31
-rw-r--r--server/src/core/implementation.lua31
-rw-r--r--server/test/definition/table.lua17
3 files changed, 79 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
diff --git a/server/src/core/implementation.lua b/server/src/core/implementation.lua
index 9ff3fdca..c10cfaf9 100644
--- a/server/src/core/implementation.lua
+++ b/server/src/core/implementation.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
diff --git a/server/test/definition/table.lua b/server/test/definition/table.lua
index 6376d7f2..23af390d 100644
--- a/server/test/definition/table.lua
+++ b/server/test/definition/table.lua
@@ -101,3 +101,20 @@ local t = {
}
t.<?insert?>()
]]
+
+TEST[[
+local t = {
+ <!insert!> = 1,
+}
+y.<?insert?>()
+]]
+
+TEST[[
+local t = {
+ <!insert!> = 1,
+}
+local y = {
+ insert = 1,
+}
+t.<?insert?>()
+]]