summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-18 17:54:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-18 17:54:30 +0800
commite8158fd4de7e076ef019493afa33b9c2820de75a (patch)
treeb48cf97556b4bcafdae14119680220be704f94c7
parent5da8740d528b6f20e969a5b2f5fbd7679e3d267d (diff)
downloadlua-language-server-e8158fd4de7e076ef019493afa33b9c2820de75a.zip
降低文件符号的优先度
-rw-r--r--server/src/core/document_symbol.lua6
-rw-r--r--server/src/method/textDocument/documentSymbol.lua25
-rw-r--r--server/src/vm/vm.lua21
3 files changed, 39 insertions, 13 deletions
diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua
index ac81277c..39257ba3 100644
--- a/server/src/core/document_symbol.lua
+++ b/server/src/core/document_symbol.lua
@@ -228,6 +228,9 @@ local function packChild(symbols, finish, kind)
t = {}
end
t[#t+1] = symbol
+ if coroutine.isyieldable() then
+ coroutine.yield()
+ end
end
return t
end
@@ -249,6 +252,9 @@ return function (vm)
buildSource(vm, source, used, function (data)
symbols[#symbols+1] = data
end)
+ if coroutine.isyieldable() then
+ coroutine.yield()
+ end
end
local packedSymbols = packSymbols(symbols)
diff --git a/server/src/method/textDocument/documentSymbol.lua b/server/src/method/textDocument/documentSymbol.lua
index 9b21131d..4e7c3808 100644
--- a/server/src/method/textDocument/documentSymbol.lua
+++ b/server/src/method/textDocument/documentSymbol.lua
@@ -46,17 +46,30 @@ return function (lsp, params)
end
return function (response)
- timerCache[uri] = ac.wait(0.5, function ()
- local symbols = core.documentSymbol(vm)
- if not symbols then
- return nil
+ local co = coroutine.create(function ()
+ return core.documentSymbol(vm)
+ end)
+ timerCache[uri] = ac.loop(0.001, function (t)
+ local suc, res = coroutine.resume(co)
+ if not suc then
+ t:remove()
+ error(res)
+ return
+ end
+ if coroutine.status(co) == 'suspended' then
+ return
+ end
+
+ t:remove()
+ if not res then
+ response(nil)
end
- for _, symbol in ipairs(symbols) do
+ for _, symbol in ipairs(res) do
convertRange(lines, symbol)
end
- response(symbols)
+ response(res)
end)
end
end
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 9fcd57ae..0c952765 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -668,6 +668,13 @@ function mt:getUnary(exp)
end
function mt:getExp(exp)
+ if coroutine.isyieldable() then
+ if self.lsp:isNeedCompile(self.uri) then
+ coroutine.yield()
+ else
+ coroutine.yield('stop')
+ end
+ end
self:instantSource(exp)
local tp = exp.type
if tp == 'nil' then
@@ -978,6 +985,13 @@ function mt:doAction(action)
-- Skip
return
end
+ if coroutine.isyieldable() then
+ if self.lsp:isNeedCompile(self.uri) then
+ coroutine.yield()
+ else
+ coroutine.yield('stop')
+ end
+ end
local tp = action.type
if tp == 'do' then
self:doDo(action)
@@ -1017,13 +1031,6 @@ end
function mt:doActions(actions)
for _, action in ipairs(actions) do
self:doAction(action)
- if coroutine.isyieldable() then
- if self.lsp:isNeedCompile(self.uri) then
- coroutine.yield()
- else
- coroutine.yield('stop')
- end
- end
end
end