diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-28 00:09:22 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-28 00:09:22 +0800 |
commit | 85768c4898cd29355e2a6d009cd68ff40ae7e404 (patch) | |
tree | 669f2cd89d36f4b74b94f3de9980fee5623fa937 /script-beta/provider/semantic-tokens.lua | |
parent | 2f84107fab60bd928fb417f1d3c3478a2ccbd3fb (diff) | |
download | lua-language-server-85768c4898cd29355e2a6d009cd68ff40ae7e404.zip |
语义着色
Diffstat (limited to 'script-beta/provider/semantic-tokens.lua')
-rw-r--r-- | script-beta/provider/semantic-tokens.lua | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/script-beta/provider/semantic-tokens.lua b/script-beta/provider/semantic-tokens.lua new file mode 100644 index 00000000..a8b1b23f --- /dev/null +++ b/script-beta/provider/semantic-tokens.lua @@ -0,0 +1,65 @@ +local proto = require 'proto' +local tokenTypes = require 'define.TokenTypes' +local tokenModifiers = require 'define.TokenModifiers' +local client = require 'provider.client' + +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 function enable() + if isEnable then + return + end + if not client.info.capabilities.textDocument.semanticTokens then + return + end + isEnable = true + log.debug('Enable semantic tokens.') + proto.awaitRequest('client/registerCapability', { + registrations = { + { + id = 'semantic-tokens', + method = 'textDocument/semanticTokens/full', + registerOptions = { + legend = { + tokenTypes = toArray(tokenTypes), + tokenModifiers = toArray(tokenModifiers), + }, + range = true, + full = false, + }, + }, + } + }) +end + +local function disable() + if not isEnable then + return + end + isEnable = false + log.debug('Disable semantic tokens.') + proto.awaitRequest('client/unregisterCapability', { + unregisterations = { + { + id = 'semantic-tokens', + method = 'textDocument/semanticTokens/full', + }, + } + }) +end + +return { + enable = enable, + disable = disable, +} |