diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/client.lua | 8 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 3 | ||||
-rw-r--r-- | script/provider/capability.lua | 21 | ||||
-rw-r--r-- | script/provider/provider.lua | 3 | ||||
-rw-r--r-- | script/provider/semantic-tokens.lua | 88 |
5 files changed, 42 insertions, 81 deletions
diff --git a/script/client.lua b/script/client.lua index d223715d..8dec85be 100644 --- a/script/client.lua +++ b/script/client.lua @@ -381,6 +381,14 @@ function m.editText(uri, edits) }) end +function m.setReady() + m._ready = true +end + +function m.isReady() + return m._ready == true +end + local function hookPrint() if TEST then return diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 12848d2b..4c45c429 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -367,6 +367,9 @@ end ---@async return function (uri, start, finish) + if config.get(uri, 'Lua.color.mode') == 'Grammar' then + return nil + end local state = files.getState(uri) if not state then return nil diff --git a/script/provider/capability.lua b/script/provider/capability.lua index 439978d6..8a1424ca 100644 --- a/script/provider/capability.lua +++ b/script/provider/capability.lua @@ -1,11 +1,22 @@ -local sp = require 'bee.subprocess' local nonil = require 'without-check-nil' local client = require 'client' local platform = require 'bee.platform' local completion = require 'provider.completion' +local define = require 'proto.define' require 'provider.semantic-tokens' +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 m = {} local function testFileEvents(initer) @@ -93,6 +104,14 @@ function m.getIniter() firstTriggerCharacter = '\n', moreTriggerCharacter = nil, -- string[] }, + semanticTokensProvider = { + legend = { + tokenTypes = toArray(define.TokenTypes), + tokenModifiers = toArray(define.TokenModifiers), + }, + range = true, + full = false, + }, --documentOnTypeFormattingProvider = { -- firstTriggerCharacter = '}', --}, diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 5ac787f8..f351b793 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -131,6 +131,7 @@ m.register 'initialized'{ registrations = registrations }) end + client.setReady() library.init() workspace.init() return true @@ -823,9 +824,9 @@ m.register 'textDocument/semanticTokens/full' { } m.register 'textDocument/semanticTokens/range' { - abortByFileUpdate = true, ---@async function (params) + log.debug('textDocument/semanticTokens/range') local uri = files.getRealUri(params.textDocument.uri) workspace.awaitReady(uri) local _ <close> = progress.create(workspace.getScope(uri), lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5) 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 {} |