summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArcanox <arcanox@arcanox.me>2021-09-26 00:01:26 -0500
committerArcanox <arcanox@arcanox.me>2021-09-26 00:01:26 -0500
commit107f9a05ca4969a6f376180a03e8287240ea6d36 (patch)
treec1e89db8934256fd4676117f09afd641592b0685
parentcb60b363f68a966e033a3dcaad95a142e62749b4 (diff)
downloadlua-language-server-107f9a05ca4969a6f376180a03e8287240ea6d36.zip
Semantic highlighting methods cannot return a null response if they're canceled or the editor will clear all the tokens until the next time the request returns a full result
-rw-r--r--script/proto/proto.lua20
-rw-r--r--script/provider/provider.lua4
2 files changed, 17 insertions, 7 deletions
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 61306b9f..311b9d9b 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -10,9 +10,10 @@ local reqCounter = util.counter()
local m = {}
-m.ability = {}
-m.waiting = {}
-m.holdon = {}
+m.ability = {}
+m.waiting = {}
+m.holdon = {}
+m.errorOnCancel = {}
function m.getMethodName(proto)
if proto.method:sub(1, 2) == '$/' then
@@ -22,8 +23,11 @@ function m.getMethodName(proto)
end
end
-function m.on(method, callback)
+function m.on(method, callback, errorOnCancel)
m.ability[method] = callback
+ if errorOnCancel then
+ m.errorOnCancel[method] = true
+ end
end
function m.response(id, res)
@@ -124,6 +128,7 @@ function m.doMethod(proto)
await.setID('proto:' .. proto.id)
end
local clock = os.clock()
+ local completed = false
local ok = true
local res
-- 任务可能在执行过程中被中断,通过close来捕获
@@ -138,12 +143,17 @@ function m.doMethod(proto)
end
await.close('proto:' .. proto.id)
if ok then
- m.response(proto.id, res)
+ if completed or not m.errorOnCancel[method] then
+ m.response(proto.id, res)
+ else
+ m.responseErr(proto.id, define.ErrorCodes.RequestCancelled, res)
+ end
else
m.responseErr(proto.id, define.ErrorCodes.InternalError, res)
end
end
ok, res = xpcall(abil, log.error, proto.params)
+ completed = true
end)
end
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 9803801b..05202c01 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -692,7 +692,7 @@ proto.on('textDocument/semanticTokens/full', function (params)
return {
data = results
}
-end)
+end, true)
proto.on('textDocument/semanticTokens/range', function (params)
local uri = params.textDocument.uri
@@ -707,7 +707,7 @@ proto.on('textDocument/semanticTokens/range', function (params)
return {
data = results
}
-end)
+end, true)
proto.on('textDocument/foldingRange', function (params)
local core = require 'core.folding'