diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-06 21:18:58 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-06 21:18:58 +0800 |
commit | 6f76cb75f205bc2343ac0155abbcb2f23a764d10 (patch) | |
tree | 8e65688e0a130212b18ebadc386b3356ebe70fa3 /script/provider/semantic-tokens.lua | |
parent | 1cb6288aa6f5fe4c79d96bdf82890b637a068784 (diff) | |
download | lua-language-server-6f76cb75f205bc2343ac0155abbcb2f23a764d10.zip |
update semantic-tokens
Diffstat (limited to 'script/provider/semantic-tokens.lua')
-rw-r--r-- | script/provider/semantic-tokens.lua | 88 |
1 files changed, 9 insertions, 79 deletions
diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua index b867359f..89c396f0 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -6,48 +6,14 @@ local config = require 'config' local lang = require 'language' local nonil = require 'without-check-nil' -local isEnable = false - -local function toArray(map) - local array = {} - for k in pairs(map) do - array[#array+1] = k - end - table.sort(array, function (a, b) - return map[a] < map[b] - end) - return array -end - local dontShowAgain = false -local function enable(uri) - if isEnable then - return - end - nonil.enable() - if not client.info.capabilities.textDocument.semanticTokens.dynamicRegistration then +local function check(uri) + if dontShowAgain then return end + dontShowAgain = true nonil.disable() - isEnable = true - log.debug('Enable semantic tokens.') - proto.request('client/registerCapability', { - registrations = { - { - id = 'semantic-tokens', - method = 'textDocument/semanticTokens', - registerOptions = { - legend = { - tokenTypes = toArray(define.TokenTypes), - tokenModifiers = toArray(define.TokenModifiers), - }, - range = true, - full = false, - }, - }, - } - }) - if config.get(uri, 'editor.semanticHighlighting.enabled') == 'configuredByTheme' and not dontShowAgain then + if config.get(uri, 'editor.semanticHighlighting.enabled') == 'configuredByTheme' then proto.request('window/showMessageRequest', { type = define.MessageType.Info, message = lang.script.WINDOW_CHECK_SEMANTIC, @@ -73,57 +39,25 @@ local function enable(uri) } } end - if item.title == lang.script.WINDOW_DONT_SHOW_AGAIN then - dontShowAgain = true - end end) end end -local function disable(uri) - if not isEnable then - return - end - nonil.enable() - if not client.info.capabilities.textDocument.semanticTokens.dynamicRegistration then - return - end - nonil.disable() - isEnable = false - log.debug('Disable semantic tokens.') - proto.request('client/unregisterCapability', { - unregisterations = { - { - id = 'semantic-tokens', - method = 'textDocument/semanticTokens', - }, - } - }) -end - local function refresh() - if not isEnable then + if not client.isReady() then return end log.debug('Refresh semantic tokens.') proto.request('workspace/semanticTokens/refresh', json.null) + check() end config.watch(function (uri, key, value, oldValue) if key == '' then - key = 'Lua.color.mode' - value = config.get(uri, key) + refresh() end if key == 'Lua.color.mode' then - if value == 'Semantic' or value == 'SemanticEnhanced' then - if isEnable and value ~= oldValue then - refresh() - else - enable(uri) - end - else - disable(uri) - end + refresh() end if key:find '^Lua.runtime' or key:find '^Lua.workspace' @@ -132,8 +66,4 @@ config.watch(function (uri, key, value, oldValue) end end) -return { - enable = enable, - disable = disable, - refresh = refresh, -} +return {} |