From 6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 23 Nov 2019 00:05:30 +0800 Subject: =?UTF-8?q?=E6=AD=A3=E8=B7=AF=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/core/find_lib.lua | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 script/core/find_lib.lua (limited to 'script/core/find_lib.lua') diff --git a/script/core/find_lib.lua b/script/core/find_lib.lua new file mode 100644 index 00000000..e76549a8 --- /dev/null +++ b/script/core/find_lib.lua @@ -0,0 +1,65 @@ +local hoverName = require 'core.hover.name' + +local function getParentName(lib, isObject) + for _, parent in ipairs(lib.parent) do + if isObject then + if parent.type == 'object' then + return parent.nick or parent.name + end + else + if parent.type ~= 'object' then + return parent.nick or parent.name + end + end + end + return '' +end + +local function findLib(source) + local value = source:bindValue() + local lib = value:getLib() + if not lib then + return nil + end + if lib.parent then + if source:get 'object' then + -- *string:sub + local fullKey = ('*%s:%s'):format(getParentName(lib, true), lib.name) + return lib, fullKey + else + local parentValue = source:get 'parent' + if parentValue and parentValue:getType() == 'string' then + -- *string.sub + local fullKey = ('*%s.%s'):format(getParentName(lib, false), lib.name) + return lib, fullKey + else + -- string.sub + local fullKey = ('%s.%s'):format(getParentName(lib, false), lib.name) + return lib, fullKey + end + end + else + local name = hoverName(source) + local libName = lib.nick or lib.name + if name == libName or not libName then + return lib, name + elseif name == '' then + return lib, libName + else + return lib, ('%s<%s>'):format(name, libName) + end + end +end + +return function (source) + if source:bindValue() then + local lib, fullKey = findLib(source) + return lib, fullKey + end + if source:get 'in index' then + source = source:get 'in index' + local lib, fullKey = findLib(source) + return lib, fullKey + end + return nil +end -- cgit v1.2.3