From c44cdf61136a639138a8bcd69bdcd37432ea63db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 16 Jan 2019 14:33:25 +0800 Subject: =?UTF-8?q?=E8=BD=AC=E5=88=B0=E5=AE=9A=E4=B9=89=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E7=BB=93=E6=9E=9C=E6=97=B6=E9=80=80=E5=8C=96=E4=B8=BA?= =?UTF-8?q?=E6=89=BE=E5=90=8C=E4=B9=89=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/definition.lua | 31 +++++++++++++++++++++++++++++++ server/src/core/implementation.lua | 31 +++++++++++++++++++++++++++++++ server/test/definition/table.lua | 17 +++++++++++++++++ 3 files changed, 79 insertions(+) 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.() ]] + +TEST[[ +local t = { + = 1, +} +y.() +]] + +TEST[[ +local t = { + = 1, +} +local y = { + insert = 1, +} +t.() +]] -- cgit v1.2.3