summaryrefslogtreecommitdiff
path: root/server-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-10-28 16:36:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-10-28 16:36:50 +0800
commit8c3389778db135c4fef78db2ba5cb50d4cb5b448 (patch)
tree2c729526aad0f562edfe6794dba81f1136e5b46d /server-beta
parent13a9025d969bc416cd4c1057865448812f00e00b (diff)
downloadlua-language-server-8c3389778db135c4fef78db2ba5cb50d4cb5b448.zip
支持函数返回值
Diffstat (limited to 'server-beta')
-rw-r--r--server-beta/src/core/definition.lua3
-rw-r--r--server-beta/src/parser/compile.lua15
-rw-r--r--server-beta/src/searcher/eachRef.lua13
3 files changed, 28 insertions, 3 deletions
diff --git a/server-beta/src/core/definition.lua b/server-beta/src/core/definition.lua
index 305bb868..8a808e23 100644
--- a/server-beta/src/core/definition.lua
+++ b/server-beta/src/core/definition.lua
@@ -5,7 +5,8 @@ local files = require 'files'
local function findDef(searcher, source, callback)
searcher:eachRef(source, function (info)
if info.mode == 'declare'
- or info.mode == 'set' then
+ or info.mode == 'set'
+ or info.mode == 'return' then
local src = info.source
local uri = info.uri
if src.type == 'setfield'
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua
index 2bcb7e46..51803753 100644
--- a/server-beta/src/parser/compile.lua
+++ b/server-beta/src/parser/compile.lua
@@ -194,6 +194,13 @@ local vmMap = {
finish = obj.finish,
}
end
+ local func = guide.getParentFunction(obj)
+ if func then
+ if not func.returns then
+ func.returns = {}
+ end
+ func.returns[#func.returns+1] = obj
+ end
end,
['label'] = function (obj)
local block = guide.getBlock(obj)
@@ -281,7 +288,13 @@ local vmMap = {
Block = lastBlock
end,
['break'] = function (obj)
- if not guide.getBreakBlock(obj) then
+ local block = guide.getBreakBlock(obj)
+ if block then
+ if not block.breaks then
+ block.breaks = {}
+ end
+ block.breaks[#block.breaks+1] = obj
+ else
pushError {
type = 'BREAK_OUTSIDE',
start = obj.start,
diff --git a/server-beta/src/searcher/eachRef.lua b/server-beta/src/searcher/eachRef.lua
index 93a05079..ab3de029 100644
--- a/server-beta/src/searcher/eachRef.lua
+++ b/server-beta/src/searcher/eachRef.lua
@@ -4,8 +4,19 @@ local function ofCall(searcher, func, index, callback)
searcher:eachRef(func, function (info)
local src = info.source
local funcDef = src.value
- if funcDef and funcDef.type == 'function' then
+ if funcDef and funcDef.returns then
-- 搜索函数第 index 个返回值
+ for _, rtn in ipairs(funcDef.returns) do
+ local val = rtn[index]
+ if val then
+ callback {
+ searcher = info.searcher,
+ source = val,
+ mode = 'return',
+ }
+ info.searcher:eachRef(val, callback)
+ end
+ end
end
end)
end