diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-18 16:23:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-18 16:23:16 +0800 |
commit | 357e62b68d67c4218d95f6bee937e6d5e206d752 (patch) | |
tree | d53917e3e64b7f252fcb54116c9e5609fe380805 /server/src/method | |
parent | de4cec30d4befc0de4bd264c16c52c1a575cd5d3 (diff) | |
download | lua-language-server-357e62b68d67c4218d95f6bee937e6d5e206d752.zip |
重构文件符号
Diffstat (limited to 'server/src/method')
-rw-r--r-- | server/src/method/textDocument/documentSymbol.lua | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/server/src/method/textDocument/documentSymbol.lua b/server/src/method/textDocument/documentSymbol.lua index 2f9a6b8a..9b21131d 100644 --- a/server/src/method/textDocument/documentSymbol.lua +++ b/server/src/method/textDocument/documentSymbol.lua @@ -1,6 +1,8 @@ local core = require 'core' local lang = require 'language' +local timerCache = {} + local function posToRange(lines, start, finish) local start_row, start_col = lines:rowcol(start) local finish_row, finish_col = lines:rowcol(finish) @@ -32,19 +34,29 @@ end return function (lsp, params) local uri = params.textDocument.uri + + if timerCache[uri] then + timerCache[uri]:remove() + timerCache[uri] = nil + end + local vm, lines = lsp:loadVM(uri) if not vm then return nil end - local symbols = core.documentSymbol(vm) - if not symbols then - return nil - end + return function (response) + timerCache[uri] = ac.wait(0.5, function () + local symbols = core.documentSymbol(vm) + if not symbols then + return nil + end - for _, symbol in ipairs(symbols) do - convertRange(lines, symbol) - end + for _, symbol in ipairs(symbols) do + convertRange(lines, symbol) + end - return symbols + response(symbols) + end) + end end |