diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-05 20:34:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-05 20:34:39 +0800 |
commit | b6c18d05410fd4ca209f9c34e0992caf40cf3701 (patch) | |
tree | 8470435ace81e1959df2b4df1f71b2bac18de540 | |
parent | 0d3dce5321332022552fca038e2e2d35985235c6 (diff) | |
download | lua-language-server-b6c18d05410fd4ca209f9c34e0992caf40cf3701.zip |
improve changing config
-rw-r--r-- | script/provider/client.lua | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/script/provider/client.lua b/script/provider/client.lua index afb0a98f..d208360c 100644 --- a/script/provider/client.lua +++ b/script/provider/client.lua @@ -1,7 +1,8 @@ -local nonil = require 'without-check-nil' -local util = require 'utility' -local lang = require 'language' -local proto = require 'proto' +local nonil = require 'without-check-nil' +local util = require 'utility' +local lang = require 'language' +local proto = require 'proto' +local define = require 'proto.define' local m = {} @@ -29,21 +30,55 @@ function m.isVSCode() return m._isvscode end +function m.getOption(name) + nonil.enable() + local option = m.info.initializationOptions[name] + nonil.disable() + return option +end + +---show message to client +---@param type '"Error"'|'"Warning"'|'"Info"'|'"Log"' +---@param message any +function m.showMessage(type, message) + proto.notify('window/showMessage', { + type = define.MessageType[type] or 3, + message = message, + }) +end + ---set client config ---@param key string ---@param action '"set"'|'"add"' ---@param value any ---@param isGlobal boolean function m.setConfig(key, action, value, isGlobal) - proto.notify('$/command', { - command = 'lua.config', - data = { - key = key, - action = action, - value = value, - global = isGlobal, - } - }) + if m.getOption 'changeConfiguration' then + proto.notify('$/command', { + command = 'lua.config', + data = { + key = key, + action = action, + value = value, + global = isGlobal, + } + }) + else + -- TODO translate + local message = lang.script('你的客户端不支持从服务侧修改设置,请手动修改如下设置:') + if action == 'add' then + message = message .. lang.script('为 `{key}` 添加值 `{value}`', { + key = key, + value = value, + }) + else + message = message .. lang.script('将 `{key}` 的值设置为 `{value}`', { + key = key, + value = value, + }) + end + m.showMessage('Info', message) + end end function m.init(t) |