diff options
author | Arcanox <arcanox@arcanox.me> | 2021-09-26 14:50:36 -0500 |
---|---|---|
committer | Arcanox <arcanox@arcanox.me> | 2021-09-26 14:50:43 -0500 |
commit | 17d2ae286db1b8c8484e5db5bc3c13a25b2426bb (patch) | |
tree | 6ccbd55ec6a472e829c61b217339ec695fb3c100 | |
parent | b8feb6626cd4caefba683eaf4f99ca0600aab950 (diff) | |
download | lua-language-server-17d2ae286db1b8c8484e5db5bc3c13a25b2426bb.zip |
Change the way canceled semanticToken requests are handled according to @sumneko's suggestion
-rw-r--r-- | script/proto/define.lua | 1 | ||||
-rw-r--r-- | script/proto/proto.lua | 29 | ||||
-rw-r--r-- | script/provider/provider.lua | 16 |
3 files changed, 26 insertions, 20 deletions
diff --git a/script/proto/define.lua b/script/proto/define.lua index 731c5cc6..22e4cb04 100644 --- a/script/proto/define.lua +++ b/script/proto/define.lua @@ -174,6 +174,7 @@ m.ErrorCodes = { -- Defined by the protocol. RequestCancelled = -32800, + ContentModified = -32801, } m.SymbolKind = { diff --git a/script/proto/proto.lua b/script/proto/proto.lua index 311b9d9b..29b632fd 100644 --- a/script/proto/proto.lua +++ b/script/proto/proto.lua @@ -10,10 +10,10 @@ local reqCounter = util.counter() local m = {} -m.ability = {} -m.waiting = {} -m.holdon = {} -m.errorOnCancel = {} +m.ability = {} +m.waiting = {} +m.holdon = {} +m.closeReasons = {} function m.getMethodName(proto) if proto.method:sub(1, 2) == '$/' then @@ -23,11 +23,12 @@ function m.getMethodName(proto) end end -function m.on(method, callback, errorOnCancel) +function m.on(method, callback) m.ability[method] = callback - if errorOnCancel then - m.errorOnCancel[method] = true - end +end + +function m.close(id, reason) + m.closeReasons[id] = reason end function m.response(id, res) @@ -128,7 +129,6 @@ function m.doMethod(proto) await.setID('proto:' .. proto.id) end local clock = os.clock() - local completed = false local ok = true local res -- 任务可能在执行过程中被中断,通过close来捕获 @@ -143,17 +143,18 @@ function m.doMethod(proto) end await.close('proto:' .. proto.id) if ok then - if completed or not m.errorOnCancel[method] then - m.response(proto.id, res) + if m.closeReasons[proto.id] then + -- return an error with the reason it was cancelled + m.responseErr(proto.id, m.closeReasons[proto.id], res) + m.closeReasons[proto.id] = nil else - m.responseErr(proto.id, define.ErrorCodes.RequestCancelled, res) + m.response(proto.id, res) end else m.responseErr(proto.id, define.ErrorCodes.InternalError, res) end end - ok, res = xpcall(abil, log.error, proto.params) - completed = true + ok, res = xpcall(abil, log.error, proto.params, proto.id) end) end diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 7a5ce558..632dae6f 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -680,11 +680,13 @@ proto.on('workspace/symbol', function (params) end) -proto.on('textDocument/semanticTokens/full', function (params) +proto.on('textDocument/semanticTokens/full', function (params, id) local uri = params.textDocument.uri await.close('textDocument/semanticTokens/full') await.setID('textDocument/semanticTokens/full') - await.setID('update:' .. uri) + await.setID('update:' .. uri, function() + proto.close(id, define.ErrorCodes.ContentModified) + end) workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5) local core = require 'core.semantic-tokens' @@ -692,13 +694,15 @@ proto.on('textDocument/semanticTokens/full', function (params) return { data = results } -end, true) +end) -proto.on('textDocument/semanticTokens/range', function (params) +proto.on('textDocument/semanticTokens/range', function (params, id) local uri = params.textDocument.uri await.close('textDocument/semanticTokens/range') await.setID('textDocument/semanticTokens/range') - await.setID('update:' .. uri) + await.setID('update:' .. uri, function() + proto.close(id, define.ErrorCodes.ContentModified) + end) workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5) local core = require 'core.semantic-tokens' @@ -715,7 +719,7 @@ proto.on('textDocument/semanticTokens/range', function (params) return { data = results } -end, true) +end) proto.on('textDocument/foldingRange', function (params) local core = require 'core.folding' |