summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-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?>()
+]]