diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-26 13:45:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-26 13:45:42 +0800 |
commit | b6568168f9419f8c3c14f966b4520b73a03f5bd0 (patch) | |
tree | 2870d6456c9b39fa926623ecfe811375a3c18c86 /server | |
parent | f7291b57469e7b0a96f2f0fd13fd7d5dab01154c (diff) | |
download | lua-language-server-b6568168f9419f8c3c14f966b4520b73a03f5bd0.zip |
修正查找引用的一个bug
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/references.lua | 2 | ||||
-rw-r--r-- | server/test/crossfile/init.lua | 1 | ||||
-rw-r--r-- | server/test/crossfile/references.lua | 126 |
3 files changed, 128 insertions, 1 deletions
diff --git a/server/src/core/references.lua b/server/src/core/references.lua index 4bd26b07..10d8b2df 100644 --- a/server/src/core/references.lua +++ b/server/src/core/references.lua @@ -18,7 +18,7 @@ local function parseResult(vm, source, declarat, callback) end end) loc:getValue():eachInfo(function (info, src) - if (declarat and (info.type == 'set' or info.type == 'local')) or info.type == 'get' then + if (declarat and (info.type == 'set' or info.type == 'local' or info.type == 'return')) or info.type == 'get' then callback(src) end end) diff --git a/server/test/crossfile/init.lua b/server/test/crossfile/init.lua index 30bf23df..96462fa5 100644 --- a/server/test/crossfile/init.lua +++ b/server/test/crossfile/init.lua @@ -2,3 +2,4 @@ require 'crossfile.definition' require 'crossfile.hover' require 'crossfile.completion' require 'crossfile.document_symbol' +require 'crossfile.references' diff --git a/server/test/crossfile/references.lua b/server/test/crossfile/references.lua new file mode 100644 index 00000000..abdf3a35 --- /dev/null +++ b/server/test/crossfile/references.lua @@ -0,0 +1,126 @@ +local service = require 'service' +local workspace = require 'workspace' +local fs = require 'bee.filesystem' +local core = require 'core' + +rawset(_G, 'TEST', true) + +local EXISTS = {} + +local function eq(a, b) + if a == EXISTS and b ~= nil then + return true + end + local tp1, tp2 = type(a), type(b) + if tp1 ~= tp2 then + return false + end + if tp1 == 'table' then + local mark = {} + for k in pairs(a) do + if not eq(a[k], b[k]) then + return false + end + mark[k] = true + end + for k in pairs(b) do + if not mark[k] then + return false + end + end + return true + end + return a == b +end + +local function catch_target(script) + local list = {} + local cur = 1 + while true do + local start, finish = script:find('<[!?].-[!?]>', cur) + if not start then + break + end + list[#list+1] = { start + 2, finish - 2 } + cur = finish + 1 + end + return list +end + +local function founded(targets, results) + if #targets ~= #results then + return false + end + for _, target in ipairs(targets) do + for _, result in ipairs(results) do + if target[1] == result[1] and target[2] == result[2] then + goto NEXT + end + end + do return false end + ::NEXT:: + end + return true +end + +function TEST(data) + local lsp = service() + local ws = workspace(lsp, 'test') + lsp.workspace = ws + ws.root = ROOT + + local mainUri + local pos + local expect = {} + for _, info in ipairs(data) do + local uri = ws:uriEncode(fs.path(info.path)) + local script = info.content + local list = catch_target(script) + for _, location in ipairs(list) do + expect[#expect+1] = { + location[1], + location[2], + uri, + } + end + local start = script:find('<?', 1, true) + local finish = script:find('?>', 1, true) + if start then + mainUri = uri + pos = (start + finish) // 2 + 1 + end + local newScript = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') + lsp:saveText(uri, 1, newScript) + ws:addFile(uri) + end + + while lsp._needCompile[1] do + lsp:compileVM(lsp._needCompile[1]) + end + + local vm = lsp:loadVM(mainUri) + assert(vm) + local result = core.references(vm, pos, true) + if expect then + assert(result) + assert(founded(expect, result)) + else + assert(result == nil) + end +end + +TEST { + { + path = 'lib.lua', + content = [[ + return <!function () + end!> + ]], + }, + { + path = 'a.lua', + content = [[ + local <?f?> = require 'lib' + ]], + }, +} |