diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-23 16:52:14 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-23 16:52:14 +0800 |
commit | 294d884d97e5b04fbc5c7ff3487f2fc4e5832f4f (patch) | |
tree | 1870270e615e51ed976d3ef4b91cf43c34071440 /script-beta | |
parent | 57bfae9cd5a176c68f5874f8dad47db4f9e29174 (diff) | |
download | lua-language-server-294d884d97e5b04fbc5c7ff3487f2fc4e5832f4f.zip |
修正一些bug
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/hover/label.lua | 2 | ||||
-rw-r--r-- | script-beta/core/hover/table.lua | 19 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 30 |
3 files changed, 42 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 |