diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-22 15:38:49 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-22 15:38:49 +0800 |
commit | 48c5a0eea7c9478b43d447b0c47ee2f3d7b01f47 (patch) | |
tree | 34c8cf81b3bea7aa2ee5b5c7511e7066d8cbd304 | |
parent | ff59147f34b74cf47c474f370463c4ff7ffc0d0c (diff) | |
download | lua-language-server-48c5a0eea7c9478b43d447b0c47ee2f3d7b01f47.zip |
#409
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | locale/en-us/script.lua | 1 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 1 | ||||
-rw-r--r-- | meta/3rd/example/config.lua | 14 | ||||
-rw-r--r-- | script/client.lua | 12 | ||||
-rw-r--r-- | script/config/config.lua | 23 |
6 files changed, 51 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md index 34ca77f1..6d9882e7 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # changelog +## 2.3.3 +* `NEW` config supports prop + ## 2.3.2 `2021-7-21` * `NEW` `LuaDoc`: supports `['string']` as field: diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index 2125ee0c..7af86ba0 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -238,6 +238,7 @@ WINDOW_TELEMETRY_DISABLE = 'Prohibit' WINDOW_CLIENT_NOT_SUPPORT_CONFIG = 'Your client does not support modifying settings from the server side, please manually modify the following settings:' WINDOW_MANUAL_CONFIG_ADD = '`{key}`: add element `{value:q}` ;' WINDOW_MANUAL_CONFIG_SET = '`{key}`: set to `{value:q}` ;' +WINDOW_MANUAL_CONFIG_PROP = '`{key}`: set the property `{prop}` to `{value:q}`;' WINDOW_APPLY_WHIT_SETTING = 'Apply and modify settings' WINDOW_APPLY_WHITOUT_SETTING = 'Apply but do not modify settings' WINDOW_ASK_APPLY_LIBRARY = 'Do you need to configure your work environment as `{}`?' diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index a1619b98..cdd0d900 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -237,6 +237,7 @@ WINDOW_TELEMETRY_DISABLE = '禁止' WINDOW_CLIENT_NOT_SUPPORT_CONFIG = '你的客户端不支持从服务侧修改设置,请手动修改如下设置:' WINDOW_MANUAL_CONFIG_ADD = '为 `{key}` 添加值 `{value:q}`;' WINDOW_MANUAL_CONFIG_SET = '将 `{key}` 的值设置为 `{value:q}`;' +WINDOW_MANUAL_CONFIG_PROP = '将 `{key}` 的属性 `{prop}` 设置为 `{value:q}`;' WINDOW_APPLY_WHIT_SETTING = '应用并修改设置' WINDOW_APPLY_WHITOUT_SETTING = '应用但不修改设置' WINDOW_ASK_APPLY_LIBRARY = '是否需要将你的工作环境配置为 `{}` ?' diff --git a/meta/3rd/example/config.lua b/meta/3rd/example/config.lua index e3ae0601..e3d13e41 100644 --- a/meta/3rd/example/config.lua +++ b/meta/3rd/example/config.lua @@ -15,7 +15,19 @@ configs = { key = 'Lua.diagnostics.globals', action = 'add', value = 'global1', - } + }, + { + key = 'Lua.runtime.special', + action = 'prop', + prop = 'include', + value = 'require', + }, + { + key = 'Lua.runtime.builtin', + action = 'prop', + prop = 'io', + value = 'disable', + }, } for _, name in ipairs {'global2', 'global3', 'global4'} do configs[#configs+1] = { diff --git a/script/client.lua b/script/client.lua index 92bb1327..ad585e85 100644 --- a/script/client.lua +++ b/script/client.lua @@ -99,8 +99,9 @@ end ---@class config.change ---@field key string +---@field prop? string ---@field value any ----@field action '"add"'|'"set"' +---@field action '"add"'|'"set"'|'"prop"' ---@field isGlobal? boolean ---@field uri? uri @@ -119,6 +120,11 @@ function m.setConfig(changes, onlyMemory) if suc then finalChanges[#finalChanges+1] = change end + elseif change.action == 'prop' then + local suc = config.prop(change.key, change.prop, change.value) + if suc then + finalChanges[#finalChanges+1] = change + end end change.uri = m.info.rootUri end @@ -139,8 +145,10 @@ function m.setConfig(changes, onlyMemory) for _, change in ipairs(finalChanges) do if change.action == 'add' then messages[#messages+1] = lang.script('WINDOW_MANUAL_CONFIG_ADD', change) - else + elseif change.action == 'set' then messages[#messages+1] = lang.script('WINDOW_MANUAL_CONFIG_SET', change) + elseif change.action == 'prop' then + messages[#messages+1] = lang.script('WINDOW_MANUAL_CONFIG_PROP', change) end end local message = table.concat(messages, '\n') diff --git a/script/config/config.lua b/script/config/config.lua index e9b29e6b..d6919c65 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -254,6 +254,29 @@ function m.add(key, value) return true end +function m.prop(key, prop, value) + local unit = Template[key] + if not unit then + return false + end + local map = rawConfig[key] + if type(map) ~= 'table' then + return false + end + if util.equal(map[prop], value) then + return false + end + local copyed = {} + for k, v in pairs(map) do + copyed[k] = v + end + copyed[prop] = value + if unit:checker(copyed) then + update(key, unit:loader(copyed), copyed) + end + return true +end + function m.get(key) return config[key] end |