diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-22 15:02:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-22 15:02:25 +0800 |
commit | fbd1394858972c92439d927fa30dabcfd55dc705 (patch) | |
tree | 38b6b0aaa4b7760f68bd1d10a1c0d02f23a42b10 | |
parent | dc7275ac9b56f26923c80c1e8bbce185c2d147a4 (diff) | |
download | lua-language-server-fbd1394858972c92439d927fa30dabcfd55dc705.zip |
修正一个引用计算的bug
-rw-r--r-- | server-beta/src/vm/eachRef.lua | 46 | ||||
-rw-r--r-- | server-beta/test.lua | 2 | ||||
-rw-r--r-- | server-beta/test/crossfile/references.lua | 18 |
3 files changed, 40 insertions, 26 deletions
diff --git a/server-beta/src/vm/eachRef.lua b/server-beta/src/vm/eachRef.lua index 465b1267..cfb2bef8 100644 --- a/server-beta/src/vm/eachRef.lua +++ b/server-beta/src/vm/eachRef.lua @@ -6,11 +6,8 @@ local function ofCall(func, index, callback) vm.eachRef(func, function (info) local src = info.source local returns - if info.mode == 'main' then + if src.type == 'main' or src.type == 'function' then returns = src.returns - else - local funcDef = src.value - returns = funcDef and funcDef.returns end if returns then -- 搜索函数第 index 个返回值 @@ -52,7 +49,26 @@ local function ofReturn(rtn, index, callback) end -- 搜索函数调用的第 index 个接收值 if func.type == 'main' then - vm.eachRef(func, callback) + local myUri = func.uri + local uris = files.findLinkTo(myUri) + if not uris then + return + end + for _, uri in ipairs(uris) do + local ast = files.getAst(uri) + if ast then + local links = vm.getLinks(ast.ast) + if links then + for linkUri, calls in pairs(links) do + if files.eq(linkUri, myUri) then + for i = 1, #calls do + ofCallSelect(calls[i], 1, callback) + end + end + end + end + end + end else vm.eachRef(func, function (info) local source = info.source @@ -390,26 +406,6 @@ local function ofMain(source, callback) source = source, mode = 'main', } - local myUri = source.uri - local uris = files.findLinkTo(myUri) - if not uris then - return - end - for _, uri in ipairs(uris) do - local ast = files.getAst(uri) - if ast then - local links = vm.getLinks(ast.ast) - if links then - for linkUri, calls in pairs(links) do - if files.eq(linkUri, myUri) then - for i = 1, #calls do - ofCallSelect(calls[i], 1, callback) - end - end - end - end - end - end end local function eachRef(source, callback) diff --git a/server-beta/test.lua b/server-beta/test.lua index dc1023d6..dffae940 100644 --- a/server-beta/test.lua +++ b/server-beta/test.lua @@ -42,7 +42,7 @@ local function main() test 'highlight' test 'rename' test 'type_inference' - test 'hover' + --test 'hover' --test 'completion' --test 'signature' --test 'document_symbol' diff --git a/server-beta/test/crossfile/references.lua b/server-beta/test/crossfile/references.lua index 0b44b3f4..a1747dac 100644 --- a/server-beta/test/crossfile/references.lua +++ b/server-beta/test/crossfile/references.lua @@ -229,3 +229,21 @@ TEST { ]], }, } + +TEST { + { + path = 'a.lua', + content = [[ + local f = require 'lib' + local <?o?> = f() + ]], + }, + { + path = 'lib.lua', + content = [[ + return function () + return <!{}!> + end + ]], + }, +} |