diff options
-rw-r--r-- | script-beta/core/hover/label.lua | 9 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 49 | ||||
-rw-r--r-- | test-beta/definition/luadoc.lua | 6 | ||||
-rw-r--r-- | test-beta/hover/init.lua | 64 |
4 files changed, 68 insertions, 60 deletions
diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua index be73eec2..6ce8ef8e 100644 --- a/script-beta/core/hover/label.lua +++ b/script-beta/core/hover/label.lua @@ -36,13 +36,16 @@ local function asValue(source, title) local class = vm.getClass(source, 'deep') local literal = vm.getInferLiteral(source, 'deep') local cont - if vm.hasInferType(source, 'table', 'deep') then - cont = buildTable(source) + if type ~= 'string' then + if #vm.getFields(source, 'deep') > 0 + or vm.hasInferType(source, 'table', 'deep') then + cont = buildTable(source) + end end local pack = {} pack[#pack+1] = title pack[#pack+1] = name .. ':' - if cont then + if cont and type == 'table' then type = nil end if class then diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 7974f325..77d43e55 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -698,6 +698,8 @@ function m.getName(obj) return obj.class[1] elseif tp == 'doc.alias' then return obj.alias[1] + elseif tp == 'doc.field' then + return obj.field[1] end return m.getNameOfLiteral(obj) end @@ -765,6 +767,12 @@ function m.getKeyName(obj) elseif tp == 'field' or tp == 'method' then return 's|' .. obj[1] + elseif tp == 'doc.class' then + return 's|' .. obj.class[1] + elseif tp == 'doc.alias' then + return 's|' .. obj.alias[1] + elseif tp == 'doc.field' then + return 's|' .. obj.field[1] end return m.getKeyNameOfLiteral(obj) end @@ -1313,8 +1321,10 @@ function m.searchFields(status, obj, key, interface, deep) return results elseif obj.type == 'library' then local results = {} - for i = 1, #obj.fields do - results[i] = obj.fields[i] + if obj.fields then + for i = 1, #obj.fields do + results[i] = obj.fields[i] + end end return results else @@ -1464,6 +1474,8 @@ function m.checkSameSimpleByBindDocs(status, obj, start, queue, mode) end elseif doc.type == 'doc.overload' then results[#results+1] = doc.overload + elseif doc.type == 'doc.field' then + results[#results+1] = doc end end local mark = {} @@ -1481,11 +1493,18 @@ function m.checkSameSimpleByBindDocs(status, obj, start, queue, mode) end end end - queue[#queue+1] = { - obj = res, - start = start, - force = true, - } + if res.type == 'doc.type.function' then + queue[#queue+1] = { + obj = res, + start = start, + force = true, + } + elseif res.type == 'doc.field' then + queue[#queue+1] = { + obj = res, + start = start + 1, + } + end end for _, res in ipairs(newStatus.results) do queue[#queue+1] = { @@ -1877,7 +1896,8 @@ function m.pushResult(status, mode, ref, simple) results[#results+1] = ref elseif ref.type == 'library' then results[#results+1] = ref - elseif ref.type == 'doc.type.function' then + elseif ref.type == 'doc.type.function' + or ref.type == 'doc.field' then results[#results+1] = ref end if ref.parent and ref.parent.type == 'return' then @@ -1914,7 +1934,8 @@ function m.pushResult(status, mode, ref, simple) end elseif ref.type == 'library' then results[#results+1] = ref - elseif ref.type == 'doc.type.function' then + elseif ref.type == 'doc.type.function' + or ref.type == 'doc.field' then results[#results+1] = ref end if ref.parent and ref.parent.type == 'return' then @@ -1946,7 +1967,8 @@ function m.pushResult(status, mode, ref, simple) end elseif ref.type == 'library' then results[#results+1] = ref - elseif ref.type == 'doc.type.function' then + elseif ref.type == 'doc.type.function' + or ref.type == 'doc.field' then results[#results+1] = ref end end @@ -2614,6 +2636,13 @@ function m.inferCheckDoc(status, source) end return true end + if source.type == 'doc.field' then + local results = m.getDocTypeNames(source.extends) + for _, res in ipairs(results) do + status.results[#status.results+1] = res + end + return true + end end function m.getVarargDocType(source) diff --git a/test-beta/definition/luadoc.lua b/test-beta/definition/luadoc.lua index 815b96f4..675495ef 100644 --- a/test-beta/definition/luadoc.lua +++ b/test-beta/definition/luadoc.lua @@ -113,16 +113,16 @@ local <!mt!> local <?<!x!>?> = f() ]] --- TODO -do return end TEST [[ ---@class Class ----@field <!name string!> +---@field <!name!> string ---@field id integer local mt = {} mt.<?name?> ]] +-- TODO +do return end TEST [[ ---@class loli local unit diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index e1c11f04..43a81fa3 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -512,7 +512,15 @@ TEST [[ print(io.<?stderr?>) ]] [[ -global io.stderr: FILE* +global io.stderr: FILE* { + close: function, + flush: function, + lines: function, + read: function, + seek: function, + setvbuf: function, + write: function, +} ]] TEST [[ @@ -1235,49 +1243,17 @@ function f(x: number?, y: boolean?) 2. string? ]] -do return end -TEST [[ ----@param x number {optional = 'after'} ----@param y boolean {optional = 'self'} ----@param z string -function <?f?>(x, y, z) end -]] -[=[ -function f([x: number [, y: boolean], z: string]) -]=] - -TEST [[ ----@return string {name = 'key'} ----@return string {name = 'value'} -function <?f?>() end -]] -[=[ -function f() - -> key: string, value: string -]=] - TEST [[ ----@return {name = 'x', optional = 'after'} ----@return string {name = 'y', optional = 'self'} ----@return string {name = 'z'} -function <?f?>() end +---@class Class +---@field x number +---@field y number +---@field z string +local <?t?> ]] -[=[ -function f() - -> [x: any [, y: string], z: string] -]=] - -TEST [[ ----@return {name = 'x', optional = 'after'} ----@return string {name = 'y', optional = 'self'} ----@return string {name = 'z'} -function f() - return function (a, b) - end -end - -<?f2?> = f() +[[ +local t: Class { + x: number, + y: number, + z: string, +} ]] -[=[ -function f2(a: any, b: any) -]=] |