summaryrefslogtreecommitdiff
path: root/server/src/matcher/find_lib.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-10 13:41:04 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-10 13:41:04 +0800
commit41aea3f8753e58ba460907f82e30bd093e3ee463 (patch)
treebbe762ea130648f1857b975cb3eb005b84d41a73 /server/src/matcher/find_lib.lua
parent3ecf1f3050877af26f65cf54ba2c252a84eebb26 (diff)
downloadlua-language-server-41aea3f8753e58ba460907f82e30bd093e3ee463.zip
整理代码
Diffstat (limited to 'server/src/matcher/find_lib.lua')
-rw-r--r--server/src/matcher/find_lib.lua115
1 files changed, 3 insertions, 112 deletions
diff --git a/server/src/matcher/find_lib.lua b/server/src/matcher/find_lib.lua
index f24dabd4..b9efacb2 100644
--- a/server/src/matcher/find_lib.lua
+++ b/server/src/matcher/find_lib.lua
@@ -1,112 +1,4 @@
-local lni = require 'lni'
-local fs = require 'bee.filesystem'
-
-local function mergeEnum(lib, locale)
- if not lib or not locale then
- return
- end
- local pack = {}
- for _, enum in ipairs(lib) do
- if enum.enum then
- pack[enum.enum] = enum
- end
- end
- for _, enum in ipairs(locale) do
- if pack[enum.enum] then
- pack[enum.enum].description = enum.description
- end
- end
-end
-
-local function mergeField(lib, locale)
- if not lib or not locale then
- return
- end
- local pack = {}
- for _, field in ipairs(lib) do
- if field.field then
- pack[field.field] = field
- end
- end
- for _, field in ipairs(locale) do
- if pack[field.field] then
- pack[field.field].description = field.description
- end
- end
-end
-
-local function mergeLocale(libs, locale)
- if not libs or not locale then
- return
- end
- for name in pairs(locale) do
- if libs[name] then
- libs[name].description = locale[name].description
- mergeEnum(libs[name].enums, locale[name].enums)
- mergeField(libs[name].fields, locale[name].fields)
- end
- end
-end
-
-local function mergeLibs(target, libs)
- if not libs then
- return
- end
- for name, lib in pairs(libs) do
- target.names[#target.names+1] = name
- target.libs[#target.libs+1] = lib
- end
-end
-
-local function loadLocale(language, relative)
- local localePath = ROOT / 'locale' / language / relative
- local localeBuf = io.load(localePath)
- if localeBuf then
- local locale = table.container()
- xpcall(lni.classics, log.error, localeBuf, localePath:string(), {locale})
- return locale
- end
- return nil
-end
-
-local Libs
-local function getLibs()
- if Libs then
- return Libs
- end
- local language = require 'language'
- Libs = setmetatable({
- names = {},
- libs = {},
- }, {
- __pairs = function (self)
- local i = 0
- return function ()
- i = i + 1
- return self.names[i], self.libs[i]
- end
- end,
- })
- for path in io.scan(ROOT / 'libs') do
- local libs
- local buf = io.load(path)
- if buf then
- libs = table.container()
- xpcall(lni.classics, log.error, buf, path:string(), {libs})
- end
- local relative = fs.relative(path, ROOT)
-
- local locale = loadLocale('en-US', relative)
- mergeLocale(libs, locale)
- if language ~= 'en-US' then
- locale = loadLocale(language, relative)
- mergeLocale(libs, locale)
- end
- mergeLibs(Libs, libs)
- end
-
- return Libs
-end
+local libs = require 'matcher.library'
local function isGlobal(var)
if var.type ~= 'field' then
@@ -208,7 +100,7 @@ local function checkParent(value, name, lib)
return nil
end
-local function findLib(var, libs)
+local function findLib(var)
local value = var.value or var
for libname, lib in pairs(libs) do
if lib.parent then
@@ -227,7 +119,6 @@ local function findLib(var, libs)
end
return function (var)
- local libs = getLibs()
- local lib, fullKey, oo = findLib(var, libs)
+ local lib, fullKey, oo = findLib(var)
return lib, fullKey, oo
end