summaryrefslogtreecommitdiff
path: root/server/src/config.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-02 17:41:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-02 17:41:50 +0800
commit052e45705d43bc653ade996f06d8441dc599e918 (patch)
treebf55818017952dc53a324cfdb3948a28995ce9f6 /server/src/config.lua
parentd31e160cc16f94be9926888ef245dd20554fdd0f (diff)
downloadlua-language-server-052e45705d43bc653ade996f06d8441dc599e918.zip
支持部分配置
Diffstat (limited to 'server/src/config.lua')
-rw-r--r--server/src/config.lua63
1 files changed, 63 insertions, 0 deletions
diff --git a/server/src/config.lua b/server/src/config.lua
new file mode 100644
index 00000000..8aff6d40
--- /dev/null
+++ b/server/src/config.lua
@@ -0,0 +1,63 @@
+local function Boolean(v)
+ if type(v) == 'boolean' then
+ return true, v
+ end
+ return false
+end
+
+local function Str2Hash(sep)
+ return function (v)
+ if type(v) ~= 'string' then
+ return false
+ end
+ local t = {}
+ for s in v:gmatch('[^'..sep..']+') do
+ t[s] = true
+ end
+ return t
+ end
+end
+
+local Template = {
+ diagnostics = {
+ postSpcae = {true, Boolean},
+ spaceOnlyLine = {true, Boolean},
+ globals = {{}, Str2Hash ';'},
+ }
+}
+
+local Config
+
+local function init()
+ if Config then
+ return
+ end
+ Config = {}
+ for c, t in pairs(Template) do
+ Config[c] = {}
+ for k, info in pairs(t) do
+ Config[c][k] = info[1]
+ end
+ end
+end
+
+local function setConfig(config)
+ pcall(function ()
+ for c, t in pairs(config) do
+ for k, v in pairs(t) do
+ local f = Template[c][k]
+ local suc, v = f(v)
+ if suc then
+ Config[c][k] = v
+ end
+ end
+ end
+ end)
+end
+
+init()
+
+return {
+ setConfig = setConfig,
+ config = Config,
+}