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 | |
parent | b6568168f9419f8c3c14f966b4520b73a03f5bd0 (diff) | |
download | lua-language-server-6d929d7682fd297f49773efef5be039f2831427a.zip |
合并child与info
Diffstat (limited to 'server')
-rw-r--r-- | server/src/method/textDocument/references.lua | 74 | ||||
-rw-r--r-- | server/src/vm/value.lua | 21 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 1 | ||||
-rw-r--r-- | server/test/crossfile/references.lua | 51 |
4 files changed, 108 insertions, 39 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 diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index 11cb9ae1..9665a50f 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -274,15 +274,16 @@ function mt:mergeValue(value) end end value._type = self._type - --if value._child then - -- if not self._child then - -- self._child = {} - -- end - -- for k, v in pairs(value._child) do - -- self._child[k] = v - -- end - --end - --value._child = self._child + + if value._child then + if not self._child then + self._child = {} + end + for k, v in pairs(value._child) do + self._child[k] = v + end + end + value._child = self._child for srcId, info in pairs(value._info) do local src = sourceMgr.list[srcId] @@ -291,6 +292,8 @@ function mt:mergeValue(value) self._info[srcId] = info end end + value._infoCount = self._infoCount + value._info = self._info if value._meta then self._meta = value._meta diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index c519ad72..5774711c 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -1180,6 +1180,7 @@ local function compile(ast, lsp, uri) local vm = setmetatable({ funcs = {}, sources = {}, + require = {}, main = nil, env = nil, lsp = lsp, diff --git a/server/test/crossfile/references.lua b/server/test/crossfile/references.lua index abdf3a35..cc57842c 100644 --- a/server/test/crossfile/references.lua +++ b/server/test/crossfile/references.lua @@ -99,6 +99,11 @@ function TEST(data) end local vm = lsp:loadVM(mainUri) + + while lsp._needCompile[1] do + lsp:compileVM(lsp._needCompile[1]) + end + assert(vm) local result = core.references(vm, pos, true) if expect then @@ -124,3 +129,49 @@ TEST { ]], }, } + +TEST { + { + path = 'a.lua', + content = [[ + local <!f!> = require 'lib' + ]], + }, + { + path = 'lib.lua', + content = [[ + return <?function () + end?> + ]], + }, +} + +TEST { + { + path = 'a.lua', + content = [[ + <!ROOT!> = 1 + ]], + }, + { + path = 'b.lua', + content = [[ + print(<?ROOT?>) + ]], + }, +} + +TEST { + { + path = 'a.lua', + content = [[ + <?ROOT?> = 1 + ]], + }, + { + path = 'b.lua', + content = [[ + print(<!ROOT!>) + ]], + }, +} |