summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-08-13 18:49:03 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-08-13 18:49:03 +0800
commit1302aa460db48fca165ed4b2603e7ba085cf77ad (patch)
treef0a9dbfee06fd9eec79a9b453889e963c28b0f31
parente2247e00da2e61700e9a981ad1d5bfe70d0cbfa0 (diff)
downloadlua-language-server-1302aa460db48fca165ed4b2603e7ba085cf77ad.zip
支持 return {}
-rw-r--r--script-beta/parser/guide.lua43
-rw-r--r--test-beta/crossfile/references.lua4
2 files changed, 34 insertions, 13 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 533d2fed..8f2fe1bf 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -868,6 +868,7 @@ local function buildSimpleList(obj, max)
list[i] = cur
break
elseif cur.type == 'function'
+ or cur.type == 'return'
or cur.type == 'main' then
break
else
@@ -1312,17 +1313,6 @@ function m.checkSameSimpleAsTableField(status, ref, start, queue)
force = true,
}
end
- -- 检查所属的table被return出去
- --local tbl = parent.parent
- --local newStatus = m.status(status)
- --m.searchRefsAsFunctionReturn(newStatus, tbl, 'ref')
- --for _, res in ipairs(newStatus.results) do
- -- queue[#queue+1] = {
- -- obj = res,
- -- start = start-1,
- -- force = true,
- -- }
- --end
end
function m.checkSameSimpleAsReturn(status, ref, start, queue)
@@ -1340,6 +1330,33 @@ function m.checkSameSimpleAsReturn(status, ref, start, queue)
end
end
+function m.checkSameSimpleAsReturnTableField(status, ref, start, queue)
+ if ref.type ~= 'tablefield' then
+ return
+ end
+ local tbl = ref.parent
+ if tbl.type ~= 'table' then
+ return
+ end
+ local rtn = tbl.parent
+ if rtn.type ~= 'return' then
+ return
+ end
+ local newStatus = m.status(status)
+ m.searchRefsAsFunctionReturn(newStatus, tbl, 'ref')
+ for _, res in ipairs(newStatus.results) do
+ queue[#queue+1] = {
+ obj = res,
+ start = start-1,
+ force = true,
+ }
+ end
+end
+
+function m.checkSameSimpleAsSetValue(status, ref, start, queue)
+
+end
+
function m.checkSameSimple(status, simple, data, mode, results, queue)
local ref = data.obj
local start = data.start
@@ -1361,6 +1378,10 @@ function m.checkSameSimple(status, simple, data, mode, results, queue)
m.checkSameSimpleAsTableField(status, ref, i, queue)
-- 检查形如 return m 的情况
m.checkSameSimpleAsReturn(status, ref, i, queue)
+ -- 检查形如 return { f = 1 } 的情况
+ m.checkSameSimpleAsReturnTableField(status, ref, i, queue)
+ -- 检查形如 a = f 的情况
+ m.checkSameSimpleAsSetValue(status, ref, i, queue)
end
if i == #simple then
break
diff --git a/test-beta/crossfile/references.lua b/test-beta/crossfile/references.lua
index 07166c3d..4fae9cb7 100644
--- a/test-beta/crossfile/references.lua
+++ b/test-beta/crossfile/references.lua
@@ -273,7 +273,7 @@ TEST {
end
return {
- f = <!f!>,
+ <!f!> = <!f!>,
}
]]
},
@@ -281,7 +281,7 @@ TEST {
path = 'b.lua',
content = [[
local t = require 'a'
- local <!f!> = t.f
+ local <!f!> = t.<!f!>
<!f!>()