diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-07 11:12:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-07 11:12:30 +0800 |
commit | 336c0b712babf2f5a0dec2c2f27963d5e568eff2 (patch) | |
tree | c75c44f46eb66f8e49f1e1ef5cb27fb4c2c9e59d /script/provider/provider.lua | |
parent | 73c4266110bd1013610db15a7e19d40498687b09 (diff) | |
download | lua-language-server-336c0b712babf2f5a0dec2c2f27963d5e568eff2.zip |
improve changing config from server side
Diffstat (limited to 'script/provider/provider.lua')
-rw-r--r-- | script/provider/provider.lua | 94 |
1 files changed, 53 insertions, 41 deletions
diff --git a/script/provider/provider.lua b/script/provider/provider.lua index b90e5a13..1dfe2719 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -1,46 +1,30 @@ -local util = require 'utility' -local cap = require 'provider.capability' -local completion= require 'provider.completion' -local semantic = require 'provider.semantic-tokens' -local await = require 'await' -local files = require 'files' -local proto = require 'proto.proto' -local define = require 'proto.define' -local workspace = require 'workspace' -local config = require 'config' -local library = require 'library' -local markdown = require 'provider.markdown' -local client = require 'provider.client' -local furi = require 'file-uri' -local pub = require 'pub' -local fs = require 'bee.filesystem' -local lang = require 'language' -local plugin = require 'plugin' -local progress = require 'progress' -local tm = require 'text-merger' -local vm = require 'vm' -local nonil = require 'without-check-nil' -local cfgLoader = require 'config.loader' - -local function updateConfig() +local util = require 'utility' +local cap = require 'provider.capability' +local completion = require 'provider.completion' +local semantic = require 'provider.semantic-tokens' +local await = require 'await' +local files = require 'files' +local proto = require 'proto.proto' +local define = require 'proto.define' +local workspace = require 'workspace' +local config = require 'config' +local library = require 'library' +local markdown = require 'provider.markdown' +local client = require 'provider.client' +local furi = require 'file-uri' +local pub = require 'pub' +local fs = require 'bee.filesystem' +local lang = require 'language' +local plugin = require 'plugin' +local progress = require 'progress' +local tm = require 'text-merger' +local nonil = require 'without-check-nil' +local cfgLoader = require 'config.loader' + +local oldConfig = config.dump() +local function applyConfig() local diagnostics = require 'provider.diagnostic' local telemetry = require 'service.telemetry' - local new - if CONFIGPATH then - new = cfgLoader.loadLocalConfig(CONFIGPATH) - log.debug('load config from local', CONFIGPATH) - else - new = cfgLoader.loadClientConfig() - log.debug('load config from client') - end - if not new then - log.warn('load config failed!') - return - end - log.debug('loaded config dump:', util.dump(new)) - - local oldConfig = config.dump() - config.update(new) local newConfig = config.dump() log.debug('config updated:', util.dump(newConfig)) @@ -75,8 +59,33 @@ local function updateConfig() proto.notify('$/status/hide') end telemetry.updateConfig() + oldConfig = newConfig +end + +local function updateConfig() + local new + if CONFIGPATH then + new = cfgLoader.loadLocalConfig(CONFIGPATH) + log.debug('load config from local', CONFIGPATH) + else + new = cfgLoader.loadClientConfig() + log.debug('load config from client') + end + if not new then + log.warn('load config failed!') + return + end + config.update(new) + log.debug('loaded config dump:', util.dump(new)) + applyConfig() end +client.watch(function (ev) + if ev == 'updateConfig' then + applyConfig() + end +end) + proto.on('initialize', function (params) client.init(params) library.init() @@ -729,6 +738,9 @@ proto.on('workspace/executeCommand', function (params) elseif command == 'lua.jsonToLua' then local core = require 'core.command.jsonToLua' return core(params.arguments[1]) + elseif command == 'lua.setConfig' then + local core = require 'core.command.setConfig' + return core(params.arguments[1]) end end) |