diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-26 14:12:30 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-26 14:12:30 +0800 |
commit | 6d929d7682fd297f49773efef5be039f2831427a (patch) | |
tree | 064eb34b4181ff39be81a83172619275798c4068 /server/src/method/textDocument/references.lua | |
parent | b6568168f9419f8c3c14f966b4520b73a03f5bd0 (diff) | |
download | lua-language-server-6d929d7682fd297f49773efef5be039f2831427a.zip |
合并child与info
Diffstat (limited to 'server/src/method/textDocument/references.lua')
-rw-r--r-- | server/src/method/textDocument/references.lua | 74 |
1 files changed, 44 insertions, 30 deletions
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 |