summaryrefslogtreecommitdiff
path: root/script-beta/vm/getLibrary.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-08-28 15:42:02 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-08-28 15:42:02 +0800
commiteec3341dcba8b4076a038827aad3869a1439058b (patch)
treedaf1c2d893de6c563d76c1dfaa9e7130afa17490 /script-beta/vm/getLibrary.lua
parentfd5ee35ff772d11d2e44ff0b0f72d2c14ac4e01f (diff)
downloadlua-language-server-eec3341dcba8b4076a038827aad3869a1439058b.zip
暂存
Diffstat (limited to 'script-beta/vm/getLibrary.lua')
-rw-r--r--script-beta/vm/getLibrary.lua101
1 files changed, 9 insertions, 92 deletions
diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua
index e9c3b78a..f9f94bca 100644
--- a/script-beta/vm/getLibrary.lua
+++ b/script-beta/vm/getLibrary.lua
@@ -2,102 +2,19 @@ local vm = require 'vm.vm'
local library = require 'library'
local guide = require 'parser.guide'
-local function checkStdLibrary(source)
- if source.library then
- return source
- end
- local value = guide.getObjectValue(source)
- if value and value.type == 'select' then
- source = value
- end
- if source.type == 'getglobal'
- or source.type == 'setglobal' then
- local name = guide.getName(source)
- return library.global[name]
- elseif source.type == 'select' then
- local call = source.vararg
- if call.type ~= 'call' then
- goto CONTINUE
- end
- local func = call.node
- local lib = vm.getLibrary(func)
- if not lib then
- goto CONTINUE
- end
- if lib.name == 'require' then
- local modName = call.args[1]
- if modName and modName.type == 'string' then
- return library.library[modName[1]]
- end
+local interface = {
+ global = function (name)
+ if name:sub(1, 2) == 's|' then
+ return library.global[name:sub(3)]
end
- ::CONTINUE::
- end
-end
+ end,
+}
-local function getLibInNode(source, nodeLib)
- if not nodeLib then
- return nil
- end
- if not nodeLib.child then
- return nil
- end
- local key = guide.getName(source)
- local defLib = nodeLib.child[key]
- return defLib
-end
-
-local function getNodeAsTable(source)
- local nodeLib = checkStdLibrary(source.node)
- return getLibInNode(source, nodeLib)
-end
-
-local function getNodeAsObject(source)
- local node = source.node
- local values = vm.getInfers(node)
- if not values then
- return nil
- end
- for i = 1, #values do
- local value = values[i]
- local type = value.type
- local nodeLib = library.object[type]
- local lib = getLibInNode(source, nodeLib)
- if lib then
- return lib
- end
- end
- return nil
-end
-
-local function checkNode(source)
- if source.type == 'method' then
- source = source.parent
- elseif source.type == 'field' then
- source = source.parent
- end
- if source.type == 'getfield'
- or source.type == 'getmethod'
- or source.type == 'getindex' then
- return getNodeAsTable(source)
- or getNodeAsObject(source)
- end
-end
+local function getLibrary(source)
+ local results = guide.requestDefinition(source, interface)
+ for _, def in ipairs(results) do
-local function checkDef(source)
- local results = guide.requestDefinition(source)
- for _, src in ipairs(results) do
- local lib = checkStdLibrary(src) or checkNode(src)
- if lib then
- return lib
- end
end
- return nil
-end
-
-local function getLibrary(source)
- return checkNode(source)
- or checkStdLibrary(source)
- or checkDef(source)
end
function vm.getLibrary(source)