diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-07 11:37:14 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-07 11:37:14 +0800 |
commit | 6b3920292359646f0f24f8770d83e8db755ef896 (patch) | |
tree | 90d9760a75d79b5cdad55d202da16f807cdd7868 /server | |
parent | 3ccf8b1b0e1048ee9056c610829d49679df6ac3b (diff) | |
download | lua-language-server-6b3920292359646f0f24f8770d83e8db755ef896.zip |
整理代码
Diffstat (limited to 'server')
-rw-r--r-- | server/src/matcher/compile.lua | 32 | ||||
-rw-r--r-- | server/src/matcher/find_lib.lua | 19 |
2 files changed, 35 insertions, 16 deletions
diff --git a/server/src/matcher/compile.lua b/server/src/matcher/compile.lua index f2017af2..5ed3e97a 100644 --- a/server/src/matcher/compile.lua +++ b/server/src/matcher/compile.lua @@ -97,6 +97,27 @@ function mt:getField(parent, key, source) return var end +function mt:isGlobal(var) + if var.type ~= 'field' then + return false + end + if not var.parent then + return false + end + return var.parent.key == '_ENV' or var.parent.key == '_G' +end + +function mt:getApi(func) + if not func then + return nil + end + func = func.value or func + if self:isGlobal(func) then + return func.key + end + return nil +end + function mt:checkName(name) local var = self:getVar(name[1], name) self:addInfo(var, 'get', name) @@ -111,17 +132,6 @@ function mt:checkDots(source) self:addInfo(dots, 'get', source) end -function mt:getApi(func) - if not func then - return nil - end - func = func.value or func - if func.type == 'field' and func.parent.key == '_ENV' then - return func.key - end - return nil -end - function mt:searchCall(call, func) local results = {} for i, exp in ipairs(call) do diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua index e52d1673..d4cb6bf2 100644 --- a/server/src/matcher/find_lib.lua +++ b/server/src/matcher/find_lib.lua @@ -99,14 +99,23 @@ local function getLibs() return Libs end -local function checkLibAsGlobal(var, name, lib) +local function isGlobal(var) + if var.type ~= 'field' then + return false + end + if not var.parent then + return false + end + return var.parent.key == '_ENV' or var.parent.key == '_G' +end + +local function checkLibAsGlobal(var, name) -- 检查是否是全局变量 local value = var.value or var - if value.type == 'field' and value.parent.key == '_ENV' then - if value.key == name then - return name - end + if value.key == name and isGlobal(value) then + return name end + return nil end local function checkLib(var, name, lib) |