summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-07 11:12:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-07 11:12:30 +0800
commit336c0b712babf2f5a0dec2c2f27963d5e568eff2 (patch)
treec75c44f46eb66f8e49f1e1ef5cb27fb4c2c9e59d
parent73c4266110bd1013610db15a7e19d40498687b09 (diff)
downloadlua-language-server-336c0b712babf2f5a0dec2c2f27963d5e568eff2.zip
improve changing config from server side
-rw-r--r--changelog.md1
-rw-r--r--meta/3rd/example/config.lua4
-rw-r--r--script/config/config.lua24
-rw-r--r--script/core/code-action.lua8
-rw-r--r--script/core/command/setConfig.lua5
-rw-r--r--script/provider/capability.lua1
-rw-r--r--script/provider/client.lua36
-rw-r--r--script/provider/diagnostic.lua4
-rw-r--r--script/provider/init.lua2
-rw-r--r--script/provider/provider.lua94
-rw-r--r--script/workspace/workspace.lua2
11 files changed, 125 insertions, 56 deletions
diff --git a/changelog.md b/changelog.md
index 0a98c3ec..d0953b97 100644
--- a/changelog.md
+++ b/changelog.md
@@ -16,6 +16,7 @@
z?: boolean,
}
```
+* `CHG` improve changing config from server side
* `CHG` improve hover color
* `CHG` improve performance
* `FIX` supports for file with LF
diff --git a/meta/3rd/example/config.lua b/meta/3rd/example/config.lua
index db6dc971..7b964d54 100644
--- a/meta/3rd/example/config.lua
+++ b/meta/3rd/example/config.lua
@@ -1,7 +1,7 @@
-- list of matched words
-words = {'thisIsAnExampleWord.ifItExistsInFile.thenTryLoadThisLibrary'}
+words = {'thisIsAnExampleWord%.ifItExistsInFile%.thenTryLoadThisLibrary'}
-- list or matched file names
-files = {'thisIsAnExampleFile.ifItExistsInWorkSpace.thenTryLoadThisLibrary'}
+files = {'thisIsAnExampleFile%.ifItExistsInWorkSpace%.thenTryLoadThisLibrary'}
-- lsit of settings to be changed
configs = {
{
diff --git a/script/config/config.lua b/script/config/config.lua
index 2f623920..521e6817 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -171,6 +171,7 @@ local Template = {
['Lua.workspace.maxPreload'] = Type.Integer >> 1000,
['Lua.workspace.preloadFileSize'] = Type.Integer >> 100,
['Lua.workspace.library'] = Type.Hash(Type.String, Type.Boolean, ';'),
+ ['Lua.workspace.checkThirdParty'] = Type.Boolean >> true,
['Lua.completion.enable'] = Type.Boolean >> true,
['Lua.completion.callSnippet'] = Type.String >> 'Disable',
['Lua.completion.keywordSnippet'] = Type.String >> 'Replace',
@@ -200,6 +201,7 @@ local Template = {
}
local config = {}
+local raw = {}
local m = {}
@@ -210,8 +212,30 @@ function m.set(key, value)
end
if unit:checker(value) then
config[key] = unit:loader(value)
+ raw[key] = value
else
config[key] = unit.default
+ raw[key] = unit.default
+ end
+end
+
+function m.add(key, value)
+ local unit = Template[key]
+ if not unit then
+ return
+ end
+ local list = raw[key]
+ if type(list) ~= 'table' then
+ return
+ end
+ local copyed = {}
+ for i, v in ipairs(list) do
+ copyed[i] = v
+ end
+ copyed[#copyed+1] = value
+ if unit:checker(copyed) then
+ config[key] = unit:loader(copyed)
+ raw[key] = copyed
end
end
diff --git a/script/core/code-action.lua b/script/core/code-action.lua
index 3fd58c81..ec43d166 100644
--- a/script/core/code-action.lua
+++ b/script/core/code-action.lua
@@ -64,7 +64,7 @@ local function disableDiagnostic(uri, code, start, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_DISABLE_DIAG,
- command = 'lua.config',
+ command = 'lua.setConfig:' .. sp:get_id(),
arguments = {
{
key = 'Lua.diagnostics.disable',
@@ -101,7 +101,7 @@ local function markGlobal(uri, name, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_MARK_GLOBAL,
- command = 'lua.config',
+ command = 'lua.setConfig:' .. sp:get_id(),
arguments = {
{
key = 'Lua.diagnostics.globals',
@@ -120,7 +120,7 @@ local function changeVersion(uri, version, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_RUNTIME_VERSION,
- command = 'lua.config',
+ command = 'lua.setConfig:' .. sp:get_id(),
arguments = {
{
key = 'Lua.runtime.version',
@@ -233,7 +233,7 @@ local function solveSyntaxUnicodeName(uri, err, results)
kind = 'quickfix',
command = {
title = lang.script.COMMAND_UNICODE_NAME,
- command = 'lua.config',
+ command = 'lua.setConfig:' .. sp:get_id(),
arguments = {
{
key = 'Lua.runtime.unicodeName',
diff --git a/script/core/command/setConfig.lua b/script/core/command/setConfig.lua
new file mode 100644
index 00000000..c5fc3f44
--- /dev/null
+++ b/script/core/command/setConfig.lua
@@ -0,0 +1,5 @@
+local client = require 'provider.client'
+
+return function (data)
+ client.setConfig(data.key, data.action, data.value, data.isGlobal, data.uri)
+end
diff --git a/script/provider/capability.lua b/script/provider/capability.lua
index 72329eff..3cc98744 100644
--- a/script/provider/capability.lua
+++ b/script/provider/capability.lua
@@ -81,6 +81,7 @@ function m.getIniter()
'lua.removeSpace:' .. sp:get_id(),
'lua.solve:' .. sp:get_id(),
'lua.jsonToLua:' .. sp:get_id(),
+ 'lua.setConfig:' .. sp:get_id(),
},
},
foldingRangeProvider = true,
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
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 862d74a3..e3131272 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -284,11 +284,15 @@ local function askForDisable()
client.setConfig('Lua.diagnostics.workspaceDelay'
, 'set'
, delay * 1000
+ , false
+ , ws.uri
)
elseif item.title == lang.script.WINDOW_DISABLE_DIAGNOSTIC then
client.setConfig('Lua.diagnostics.workspaceDelay'
, 'set'
, -1
+ , false
+ , ws.uri
)
end
end
diff --git a/script/provider/init.lua b/script/provider/init.lua
index 7eafb70a..a69fbab3 100644
--- a/script/provider/init.lua
+++ b/script/provider/init.lua
@@ -1 +1 @@
-require 'provider.provider'
+return require 'provider.provider'
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)
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index ee887064..438a5c74 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -207,6 +207,8 @@ local function loadFileFactory(root, progressData, isLibrary)
, 'set'
, config.get 'Lua.workspace.maxPreload'
+ math.max(1000, config.get 'Lua.workspace.maxPreload')
+ , false
+ , m.uri
)
end
end)