diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-11-22 14:33:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-11-22 14:33:42 +0800 |
commit | 2b2eea0beef2ce5e9705cdda7f467fd96f8de5bc (patch) | |
tree | 1dae1f06da79ac0d63cb75b9d76daa7a15ace862 /script/provider | |
parent | 9313b06d5c6558dca5d0ece8967c84fbab12543c (diff) | |
download | lua-language-server-2b2eea0beef2ce5e9705cdda7f467fd96f8de5bc.zip |
merge settings
Diffstat (limited to 'script/provider')
-rw-r--r-- | script/provider/provider.lua | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/script/provider/provider.lua b/script/provider/provider.lua index d732f3c2..2bda860c 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -15,33 +15,48 @@ local tm = require 'text-merger' local cfgLoader = require 'config.loader' local converter = require 'proto.converter' local filewatch = require 'filewatch' +local json = require 'json' + +local function mergeConfig(a, b) + for k, v in pairs(b) do + if a[k] == nil then + a[k] = v + end + end +end ---@async local function updateConfig() - local new + local merged = {} + if CONFIGPATH then - new = cfgLoader.loadLocalConfig(CONFIGPATH) - config.setSource 'path' + local cfg = cfgLoader.loadLocalConfig(CONFIGPATH) log.debug('load config from local', CONFIGPATH) -- watch directory filewatch.watch(workspace.getAbsolutePath(CONFIGPATH):gsub('[^/\\]+$', '')) - else - new = cfgLoader.loadRCConfig('.luarc.json') - if new then - config.setSource 'luarc' - log.debug('load config from luarc') - else - new = cfgLoader.loadClientConfig() - config.setSource 'client' - log.debug('load config from client') - end + mergeConfig(merged, cfg) end - if not new then - log.warn('load config failed!') - return + + local rc = cfgLoader.loadRCConfig('.luarc.json') + if rc then + log.debug('load config from luarc') + mergeConfig(merged, rc) + end + + local clientConfig = cfgLoader.loadClientConfig() + if clientConfig then + log.debug('load config from client') + mergeConfig(merged, clientConfig) end - config.update(new) - log.debug('loaded config dump:', util.dump(new)) + + for k, v in pairs(merged) do + if v == json.null then + merged[k] = nil + end + end + + config.update(merged) + log.debug('loaded config dump:', util.dump(merged)) end ---@class provider |