summaryrefslogtreecommitdiff
path: root/server/src/config.lua
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-16 17:12:40 +0800
committersumneko <sumneko@hotmail.com>2019-04-16 17:12:40 +0800
commitca69ac28173674eb80f822161ed6379e6070d272 (patch)
tree2b4136ddf7be3e1ddb682d2860f2df460b2f8c7c /server/src/config.lua
parent4cb9c12ca12e3ce6e254897cc1a72f651bd9fdf8 (diff)
downloadlua-language-server-ca69ac28173674eb80f822161ed6379e6070d272.zip
根据文件关联来搜索lua文件
Diffstat (limited to 'server/src/config.lua')
-rw-r--r--server/src/config.lua50
1 files changed, 44 insertions, 6 deletions
diff --git a/server/src/config.lua b/server/src/config.lua
index 125ac655..5272a964 100644
--- a/server/src/config.lua
+++ b/server/src/config.lua
@@ -57,7 +57,27 @@ local function Array(checker)
end
end
-local Template = {
+local function Hash(keyChecker, valueChecker)
+ return function (tbl)
+ if type(tbl) ~= 'table' then
+ return false
+ end
+ local t = {}
+ for k, v in pairs(tbl) do
+ local ok1, key = keyChecker(k)
+ local ok2, value = valueChecker(v)
+ if ok1 and ok2 then
+ t[key] = value
+ end
+ end
+ if not next(t) then
+ return false
+ end
+ return true, t
+ end
+end
+
+local ConfigTemplate = {
runtime = {
version = {'Lua 5.3', String},
library = {{}, Str2Hash ';'},
@@ -80,33 +100,50 @@ local Template = {
}
}
-local Config
+local OtherTemplate = {
+ associations = {{}, Hash(String, String)},
+}
+
+local Config, Other
local function init()
if Config then
return
end
+
Config = {}
- for c, t in pairs(Template) do
+ for c, t in pairs(ConfigTemplate) do
Config[c] = {}
for k, info in pairs(t) do
Config[c][k] = info[1]
end
end
+
+ Other = {}
+ for k, v in pairs(OtherTemplate) do
+ Other[k] = v
+ end
end
-local function setConfig(self, config)
+local function setConfig(self, config, other)
pcall(function ()
for c, t in pairs(config) do
for k, v in pairs(t) do
- local info = Template[c][k]
+ local info = ConfigTemplate[c][k]
local suc, v = info[2](v)
if suc then
Config[c][k] = v
end
end
end
- log.debug('Config update: ', table.dump(Config))
+ for k, v in pairs(other) do
+ local info = OtherTemplate[k]
+ local suc, v = info[2](v)
+ if suc then
+ Other[k] = v
+ end
+ end
+ log.debug('Config update: ', table.dump(Config), table.dump(Other))
end)
end
@@ -115,4 +152,5 @@ init()
return {
setConfig = setConfig,
config = Config,
+ other = Other,
}