summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-27 15:43:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-27 15:43:18 +0800
commitbddbb7095d2d4977dcf3259489a188eba9e2d321 (patch)
tree2f0d4bc59375a6a21cd744cae94ef65edcd5fd08
parenteb939ecccd11c6c628fc478f6e4550ab9c66a95c (diff)
downloadlua-language-server-bddbb7095d2d4977dcf3259489a188eba9e2d321.zip
`$/cancelRequest` returns code `RequestCancelled`
-rw-r--r--script/await.lua4
-rw-r--r--script/proto/define.lua1
-rw-r--r--script/proto/proto.lua15
-rw-r--r--script/provider/provider.lua4
4 files changed, 16 insertions, 8 deletions
diff --git a/script/await.lua b/script/await.lua
index bfa8257d..e92af272 100644
--- a/script/await.lua
+++ b/script/await.lua
@@ -21,7 +21,7 @@ local function setID(id, co, callback)
if not m.idMap[id] then
m.idMap[id] = setmetatable({}, wkmt)
end
- m.idMap[id][co] = callback
+ m.idMap[id][co] = callback or true
end
--- 设置错误处理器
@@ -94,7 +94,7 @@ function m.close(id)
for co, callback in pairs(map) do
if coroutine.status(co) == 'suspended' then
map[co] = nil
- if callback then
+ if type(callback) == 'function' then
xpcall(callback, log.error)
end
coroutine.close(co)
diff --git a/script/proto/define.lua b/script/proto/define.lua
index 699bcd15..8ee63821 100644
--- a/script/proto/define.lua
+++ b/script/proto/define.lua
@@ -173,6 +173,7 @@ m.ErrorCodes = {
UnknownErrorCode = -32001,
-- Defined by the protocol.
+ ContentModified = -32801,
RequestCancelled = -32800,
}
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 61306b9f..7767ec0a 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -116,7 +116,7 @@ function m.doMethod(proto)
return
end
if proto.id then
- m.holdon[proto.id] = method
+ m.holdon[proto.id] = proto
end
await.call(function ()
--log.debug('Start method:', method)
@@ -124,7 +124,7 @@ function m.doMethod(proto)
await.setID('proto:' .. proto.id)
end
local clock = os.clock()
- local ok = true
+ local ok = false
local res
-- 任务可能在执行过程中被中断,通过close来捕获
local response <close> = function ()
@@ -140,13 +140,22 @@ function m.doMethod(proto)
if ok then
m.response(proto.id, res)
else
- m.responseErr(proto.id, define.ErrorCodes.InternalError, res)
+ m.responseErr(proto.id, proto._closeReason or define.ErrorCodes.InternalError, res)
end
end
ok, res = xpcall(abil, log.error, proto.params)
end)
end
+function m.close(id, reason)
+ local proto = m.holdon[id]
+ if not proto then
+ return
+ end
+ proto._closeReason = reason
+ await.close('proto:' .. id)
+end
+
function m.doResponse(proto)
local id = proto.id
local resume = m.waiting[id]
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 070652ef..ff9296d6 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -684,7 +684,6 @@ proto.on('textDocument/semanticTokens/full', function (params)
local uri = params.textDocument.uri
await.close('textDocument/semanticTokens/full')
await.setID('textDocument/semanticTokens/full')
- await.setID('update:' .. uri)
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5)
local core = require 'core.semantic-tokens'
@@ -702,7 +701,6 @@ proto.on('textDocument/semanticTokens/range', function (params)
local uri = params.textDocument.uri
await.close('textDocument/semanticTokens/range')
await.setID('textDocument/semanticTokens/range')
- await.setID('update:' .. uri)
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5)
local core = require 'core.semantic-tokens'
@@ -806,7 +804,7 @@ proto.on('textDocument/onTypeFormatting', function (params)
end)
proto.on('$/cancelRequest', function (params)
- await.close('proto:' .. params.id)
+ proto.close(params.id, define.ErrorCodes.RequestCancelled)
end)
proto.on('$/requestHint', function (params)