summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/hover/label.lua2
-rw-r--r--script-beta/core/hover/table.lua19
-rw-r--r--script-beta/parser/guide.lua30
-rw-r--r--test-beta/hover/init.lua11
4 files changed, 53 insertions, 9 deletions
diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua
index dcfc21c3..5798317f 100644
--- a/script-beta/core/hover/label.lua
+++ b/script-beta/core/hover/label.lua
@@ -95,7 +95,7 @@ local function asString(source)
return ''
end
local len = #str
- local charLen = utf8.len(str, 1, -1, true)
+ local charLen = util.utf8Len(str, 1, -1)
-- TODO 翻译
if len == charLen then
return ('%d 个字节'):format(len)
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua
index 17316367..7b53979a 100644
--- a/script-beta/core/hover/table.lua
+++ b/script-beta/core/hover/table.lua
@@ -111,6 +111,23 @@ local function mergeLiteral(literals)
return table.concat(results, '|')
end
+local function mergeTypes(types)
+ local results = {}
+ local mark = {
+ -- 讲道理table的keyvalue不会是nil
+ ['nil'] = true,
+ }
+ for _, tv in ipairs(types) do
+ for tp in tv:gmatch '[^|]+' do
+ if not mark[tp] then
+ mark[tp] = true
+ results[#results+1] = tp
+ end
+ end
+ end
+ return guide.mergeTypes(results)
+end
+
local function clearClasses(classes)
local knownClasses = {
['any'] = true,
@@ -168,7 +185,7 @@ return function (source)
for key, class in pairs(classes) do
literals[key] = mergeLiteral(literals[key])
- classes[key] = guide.mergeTypes(class)
+ classes[key] = mergeTypes(class)
end
if not next(classes) then
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index b9de7363..e377b6c8 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -2755,10 +2755,19 @@ local function mergeLibraryFunctionReturns(status, source, index)
end
local rtn = returns[index]
if rtn then
- status.results[#status.results+1] = {
- type = rtn.type,
- source = rtn,
- }
+ if type(rtn.type) == 'table' then
+ for _, tp in ipairs(rtn.type) do
+ status.results[#status.results+1] = {
+ type = tp,
+ source = rtn,
+ }
+ end
+ else
+ status.results[#status.results+1] = {
+ type = rtn.type,
+ source = rtn,
+ }
+ end
end
end
@@ -2806,6 +2815,10 @@ function m.inferByCallReturnAndIndex(status, call, index)
end
function m.inferByCallReturn(status, source)
+ if source.type == 'call' then
+ m.inferByCallReturnAndIndex(status, source, 1)
+ return
+ end
if source.type ~= 'select' then
if source.value and source.value.type == 'select' then
source = source.value
@@ -2877,9 +2890,12 @@ function m.searchInfer(status, obj)
while obj.type == 'paren' do
obj = obj.exp
end
- obj = m.getObjectValue(obj) or obj
- if obj.type == 'select' then
- obj = obj.parent
+ while true do
+ local value = m.getObjectValue(obj)
+ if not value or value == obj then
+ break
+ end
+ obj = value
end
local cache, makeCache
diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua
index 8ec6cb9c..7f20666a 100644
--- a/test-beta/hover/init.lua
+++ b/test-beta/hover/init.lua
@@ -755,6 +755,17 @@ field t.v: {
}
]]
+TEST [[
+local <?t?> = {
+ f = io.open(),
+}
+]]
+[[
+local t: {
+ f: FILE*,
+}
+]]
+
--TEST[[
-----@class Class
--local <?x?> = class()