summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/libs/lua53/table.lni5
-rw-r--r--server/src/matcher/find_lib.lua13
-rw-r--r--server/test/find_lib/init.lua51
-rw-r--r--server/test/main.lua1
4 files changed, 68 insertions, 2 deletions
diff --git a/server/libs/lua53/table.lni b/server/libs/lua53/table.lni
index 5cb9a951..94e60664 100644
--- a/server/libs/lua53/table.lni
+++ b/server/libs/lua53/table.lni
@@ -3,3 +3,8 @@ type = 'function'
[table]
type = 'table'
+[[.source]]
+type = 'global'
+[[.source]]
+type = 'library'
+name = 'table'
diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua
index d4cb6bf2..84cf44c5 100644
--- a/server/src/matcher/find_lib.lua
+++ b/server/src/matcher/find_lib.lua
@@ -122,6 +122,15 @@ local function checkLib(var, name, lib)
if not lib.source then
return checkLibAsGlobal(var, name)
end
+ for _, source in ipairs(lib.source) do
+ if source.type == 'global' then
+ local fullkey = checkLibAsGlobal(var, name)
+ if fullkey then
+ return fullkey
+ end
+ end
+ end
+ return nil
end
local function findLib(var, libs)
@@ -136,6 +145,6 @@ end
return function (var)
local libs = getLibs()
- local lib, key = findLib(var, libs)
- return lib, key
+ local lib, fullkey = findLib(var, libs)
+ return lib, fullkey
end
diff --git a/server/test/find_lib/init.lua b/server/test/find_lib/init.lua
new file mode 100644
index 00000000..29297bcf
--- /dev/null
+++ b/server/test/find_lib/init.lua
@@ -0,0 +1,51 @@
+local matcher = require 'matcher'
+local parser = require 'parser'
+local findResult = require 'matcher.find_result'
+local findLib = require 'matcher.find_lib'
+
+rawset(_G, 'TEST', true)
+
+function TEST(fullkey)
+ return function (script)
+ local start = script:find('<?', 1, true)
+ local finish = script:find('?>', 1, true)
+ local pos = (start + finish) // 2 + 1
+ local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ')
+ local ast = parser:ast(new_script)
+ assert(ast)
+ local results = matcher.compile(ast)
+ assert(results)
+ local result = findResult(results, pos)
+ assert(result)
+ assert(result.type == 'var')
+ local var = result.var
+ assert(var)
+ local _, name = findLib(var)
+ assert(name)
+ assert(name == fullkey)
+ end
+end
+
+TEST 'require' [[
+<?require?> 'xxx'
+]]
+
+TEST 'require' [[
+local <?req?> = require
+]]
+
+TEST 'require' [[
+local req = require
+local t = {
+ xx = req,
+}
+t[<?'xx'?>]()
+]]
+
+TEST 'table' [[
+<?table?>.unpack()
+]]
+
+TEST 'table' [[
+local <?xx?> = require 'table'
+]]
diff --git a/server/test/main.lua b/server/test/main.lua
index 58394989..9b6e2c02 100644
--- a/server/test/main.lua
+++ b/server/test/main.lua
@@ -21,6 +21,7 @@ local function main()
end
test 'definition'
+ test 'find_lib'
print('测试完成')
end