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/client.lua | |
parent | 73c4266110bd1013610db15a7e19d40498687b09 (diff) | |
download | lua-language-server-336c0b712babf2f5a0dec2c2f27963d5e568eff2.zip |
improve changing config from server side
Diffstat (limited to 'script/provider/client.lua')
-rw-r--r-- | script/provider/client.lua | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/script/provider/client.lua b/script/provider/client.lua index d208360c..4b92c315 100644 --- a/script/provider/client.lua +++ b/script/provider/client.lua @@ -1,10 +1,12 @@ -local nonil = require 'without-check-nil' -local util = require 'utility' -local lang = require 'language' -local proto = require 'proto' -local define = require 'proto.define' +local nonil = require 'without-check-nil' +local util = require 'utility' +local lang = require 'language' +local proto = require 'proto' +local define = require 'proto.define' +local config = require 'config' local m = {} +m.watchList = {} function m.client(newClient) if newClient then @@ -52,7 +54,14 @@ end ---@param action '"set"'|'"add"' ---@param value any ---@param isGlobal boolean -function m.setConfig(key, action, value, isGlobal) +---@param uri uri +function m.setConfig(key, action, value, isGlobal, uri) + if action == 'add' then + config.add(key, value) + elseif action == 'set' then + config.set(key, value) + end + m.event('updateConfig') if m.getOption 'changeConfiguration' then proto.notify('$/command', { command = 'lua.config', @@ -61,18 +70,19 @@ function m.setConfig(key, action, value, isGlobal) action = action, value = value, global = isGlobal, + uri = uri, } }) else -- TODO translate local message = lang.script('你的客户端不支持从服务侧修改设置,请手动修改如下设置:') if action == 'add' then - message = message .. lang.script('为 `{key}` 添加值 `{value}`', { + message = message .. lang.script('为 `{key}` 添加值 `{value:q}`', { key = key, value = value, }) else - message = message .. lang.script('将 `{key}` 的值设置为 `{value}`', { + message = message .. lang.script('将 `{key}` 的值设置为 `{value:q}`', { key = key, value = value, }) @@ -81,6 +91,16 @@ function m.setConfig(key, action, value, isGlobal) end end +function m.event(ev, ...) + for _, callback in ipairs(m.watchList) do + callback(ev, ...) + end +end + +function m.watch(callback) + m.watchList[#m.watchList+1] = callback +end + function m.init(t) log.debug('Client init', util.dump(t)) m.info = t |