From 6d929d7682fd297f49773efef5be039f2831427a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 26 Mar 2019 14:12:30 +0800 Subject: =?UTF-8?q?=E5=90=88=E5=B9=B6child=E4=B8=8Einfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/method/textDocument/references.lua | 74 ++++++++++++++++----------- 1 file changed, 44 insertions(+), 30 deletions(-) (limited to 'server/src/method/textDocument/references.lua') diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua index cdc25f05..7dbd4b95 100644 --- a/server/src/method/textDocument/references.lua +++ b/server/src/method/textDocument/references.lua @@ -5,41 +5,55 @@ return function (lsp, params) local declarat = params.context.includeDeclaration local vm, lines = lsp:loadVM(uri) if not vm then - return {} + return nil end -- lua是从1开始的,因此都要+1 local position = lines:positionAsChar(params.position.line + 1, params.position.character) - local positions = core.references(vm, position, declarat) - if not positions then - return {} - end - local locations = {} - for i, position in ipairs(positions) do - local start, finish, valueUri = position[1], position[2], (position[3] or uri) - local _, valueLines = lsp:getVM(valueUri) - if valueLines then - local start_row, start_col = valueLines:rowcol(start) - local finish_row, finish_col = valueLines:rowcol(finish) - locations[i] = { - uri = valueUri, - range = { - start = { - line = start_row - 1, - character = start_col - 1, - }, - ['end'] = { - line = finish_row - 1, - -- 这里不用-1,因为前端期待的是匹配完成后的位置 - character = finish_col, - }, - } - } - end - end + return function (response) + ac.timer(0.1, 100, function (t) + if lsp:isWaitingCompile() then + return + end + t:remove() + + local positions = core.references(vm, position, declarat) + if not positions then + response(nil) + return + end - local response = locations + local locations = {} + for i, position in ipairs(positions) do + local start, finish, valueUri = position[1], position[2], (position[3] or uri) + local _, valueLines = lsp:getVM(valueUri) + if valueLines then + local start_row, start_col = valueLines:rowcol(start) + local finish_row, finish_col = valueLines:rowcol(finish) + locations[i] = { + uri = valueUri, + range = { + start = { + line = start_row - 1, + character = start_col - 1, + }, + ['end'] = { + line = finish_row - 1, + -- 这里不用-1,因为前端期待的是匹配完成后的位置 + character = finish_col, + }, + } + } + end + end - return response + if #locations == 0 then + response(nil) + return + end + + response(locations) + end) + end end -- cgit v1.2.3