diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/client.lua (renamed from script/provider/client.lua) | 16 | ||||
-rw-r--r-- | script/config/config.lua | 20 | ||||
-rw-r--r-- | script/core/command/setConfig.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/unused-function.lua | 2 | ||||
-rw-r--r-- | script/files.lua | 2 | ||||
-rw-r--r-- | script/library.lua | 2 | ||||
-rw-r--r-- | script/provider/capability.lua | 2 | ||||
-rw-r--r-- | script/provider/completion.lua | 2 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 2 | ||||
-rw-r--r-- | script/provider/provider.lua | 2 | ||||
-rw-r--r-- | script/provider/semantic-tokens.lua | 2 | ||||
-rw-r--r-- | script/service/telemetry.lua | 2 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 2 |
13 files changed, 41 insertions, 17 deletions
diff --git a/script/provider/client.lua b/script/client.lua index a3d837bb..14973a64 100644 --- a/script/provider/client.lua +++ b/script/client.lua @@ -39,10 +39,18 @@ function m.getOption(name) return option end +local function packMessage(...) + local strs = table.pack(...) + for i = 1, strs.n do + strs[i] = tostring(strs[i]) + end + return table.concat(strs, '\t') +end + ---show message to client ---@param type '"Error"'|'"Warning"'|'"Info"'|'"Log"' ----@param message any -function m.showMessage(type, message) +function m.showMessage(type, ...) + local message = packMessage(...) proto.notify('window/showMessage', { type = define.MessageType[type] or 3, message = message, @@ -54,8 +62,8 @@ function m.showMessage(type, message) end ---@param type '"Error"'|'"Warning"'|'"Info"'|'"Log"' ----@param message any -function m.logMessage(type, message) +function m.logMessage(type, ...) + local message = packMessage(...) proto.notify('window/logMessage', { type = define.MessageType[type] or 4, message = message, diff --git a/script/config/config.lua b/script/config/config.lua index 61b09f4e..e7831707 100644 --- a/script/config/config.lua +++ b/script/config/config.lua @@ -203,13 +203,19 @@ local Template = { local config = {} local rawConfig = {} +local m = {} +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) end -local m = {} - function m.set(key, value) local unit = Template[key] if not unit then @@ -285,6 +291,16 @@ function m.update(new) expand(new) end +function m.watch(callback) + m.watchList[#m.watchList+1] = callback +end + +function m.event(ev, ...) + for _, callback in ipairs(m.watchList) do + callback(ev, ...) + end +end + for key in pairs(Template) do m.set(key) end diff --git a/script/core/command/setConfig.lua b/script/core/command/setConfig.lua index 21ec1d57..e3eb0d0a 100644 --- a/script/core/command/setConfig.lua +++ b/script/core/command/setConfig.lua @@ -1,4 +1,4 @@ -local client = require 'provider.client' +local client = require 'client' return function (data) client.setConfig {data} diff --git a/script/core/diagnostics/unused-function.lua b/script/core/diagnostics/unused-function.lua index 59f27e59..cf5d47b5 100644 --- a/script/core/diagnostics/unused-function.lua +++ b/script/core/diagnostics/unused-function.lua @@ -4,7 +4,7 @@ local vm = require 'vm' local define = require 'proto.define' local lang = require 'language' local await = require 'await' -local client = require 'provider.client' +local client = require 'client' local function isToBeClosed(source) if not source.attrs then diff --git a/script/files.lua b/script/files.lua index f5727d41..8fbad7c0 100644 --- a/script/files.lua +++ b/script/files.lua @@ -12,7 +12,7 @@ local util = require 'utility' local guide = require 'parser.guide' local smerger = require 'string-merger' local progress = require "progress" -local client = require 'provider.client' +local client = require 'client' local unicode diff --git a/script/library.lua b/script/library.lua index b9ea9892..9fc6a655 100644 --- a/script/library.lua +++ b/script/library.lua @@ -2,7 +2,7 @@ local fs = require 'bee.filesystem' local config = require 'config' local util = require 'utility' local lang = require 'language' -local client = require 'provider.client' +local client = require 'client' local lloader = require 'locale-loader' local fsu = require 'fs-utility' local define = require "proto.define" diff --git a/script/provider/capability.lua b/script/provider/capability.lua index 3cc98744..b8a56b7b 100644 --- a/script/provider/capability.lua +++ b/script/provider/capability.lua @@ -1,6 +1,6 @@ local sp = require 'bee.subprocess' local nonil = require 'without-check-nil' -local client = require 'provider.client' +local client = require 'client' local platform = require 'bee.platform' local completion = require 'provider.completion' diff --git a/script/provider/completion.lua b/script/provider/completion.lua index bca5b7af..108ea023 100644 --- a/script/provider/completion.lua +++ b/script/provider/completion.lua @@ -1,6 +1,6 @@ local proto = require 'proto' local nonil = require 'without-check-nil' -local client = require 'provider.client' +local client = require 'client' local isEnable = false diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index fa31805c..0a857be7 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -8,7 +8,7 @@ local core = require 'core.diagnostics' local util = require 'utility' local ws = require 'workspace' local progress = require "progress" -local client = require 'provider.client' +local client = require 'client' local m = {} m._start = false diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 1dfe2719..5ad5bc0b 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -10,7 +10,7 @@ local workspace = require 'workspace' local config = require 'config' local library = require 'library' local markdown = require 'provider.markdown' -local client = require 'provider.client' +local client = require 'client' local furi = require 'file-uri' local pub = require 'pub' local fs = require 'bee.filesystem' diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua index 942bd046..5e331ebd 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -1,6 +1,6 @@ local proto = require 'proto' local define = require 'proto.define' -local client = require 'provider.client' +local client = require 'client' local json = require "json" local config = require 'config' local lang = require 'language' diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua index 11c872ce..7a2b2514 100644 --- a/script/service/telemetry.lua +++ b/script/service/telemetry.lua @@ -1,7 +1,7 @@ local net = require 'service.net' local timer = require 'timer' local config = require 'config' -local client = require 'provider.client' +local client = require 'client' local nonil = require 'without-check-nil' local util = require 'utility' local platform = require 'bee.platform' diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 99d71b48..b50ed42b 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -11,7 +11,7 @@ local lang = require 'language' local library = require 'library' local progress = require 'progress' local define = require "proto.define" -local client = require 'provider.client' +local client = require 'client' local m = {} m.type = 'workspace' |