From 2d19737aab53701661a41933e12df08edf078bc1 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, 5 Dec 2018 17:34:12 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/definition.lua | 39 +---------------------------------- server/src/matcher/find_result.lua | 37 +++++++++++++++++++++++++++++++++ server/src/matcher/implementation.lua | 39 +---------------------------------- server/src/matcher/references.lua | 39 +---------------------------------- 4 files changed, 40 insertions(+), 114 deletions(-) create mode 100644 server/src/matcher/find_result.lua (limited to 'server/src') diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua index 27dfe450..dbb24a47 100644 --- a/server/src/matcher/definition.lua +++ b/server/src/matcher/definition.lua @@ -1,41 +1,4 @@ - -local function isContainPos(obj, pos) - return obj.start <= pos and obj.finish + 1 >= pos -end - -local function findResult(results, pos) - for _, var in ipairs(results.vars) do - for _, info in ipairs(var) do - if isContainPos(info.source, pos) then - return { - type = 'var', - var = var, - } - end - end - end - for _, dots in ipairs(results.dots) do - for _, info in ipairs(dots) do - if isContainPos(info.source, pos) then - return { - type = 'dots', - dots = dots, - } - end - end - end - for _, label in ipairs(results.labels) do - for _, info in ipairs(label) do - if isContainPos(info.source, pos) then - return { - type = 'label', - label = label, - } - end - end - end - return nil -end +local findResult = require 'matcher.find_result' local function tryMeta(var) local keys = {} diff --git a/server/src/matcher/find_result.lua b/server/src/matcher/find_result.lua new file mode 100644 index 00000000..b9313510 --- /dev/null +++ b/server/src/matcher/find_result.lua @@ -0,0 +1,37 @@ +local function isContainPos(obj, pos) + return obj.start <= pos and obj.finish + 1 >= pos +end + +return function (results, pos) + for _, var in ipairs(results.vars) do + for _, info in ipairs(var) do + if isContainPos(info.source, pos) then + return { + type = 'var', + var = var, + } + end + end + end + for _, dots in ipairs(results.dots) do + for _, info in ipairs(dots) do + if isContainPos(info.source, pos) then + return { + type = 'dots', + dots = dots, + } + end + end + end + for _, label in ipairs(results.labels) do + for _, info in ipairs(label) do + if isContainPos(info.source, pos) then + return { + type = 'label', + label = label, + } + end + end + end + return nil +end diff --git a/server/src/matcher/implementation.lua b/server/src/matcher/implementation.lua index bf509ff3..e51d7a22 100644 --- a/server/src/matcher/implementation.lua +++ b/server/src/matcher/implementation.lua @@ -1,41 +1,4 @@ - -local function isContainPos(obj, pos) - return obj.start <= pos and obj.finish + 1 >= pos -end - -local function findResult(results, pos) - for _, var in ipairs(results.vars) do - for _, info in ipairs(var) do - if isContainPos(info.source, pos) then - return { - type = 'var', - var = var, - } - end - end - end - for _, dots in ipairs(results.dots) do - for _, info in ipairs(dots) do - if isContainPos(info.source, pos) then - return { - type = 'dots', - dots = dots, - } - end - end - end - for _, label in ipairs(results.labels) do - for _, info in ipairs(label) do - if isContainPos(info.source, pos) then - return { - type = 'label', - label = label, - } - end - end - end - return nil -end +local findResult = require 'matcher.find_result' local function tryMeta(var) local keys = {} diff --git a/server/src/matcher/references.lua b/server/src/matcher/references.lua index c0a98fe3..f5b72c55 100644 --- a/server/src/matcher/references.lua +++ b/server/src/matcher/references.lua @@ -1,41 +1,4 @@ - -local function isContainPos(obj, pos) - return obj.start <= pos and obj.finish + 1 >= pos -end - -local function findResult(results, pos) - for _, var in ipairs(results.vars) do - for _, info in ipairs(var) do - if isContainPos(info.source, pos) then - return { - type = 'var', - var = var, - } - end - end - end - for _, dots in ipairs(results.dots) do - for _, info in ipairs(dots) do - if isContainPos(info.source, pos) then - return { - type = 'dots', - dots = dots, - } - end - end - end - for _, label in ipairs(results.labels) do - for _, info in ipairs(label) do - if isContainPos(info.source, pos) then - return { - type = 'label', - label = label, - } - end - end - end - return nil -end +local findResult = require 'matcher.find_result' local function tryMeta(var) local keys = {} -- cgit v1.2.3