diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/client.lua | 16 | ||||
-rw-r--r-- | script/provider/provider.lua | 50 |
2 files changed, 44 insertions, 22 deletions
diff --git a/script/client.lua b/script/client.lua index f0f7aa44..d9399ddd 100644 --- a/script/client.lua +++ b/script/client.lua @@ -12,6 +12,7 @@ local scope = require 'workspace.scope' local inspect = require 'inspect' local m = {} +m._eventList = {} function m.client(newClient) if newClient then @@ -389,8 +390,22 @@ function m.editText(uri, edits) }) end +---@param callback async fun() +function m.event(callback) + m._eventList[#m._eventList+1] = callback +end + +function m._callEvent(ev) + for _, callback in ipairs(m._eventList) do + await.call(function () + callback(ev) + end) + end +end + function m.setReady() m._ready = true + m._callEvent('ready') end function m.isReady() @@ -415,6 +430,7 @@ function m.init(t) lang(LOCALE or t.locale) converter.setOffsetEncoding(m.getOffsetEncoding()) hookPrint() + m._callEvent('init') end return m diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 44805130..ac952715 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -909,29 +909,35 @@ local function toArray(map) return array end -m.register 'textDocument/semanticTokens/full' { - capability = { - semanticTokensProvider = { - legend = { - tokenTypes = toArray(define.TokenTypes), - tokenModifiers = toArray(define.TokenModifiers), - }, - full = true, - }, - }, - ---@async - function (params) - log.debug('textDocument/semanticTokens/full') - local uri = files.getRealUri(params.textDocument.uri) - workspace.awaitReady(uri) - local _ <close> = progress.create(uri, lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5) - local core = require 'core.semantic-tokens' - local results = core(uri, 0, math.huge) - return { - data = results - } +client.event(function (ev) + if ev == 'init' then + if not client.isVSCode() then + m.register 'textDocument/semanticTokens/full' { + capability = { + semanticTokensProvider = { + legend = { + tokenTypes = toArray(define.TokenTypes), + tokenModifiers = toArray(define.TokenModifiers), + }, + full = true, + }, + }, + ---@async + function (params) + log.debug('textDocument/semanticTokens/full') + local uri = files.getRealUri(params.textDocument.uri) + workspace.awaitReady(uri) + local _ <close> = progress.create(uri, lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5) + local core = require 'core.semantic-tokens' + local results = core(uri, 0, math.huge) + return { + data = results + } + end + } + end end -} +end) m.register 'textDocument/semanticTokens/range' { capability = { |