diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-23 00:05:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-23 00:05:30 +0800 |
commit | 6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444 (patch) | |
tree | fdc22d78150fd1c5edc46732c8b151ccfefb519f /script/core/find_lib.lua | |
parent | d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (diff) | |
download | lua-language-server-6da2b175e20ed3c03b0dfcfc9046de1e0e5d4444.zip |
正路目录
Diffstat (limited to 'script/core/find_lib.lua')
-rw-r--r-- | script/core/find_lib.lua | 65 |
1 files changed, 65 insertions, 0 deletions
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 |