summaryrefslogtreecommitdiff
path: root/script/provider/semantic-tokens.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-20 21:57:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-20 21:57:09 +0800
commit4ca61ec457822dd14966afa0752340ae8ce180a1 (patch)
treeae8adb1ad82c717868e551e699fd3cf3bb290089 /script/provider/semantic-tokens.lua
parentc63b2e404d8d2bb984afe3678a5ba2b2836380cc (diff)
downloadlua-language-server-4ca61ec457822dd14966afa0752340ae8ce180a1.zip
no longer beta
Diffstat (limited to 'script/provider/semantic-tokens.lua')
-rw-r--r--script/provider/semantic-tokens.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua
new file mode 100644
index 00000000..17985bcd
--- /dev/null
+++ b/script/provider/semantic-tokens.lua
@@ -0,0 +1,64 @@
+local proto = require 'proto'
+local define = require 'proto.define'
+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',
+ registerOptions = {
+ legend = {
+ tokenTypes = toArray(define.TokenTypes),
+ tokenModifiers = toArray(define.TokenModifiers),
+ },
+ range = true,
+ full = true,
+ },
+ },
+ }
+ })
+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',
+ },
+ }
+ })
+end
+
+return {
+ enable = enable,
+ disable = disable,
+}