diff options
-rw-r--r-- | script/config/config2.lua | 264 | ||||
-rw-r--r-- | script/provider/client.lua | 18 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 25 | ||||
-rw-r--r-- | script/provider/semantic-tokens.lua | 14 | ||||
-rw-r--r-- | script/service/telemetry.lua | 73 | ||||
-rw-r--r-- | script/workspace/workspace.lua | 14 |
6 files changed, 67 insertions, 341 deletions
diff --git a/script/config/config2.lua b/script/config/config2.lua deleted file mode 100644 index 8a69b234..00000000 --- a/script/config/config2.lua +++ /dev/null @@ -1,264 +0,0 @@ -local util = require 'utility' -local define = require 'proto.define' - -local m = {} -m.version = 0 - -local function Boolean(v) - if type(v) == 'boolean' then - return true, v - end - return false -end - -local function Integer(v) - if type(v) == 'number' then - return true, math.floor(v) - end - return false -end - -local function String(v) - return true, tostring(v) -end - -local function Nil(v) - if type(v) == 'nil' then - return true, nil - end - return false -end - -local function Str2Hash(sep) - return function (v) - if type(v) == 'string' then - local t = {} - for s in v:gmatch('[^'..sep..']+') do - t[s] = true - end - return true, t - end - if type(v) == 'table' then - local t = {} - for _, s in ipairs(v) do - if type(s) == 'string' then - t[s] = true - end - end - return true, t - end - return false - end -end - -local function Array2Hash(checker) - return function (tbl) - if type(tbl) ~= 'table' then - return false - end - local t = {} - if #tbl > 0 then - for _, k in ipairs(tbl) do - t[k] = true - end - else - for k, v in pairs(tbl) do - t[k] = v - end - end - return true, t - end -end - -local function Array(checker) - return function (tbl) - if type(tbl) ~= 'table' then - return false - end - local t = {} - for _, v in ipairs(tbl) do - local ok, result = checker(v) - if ok then - t[#t+1] = result - end - end - return true, t - end -end - -local function Hash(keyChecker, valueChecker) - return function (tbl) - if type(tbl) ~= 'table' then - return false - end - local t = {} - for k, v in pairs(tbl) do - local ok1, key = keyChecker(k) - local ok2, value = valueChecker(v) - if ok1 and ok2 then - t[key] = value - end - end - if not next(t) then - return false - end - return true, t - end -end - -local function Or(...) - local checkers = {...} - return function (obj) - for _, checker in ipairs(checkers) do - local suc, res = checker(obj) - if suc then - return true, res - end - end - return false - end -end - -local ConfigTemplate = { - runtime = { - version = {'Lua 5.4', String}, - path = {{ - "?.lua", - "?/init.lua", - "?/?.lua" - }, Array(String)}, - special = {{}, Hash(String, String)}, - meta = {'${version} ${language}', String}, - unicodeName = {false, Boolean}, - nonstandardSymbol = {{}, Str2Hash ';'}, - plugin = {'', String}, - fileEncoding = {'utf8', String}, - builtin = {{}, Hash(String, String)}, - }, - diagnostics = { - enable = {true, Boolean}, - globals = {{}, Str2Hash ';'}, - disable = {{}, Str2Hash ';'}, - severity = { - util.deepCopy(define.DiagnosticDefaultSeverity), - Hash(String, String), - }, - neededFileStatus = { - util.deepCopy(define.DiagnosticDefaultNeededFileStatus), - Hash(String, String), - }, - workspaceDelay = {0, Integer}, - workspaceRate = {100, Integer}, - }, - workspace = { - ignoreDir = {{}, Str2Hash ';'}, - ignoreSubmodules= {true, Boolean}, - useGitIgnore = {true, Boolean}, - maxPreload = {1000, Integer}, - preloadFileSize = {100, Integer}, - library = {{}, Array2Hash(String)}, - }, - completion = { - enable = {true, Boolean}, - callSnippet = {'Disable', String}, - keywordSnippet = {'Replace', String}, - displayContext = {6, Integer}, - workspaceWord = {true, Boolean}, - autoRequire = {true, Boolean}, - showParams = {true, Boolean}, - }, - signatureHelp = { - enable = {true, Boolean}, - }, - hover = { - enable = {true, Boolean}, - viewString = {true, Boolean}, - viewStringMax = {1000, Integer}, - viewNumber = {true, Boolean}, - previewFields = {20, Integer}, - enumsLimit = {5, Integer}, - }, - color = { - mode = {'Semantic', String}, - }, - hint = { - enable = {false, Boolean}, - paramType = {true, Boolean}, - setType = {false, Boolean}, - paramName = {true, Boolean}, - }, - intelliSense = { - searchDepth = {0, Integer}, - }, - window = { - statusBar = {true, Boolean}, - progressBar = {true, Boolean}, - }, - telemetry = { - enable = {nil, Or(Boolean, Nil)}, - } -} - -local OtherTemplate = { - associations = {{}, Hash(String, String)}, - exclude = {{}, Hash(String, Boolean)}, - semantic = {'', Or(Boolean, String)}, - acceptSuggestionOnEnter = {'on', String}, -} - -local function init() - if m.Lua then - return - end - - m.Lua = {} - for c, t in pairs(ConfigTemplate) do - m.Lua[c] = {} - for k, info in pairs(t) do - m.Lua[c][k] = info[1] - end - end - - m.other = {} - for k, info in pairs(OtherTemplate) do - m.other[k] = info[1] - end -end - -function m.setConfig(config, other) - m.version = m.version + 1 - xpcall(function () - for c, t in pairs(config) do - for k, v in pairs(t) do - local region = ConfigTemplate[c] - if region then - local info = region[k] - if info then - local suc, v = info[2](v) - if suc then - m.Lua[c][k] = v - else - m.Lua[c][k] = info[1] - end - end - end - end - end - for k, v in pairs(other) do - local info = OtherTemplate[k] - if info then - local suc, v = info[2](v) - if suc then - m.other[k] = v - else - m.other[k] = info[1] - end - end - end - log.debug('Config update: ', util.dump(m.Lua), util.dump(m.other)) - end, log.error) -end - -init() - -return m diff --git a/script/provider/client.lua b/script/provider/client.lua index 5c2ae653..afb0a98f 100644 --- a/script/provider/client.lua +++ b/script/provider/client.lua @@ -1,6 +1,7 @@ local nonil = require 'without-check-nil' local util = require 'utility' local lang = require 'language' +local proto = require 'proto' local m = {} @@ -28,6 +29,23 @@ function m.isVSCode() return m._isvscode end +---set client config +---@param key string +---@param action '"set"'|'"add"' +---@param value any +---@param isGlobal boolean +function m.setConfig(key, action, value, isGlobal) + proto.notify('$/command', { + command = 'lua.config', + data = { + key = key, + action = action, + value = value, + global = isGlobal, + } + }) +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 b385b4e3..862d74a3 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -8,6 +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 m = {} m._start = false @@ -280,23 +281,15 @@ local function askForDisable() if item.title == lang.script.WINDOW_DONT_SHOW_AGAIN then m.dontAskedForDisable = true elseif item.title == delayTitle then - proto.notify('$/command', { - command = 'lua.config', - data = { - key = 'Lua.diagnostics.workspaceDelay', - action = 'set', - value = delay * 1000, - } - }) + client.setConfig('Lua.diagnostics.workspaceDelay' + , 'set' + , delay * 1000 + ) elseif item.title == lang.script.WINDOW_DISABLE_DIAGNOSTIC then - proto.notify('$/command', { - command = 'lua.config', - data = { - key = 'Lua.diagnostics.workspaceDelay', - action = 'set', - value = -1, - } - }) + client.setConfig('Lua.diagnostics.workspaceDelay' + , 'set' + , -1 + ) end end diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua index fa636381..f9f774b1 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -64,15 +64,11 @@ local function enable() return end if item.title == lang.script.WINDOW_APPLY_SETTING then - proto.notify('$/command', { - command = 'lua.config', - data = { - key = 'editor.semanticHighlighting.enabled', - action = 'set', - value = true, - global = true, - } - }) + client.setConfig('editor.semanticHighlighting.enabled' + , 'set' + , true + , true + ) end if item.title == lang.script.WINDOW_DONT_SHOW_AGAIN then dontShowAgain = true diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua index f3a3cf12..c45320c7 100644 --- a/script/service/telemetry.lua +++ b/script/service/telemetry.lua @@ -102,50 +102,35 @@ function m.updateConfig() m.hasShowedMessage = true await.call(function () - if client.isVSCode() then - local enableTitle = lang.script.WINDOW_TELEMETRY_ENABLE - local disableTitle = lang.script.WINDOW_TELEMETRY_DISABLE - local item = proto.awaitRequest('window/showMessageRequest', { - message = lang.script.WINDOW_TELEMETRY_HINT, - type = define.MessageType.Info, - actions = { - { - title = enableTitle, - }, - { - title = disableTitle, - }, - } - }) - if not item then - return - end - if item.title == enableTitle then - proto.notify('$/command', { - command = 'lua.config', - data = { - key = 'Lua.telemetry.enable', - action = 'set', - value = true, - global = true, - } - }) - elseif item.title == disableTitle then - proto.notify('$/command', { - command = 'lua.config', - data = { - key = 'Lua.telemetry.enable', - action = 'set', - value = false, - global = true, - } - }) - end - else - proto.notify('window/showMessage', { - message = lang.script.WINDOW_TELEMETRY_HINT, - type = define.MessageType.Info, - }) + local enableTitle = lang.script.WINDOW_TELEMETRY_ENABLE + local disableTitle = lang.script.WINDOW_TELEMETRY_DISABLE + local item = proto.awaitRequest('window/showMessageRequest', { + message = lang.script.WINDOW_TELEMETRY_HINT, + type = define.MessageType.Info, + actions = { + { + title = enableTitle, + }, + { + title = disableTitle, + }, + } + }) + if not item then + return + end + if item.title == enableTitle then + client.setConfig('Lua.telemetry.enable' + , 'set' + , true + , true + ) + elseif item.title == disableTitle then + client.setConfig('Lua.telemetry.enable' + , 'set' + , false + , true + ) end end) end diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index f2b71f8a..ee887064 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -11,6 +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 m = {} m.type = 'workspace' @@ -202,14 +203,11 @@ local function loadFileFactory(root, progressData, isLibrary) return end if item.title == lang.script.WINDOW_INCREASE_UPPER_LIMIT then - proto.notify('$/command', { - command = 'lua.config', - data = { - key = 'Lua.workspace.maxPreload', - action = 'set', - value = config.get 'Lua.workspace.maxPreload' + math.max(1000, config.get 'Lua.workspace.maxPreload'), - } - }) + client.setConfig('Lua.workspace.maxPreload' + , 'set' + , config.get 'Lua.workspace.maxPreload' + + math.max(1000, config.get 'Lua.workspace.maxPreload') + ) end end) end |