diff options
Diffstat (limited to 'script/core/hover')
-rw-r--r-- | script/core/hover/init.lua | 8 | ||||
-rw-r--r-- | script/core/hover/label.lua | 14 | ||||
-rw-r--r-- | script/core/hover/table.lua | 1 |
3 files changed, 22 insertions, 1 deletions
diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua index 784ef75d..7d99a006 100644 --- a/script/core/hover/init.lua +++ b/script/core/hover/init.lua @@ -7,12 +7,14 @@ local findSource = require 'core.find-source' local markdown = require 'provider.markdown' local infer = require 'core.infer' +---@async local function getHover(source) local md = markdown() local defMark = {} local labelMark = {} local descMark = {} + ---@async local function addHover(def, checkLable) if defMark[def] then return @@ -37,12 +39,17 @@ local function getHover(source) end if infer.searchAndViewInfers(source) == 'function' then + local hasFunc for _, def in ipairs(vm.getDefs(source)) do if def.type == 'function' or def.type == 'doc.type.function' then + hasFunc = true addHover(def, true) end end + if not hasFunc then + addHover(source, true) + end else addHover(source, true) for _, def in ipairs(vm.getDefs(source)) do @@ -74,6 +81,7 @@ local accept = { ['doc.module'] = true, } +---@async local function getHoverByUri(uri, position) local ast = files.getState(uri) if not ast then diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index 8906d54d..0bb4fe89 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -16,7 +16,11 @@ local function asFunction(source, oop) local arg = buildArg(source, oop) local rtn = buildReturn(source) local lines = {} - lines[1] = ('%s %s(%s)'):format(oop and 'method' or 'function', name or '', arg) + lines[1] = ('%s%s %s(%s)'):format( + vm.isAsync(source) and 'async ' or '', + oop and 'method' or 'function', + name or '', arg + ) lines[2] = rtn return table.concat(lines, '\n') end @@ -44,6 +48,7 @@ local function asDocTypeName(source) end end +---@async local function asValue(source, title) local name = buildName(source, false) or '' local type = infer.searchAndViewInfers(source) @@ -59,6 +64,9 @@ local function asValue(source, title) local pack = {} pack[#pack+1] = title pack[#pack+1] = name .. ':' + if vm.isAsync(source, true) then + pack[#pack+1] = 'async' + end if cont and ( type == 'table' or type == 'any' @@ -76,10 +84,12 @@ local function asValue(source, title) return table.concat(pack, ' ') end +---@async local function asLocal(source) return asValue(source, 'local') end +---@async local function asGlobal(source) return asValue(source, 'global') end @@ -111,6 +121,7 @@ local function isGlobalField(source) end end +---@async local function asField(source) if isGlobalField(source) then return asGlobal(source) @@ -175,6 +186,7 @@ local function asNumber(source) return formatNumber(num) end +---@async return function (source, oop) if source.type == 'function' then return asFunction(source, oop) diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua index 68a04b40..285d5c02 100644 --- a/script/core/hover/table.lua +++ b/script/core/hover/table.lua @@ -134,6 +134,7 @@ local function getOptionalMap(fields) return optionals end +---@async return function (source) local maxFields = config.get 'Lua.hover.previewFields' if maxFields <= 0 then |