diff options
author | unknown <sumnekosun@intranet.123u.com> | 2019-04-01 18:55:51 +0800 |
---|---|---|
committer | unknown <sumnekosun@intranet.123u.com> | 2019-04-01 18:55:51 +0800 |
commit | c0708092a2c256d61c2cdbc3217a588bb86757ca (patch) | |
tree | bcdf65d29ec7f3b950090d2f0102d22eefbac4e1 /server/src/method/textDocument/references.lua | |
parent | a66a4c54ef9421f0ba5683cd727a40197078d724 (diff) | |
download | lua-language-server-c0708092a2c256d61c2cdbc3217a588bb86757ca.zip |
定义与引用会进行更多的尝试
Diffstat (limited to 'server/src/method/textDocument/references.lua')
-rw-r--r-- | server/src/method/textDocument/references.lua | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua index f21625c8..7213e590 100644 --- a/server/src/method/textDocument/references.lua +++ b/server/src/method/textDocument/references.lua @@ -1,6 +1,45 @@ local core = require 'core' local LastTask +local function findReferences(lsp, uri, position, declarat) + local vm = lsp:getVM(uri) + + local positions = core.references(vm, position, declarat) + if not positions then + return nil + 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 + + if #locations == 0 then + return nil + end + + return locations +end + return function (lsp, params) local uri = params.textDocument.uri local declarat = params.context.includeDeclaration @@ -19,49 +58,15 @@ return function (lsp, params) return function (response) LastTask = ac.loop(0.1, function (t) + local positions = findReferences(lsp, uri, position, declarat) + if positions then + response(positions) + end if lsp:isWaitingCompile() then return end t:remove() LastTask = nil - vm, lines = lsp:getVM(uri) - - local positions = core.references(vm, position, declarat) - if not positions then - response(nil) - 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 - - if #locations == 0 then - response(nil) - return - end - - response(locations) end) end end |