diff options
Diffstat (limited to 'server-beta/src/searcher/getLibrary.lua')
-rw-r--r-- | server-beta/src/searcher/getLibrary.lua | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/server-beta/src/searcher/getLibrary.lua b/server-beta/src/searcher/getLibrary.lua index b920387d..a2620295 100644 --- a/server-beta/src/searcher/getLibrary.lua +++ b/server-beta/src/searcher/getLibrary.lua @@ -1,7 +1,8 @@ local searcher = require 'searcher.searcher' local library = require 'library' +local guide = require 'parser.guide' -local function getLibrary(source) +local function checkStdLibrary(source) local globalName = searcher.getGlobal(source) if not globalName then return nil @@ -10,7 +11,37 @@ local function getLibrary(source) if library.global[name] then return library.global[name] end - return nil +end + +local function getLibrary(source) + local lib = checkStdLibrary(source) + if lib then + return lib + end + return searcher.eachRef(source, function (info) + local src = info.source + if src.type ~= 'getfield' + and src.type ~= 'getmethod' + and src.type ~= 'getindex' then + return + end + local node = src.node + local nodeGlobalName = searcher.getGlobal(node) + if not nodeGlobalName then + return + end + local nodeName = nodeGlobalName:match '^s|(.+)$' + local nodeLib = library.global[nodeName] + if not nodeLib then + return + end + if not nodeLib.child then + return + end + local key = guide.getKeyString(src) + local defLib = nodeLib.child[key] + return defLib + end) end function searcher.getLibrary(source) |