summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-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'