diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-10 10:42:57 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-10 10:42:57 +0800 |
commit | 3b27e1eadae8c56b98d6f52985aee7e9d952eb56 (patch) | |
tree | 65028b32159bdced5cf38af2245199b4df6b2ebd | |
parent | e5d6ba25f22fa873c30b786b87d6b821f926d3d9 (diff) | |
download | lua-language-server-3b27e1eadae8c56b98d6f52985aee7e9d952eb56.zip |
整理代码
-rw-r--r-- | server/src/core/library.lua | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/server/src/core/library.lua b/server/src/core/library.lua index be1d74b8..f0c292aa 100644 --- a/server/src/core/library.lua +++ b/server/src/core/library.lua @@ -65,25 +65,28 @@ local function mergeLocale(libs, locale) end end -local function insertGlobal(tbl, key, value) - if value.version then - local runtimeVersion = config.config.runtime.version - if type(value.version) == 'table' then - local ok - for _, version in ipairs(value.version) do - if version == runtimeVersion then - ok = true - break - end - end - if not ok then - return false - end - else - if value.version ~= runtimeVersion then - return false +local function isMatchVersion(version) + if not version then + return true + end + local runtimeVersion = config.config.runtime.version + if type(version) == 'table' then + for i = 1, #version do + if version[i] == runtimeVersion then + return true end end + else + if version == runtimeVersion then + return true + end + end + return false +end + +local function insertGlobal(tbl, key, value) + if not isMatchVersion(value.version) then + return false end tbl[key] = value return true @@ -169,24 +172,8 @@ local function insertChild(tbl, name, key, value) if not name or not key then return end - if value.version then - local runtimeVersion = config.config.runtime.version - if type(value.version) == 'table' then - local ok - for _, version in ipairs(value.version) do - if version == runtimeVersion then - ok = true - break - end - end - if not ok then - return - end - else - if value.version ~= runtimeVersion then - return - end - end + if not isMatchVersion(value.version) then + return end if not tbl[name] then tbl[name] = { |