summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/hover/init.lua5
-rw-r--r--script/core/hover/label.lua3
-rw-r--r--script/parser/luadoc.lua13
-rw-r--r--script/vm/getDocs.lua30
-rw-r--r--test/diagnostics/init.lua19
-rw-r--r--test/hover/init.lua16
6 files changed, 71 insertions, 15 deletions
diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua
index f0160ab5..7d99a006 100644
--- a/script/core/hover/init.lua
+++ b/script/core/hover/init.lua
@@ -39,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
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua
index 803b9596..0bb4fe89 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -64,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'
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 9f286ed4..6f7593c1 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -492,6 +492,19 @@ local function parseTypeUnitLiteralTable()
end
local function parseTypeUnit(parent, content)
+ if content == 'async' then
+ local tp, cont = peekToken()
+ if tp == 'name' then
+ if cont == 'fun' then
+ nextToken()
+ local func = parseTypeUnit(parent, cont)
+ if func then
+ func.async = true
+ return func
+ end
+ end
+ end
+ end
local result
if content == 'fun' then
result = parseTypeUnitFunction()
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua
index 22e2e0cd..ed2299ec 100644
--- a/script/vm/getDocs.lua
+++ b/script/vm/getDocs.lua
@@ -164,23 +164,23 @@ local function isDeprecated(value)
end
local function isAsync(value)
- if value.type ~= 'function' then
- return false
- end
- if not value.bindDocs then
- return false
- end
- if value._async ~= nil then
- return value._async
- end
- for _, doc in ipairs(value.bindDocs) do
- if doc.type == 'doc.async' then
- value._async = true
- return true
+ if value.type == 'function' then
+ if not value.bindDocs then
+ return false
+ end
+ if value._async ~= nil then
+ return value._async
end
+ for _, doc in ipairs(value.bindDocs) do
+ if doc.type == 'doc.async' then
+ value._async = true
+ return true
+ end
+ end
+ value._async = false
+ return false
end
- value._async = false
- return false
+ return value.async == true
end
function vm.isDeprecated(value, deep)
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index 55adda36..a46a6dd7 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -1369,3 +1369,22 @@ function F()
coroutine.yield()
end
]]
+
+TEST [[
+---@type async fun()
+local f
+
+function F()
+ <!f!>()
+end
+]]
+
+TEST [[
+---@type async fun()
+local f
+
+---@async
+function F()
+ f()
+end
+]]
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 404adb44..d2a6e084 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -1732,3 +1732,19 @@ local function <?f?>() end
[[
async function f()
]]
+
+TEST [[
+---@type function
+local <?f?>
+]]
+[[
+local f: function
+]]
+
+TEST [[
+---@type async fun()
+local <?f?>
+]]
+[[
+local f: async fun()
+]]