summaryrefslogtreecommitdiff
path: root/script/provider
diff options
context:
space:
mode:
Diffstat (limited to 'script/provider')
-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
5 files changed, 87 insertions, 50 deletions
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)