summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json2
-rw-r--r--script/config/config.lua28
-rw-r--r--script/library.lua8
-rw-r--r--script/provider/completion.lua11
-rw-r--r--script/provider/diagnostic.lua8
-rw-r--r--script/provider/provider.lua48
-rw-r--r--script/provider/semantic-tokens.lua15
-rw-r--r--script/service/service.lua11
-rw-r--r--script/service/telemetry.lua6
-rw-r--r--script/workspace/workspace.lua10
10 files changed, 89 insertions, 58 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index c2dd4704..802eba16 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -24,7 +24,7 @@
"type": "lua",
"request": "attach",
"stopOnEntry": true,
- "address": "127.0.0.1:11413",
+ "address": "127.0.0.1:11427",
"outputCapture": [
],
"sourceMaps": [
diff --git a/script/config/config.lua b/script/config/config.lua
index e7831707..3761266b 100644
--- a/script/config/config.lua
+++ b/script/config/config.lua
@@ -193,7 +193,7 @@ local Template = {
['Lua.hint.paramName'] = Type.Boolean >> true,
['Lua.window.statusBar'] = Type.Boolean >> true,
['Lua.window.progressBar'] = Type.Boolean >> true,
- ['Lua.telemetry.enable'] = Type.Or(Type.Boolean, Type.Nil),
+ ['Lua.telemetry.enable'] = Type.Or(Type.Boolean >> false, Type.Nil),
['files.associations'] = Type.Hash(Type.String, Type.String),
['files.exclude'] = Type.Hash(Type.String, Type.Boolean),
['editor.semanticHighlighting.enabled'] = Type.Or(Type.Boolean, Type.String),
@@ -208,12 +208,9 @@ m.watchList = {}
local function update(key, value, raw)
local oldValue = config[key]
- if util.equal(oldValue, value) then
- return
- end
config[key] = value
rawConfig[key] = raw
- m.event('update', key, value, oldValue)
+ m.event(key, value, oldValue)
end
function m.set(key, value)
@@ -293,16 +290,29 @@ end
function m.watch(callback)
m.watchList[#m.watchList+1] = callback
+ if m.inited then
+ for key in pairs(Template) do
+ callback(key, m.get(key), m.get(key))
+ end
+ end
end
-function m.event(ev, ...)
+function m.event(key, value, oldValue)
for _, callback in ipairs(m.watchList) do
- callback(ev, ...)
+ callback(key, value, oldValue)
end
end
-for key in pairs(Template) do
- m.set(key)
+function m.init()
+ if m.inited then
+ return
+ end
+ m.init = true
+ for key in pairs(Template) do
+ m.set(key)
+ end
end
+m.init()
+
return m
diff --git a/script/library.lua b/script/library.lua
index 9fc6a655..a46416c7 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -233,4 +233,12 @@ function m.init()
initBuiltIn()
end
+config.watch(function (key, value, oldValue)
+ if key:find '^Lua.runtime' then
+ if value ~= oldValue then
+ initBuiltIn()
+ end
+ end
+end)
+
return m
diff --git a/script/provider/completion.lua b/script/provider/completion.lua
index 108ea023..227964b3 100644
--- a/script/provider/completion.lua
+++ b/script/provider/completion.lua
@@ -1,6 +1,7 @@
local proto = require 'proto'
local nonil = require 'without-check-nil'
local client = require 'client'
+local config = require 'config'
local isEnable = false
@@ -59,6 +60,16 @@ local function disable()
})
end
+config.watch(function (key, value)
+ if key == 'Lua.completion.enable' then
+ if value == true then
+ enable()
+ else
+ disable()
+ end
+ end
+end)
+
return {
enable = enable,
disable = disable,
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 0a857be7..7ded406d 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -411,4 +411,12 @@ await.watch(function (ev, co)
end
end)
+config.watch(function (key, value, oldValue)
+ if key:find 'Lua.diagnostics' then
+ if value ~= oldValue then
+ m.diagnosticsAll()
+ end
+ end
+end)
+
return m
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 5ad5bc0b..138ee1b5 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -21,47 +21,6 @@ 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 newConfig = config.dump()
- log.debug('config updated:', util.dump(newConfig))
-
- if not util.equal(oldConfig.Lua.runtime, newConfig.Lua.runtime) then
- library.init()
- workspace.reload()
- semantic.refresh()
- end
- if not util.equal(oldConfig.Lua.diagnostics, newConfig.Lua.diagnostics) then
- diagnostics.diagnosticsAll()
- end
- if not util.equal(oldConfig.Lua.workspace, newConfig.Lua.workspace)
- or not util.equal(oldConfig.files, newConfig.files)
- then
- workspace.reload()
- semantic.refresh()
- end
-
- if newConfig.Lua.completion.enable then
- completion.enable()
- else
- completion.disable()
- end
- if newConfig.Lua.color.mode == 'Semantic' then
- semantic.enable()
- else
- semantic.disable()
- end
- if newConfig.Lua.window.statusBar then
- proto.notify('$/status/show')
- else
- proto.notify('$/status/hide')
- end
- telemetry.updateConfig()
- oldConfig = newConfig
-end
-
local function updateConfig()
local new
if CONFIGPATH then
@@ -77,15 +36,8 @@ local function updateConfig()
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()
diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua
index 5e331ebd..567f80e2 100644
--- a/script/provider/semantic-tokens.lua
+++ b/script/provider/semantic-tokens.lua
@@ -106,6 +106,21 @@ local function refresh()
proto.notify('workspace/semanticTokens/refresh', json.null)
end
+config.watch(function (key, value)
+ if key == 'Lua.color.mode' then
+ if value == 'Semantic' then
+ enable()
+ else
+ disable()
+ end
+ end
+ if key:find '^Lua.runtime'
+ or key:find '^Lua.workspace'
+ or key:find '^files' then
+ refresh()
+ end
+end)
+
return {
enable = enable,
disable = disable,
diff --git a/script/service/service.lua b/script/service/service.lua
index 247cb5b5..bd9c425f 100644
--- a/script/service/service.lua
+++ b/script/service/service.lua
@@ -10,6 +10,7 @@ local files = require 'files'
local lang = require 'language'
local ws = require 'workspace'
local time = require 'bee.time'
+local config = require 'config'
local m = {}
m.type = 'service'
@@ -198,6 +199,16 @@ function m.reportStatus()
proto.notify('$/status/report', info)
end
+config.watch(function (key, value)
+ if key == 'Lua.window.statusBar' then
+ if value then
+ proto.notify('$/status/show')
+ else
+ proto.notify('$/status/hide')
+ end
+ end
+end)
+
function m.testVersion()
local stack = debug.setcstacklimit(200)
debug.setcstacklimit(stack + 1)
diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua
index 7a2b2514..419589e7 100644
--- a/script/service/telemetry.lua
+++ b/script/service/telemetry.lua
@@ -141,4 +141,10 @@ function m.updateConfig()
end)
end
+config.watch(function (key)
+ if key == 'Lua.telemetry.enable' then
+ m.updateConfig()
+ end
+end)
+
return m
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index b50ed42b..d426f6b5 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -535,4 +535,14 @@ files.watch(function (ev, uri)
end
end)
+config.watch(function (key, value, oldValue)
+ if key:find '^Lua.runtime'
+ or key:find '^Lua.workspace'
+ or key:find '^files' then
+ if value ~= oldValue then
+ m.reload()
+ end
+ end
+end)
+
return m