summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/await.lua5
-rw-r--r--script/client.lua1
-rw-r--r--script/config/loader.lua1
-rw-r--r--script/core/command/autoRequire.lua2
-rw-r--r--script/core/command/jsonToLua.lua1
-rw-r--r--script/core/command/removeSpace.lua1
-rw-r--r--script/core/command/solve.lua1
-rw-r--r--script/core/completion.lua22
-rw-r--r--script/core/diagnostics/deprecated.lua2
-rw-r--r--script/core/diagnostics/init.lua1
-rw-r--r--script/core/diagnostics/redundant-value.lua2
-rw-r--r--script/core/diagnostics/type-check.lua2
-rw-r--r--script/core/diagnostics/undefined-field.lua1
-rw-r--r--script/core/diagnostics/undefined-global.lua2
-rw-r--r--script/core/diagnostics/unused-function.lua3
-rw-r--r--script/core/document-symbol.lua5
-rw-r--r--script/core/folding.lua3
-rw-r--r--script/core/hint.lua8
-rw-r--r--script/core/hover/init.lua3
-rw-r--r--script/core/hover/label.lua5
-rw-r--r--script/core/hover/table.lua1
-rw-r--r--script/core/semantic-tokens.lua2
-rw-r--r--script/core/signature.lua3
-rw-r--r--script/core/workspace-symbol.lua1
-rw-r--r--script/library.lua5
-rw-r--r--script/plugin.lua3
-rw-r--r--script/proto/proto.lua3
-rw-r--r--script/provider/diagnostic.lua11
-rw-r--r--script/provider/provider.lua53
-rw-r--r--script/pub/pub.lua1
-rw-r--r--script/service/telemetry.lua2
-rw-r--r--script/vm/getDocs.lua9
-rw-r--r--script/workspace/workspace.lua15
-rw-r--r--test/completion/init.lua1
-rw-r--r--test/crossfile/completion.lua1
-rw-r--r--test/crossfile/diagnostic.lua1
-rw-r--r--test/crossfile/hover.lua1
-rw-r--r--test/diagnostics/init.lua1
-rw-r--r--test/document_symbol/init.lua1
-rw-r--r--test/full/example.lua1
-rw-r--r--test/full/projects.lua1
-rw-r--r--test/full/self.lua1
-rw-r--r--test/hover/init.lua1
-rw-r--r--test/signature/init.lua1
44 files changed, 131 insertions, 60 deletions
diff --git a/script/await.lua b/script/await.lua
index e92af272..a887664a 100644
--- a/script/await.lua
+++ b/script/await.lua
@@ -66,6 +66,7 @@ function m.call(callback, ...)
end
--- 创建一个任务,并挂起当前线程,当任务完成后再延续当前线程/若任务被关闭,则返回nil
+---@async
function m.await(callback, ...)
if not coroutine.isyieldable() then
return callback(...)
@@ -109,6 +110,7 @@ end
--- 休眠一段时间
---@param time number
+---@async
function m.sleep(time)
if not coroutine.isyieldable() then
if m.errorHandle then
@@ -128,6 +130,7 @@ end
--- 等待直到唤醒
---@param callback function
+---@async
function m.wait(callback, ...)
if not coroutine.isyieldable() then
return
@@ -148,6 +151,7 @@ function m.wait(callback, ...)
end
--- 延迟
+---@async
function m.delay()
if not m._enable then
return
@@ -174,6 +178,7 @@ function m.delay()
end
--- stop then close
+---@async
function m.stop()
if not coroutine.isyieldable() then
return
diff --git a/script/client.lua b/script/client.lua
index 93ac38b3..4d338016 100644
--- a/script/client.lua
+++ b/script/client.lua
@@ -88,6 +88,7 @@ end
---@param titles string[]
---@return string action
---@return integer index
+---@async
function m.awaitRequestMessage(type, message, titles)
proto.notify('window/logMessage', {
type = define.MessageType[type] or 3,
diff --git a/script/config/loader.lua b/script/config/loader.lua
index 03fe9456..03588634 100644
--- a/script/config/loader.lua
+++ b/script/config/loader.lua
@@ -63,6 +63,7 @@ function m.loadLocalConfig(filename)
end
end
+---@async
function m.loadClientConfig()
local configs = proto.awaitRequest('workspace/configuration', {
items = {
diff --git a/script/core/command/autoRequire.lua b/script/core/command/autoRequire.lua
index ca8826d7..30bd13a1 100644
--- a/script/core/command/autoRequire.lua
+++ b/script/core/command/autoRequire.lua
@@ -63,6 +63,7 @@ local function findInsertRow(uri)
return row or 0, fmt
end
+---@async
local function askAutoRequire(visiblePaths)
local selects = {}
local nameMap = {}
@@ -125,6 +126,7 @@ local function applyAutoRequire(uri, row, name, result, fmt)
})
end
+---@async
return function (data)
local uri = data.uri
local target = data.target
diff --git a/script/core/command/jsonToLua.lua b/script/core/command/jsonToLua.lua
index 6aecee2c..d29ad608 100644
--- a/script/core/command/jsonToLua.lua
+++ b/script/core/command/jsonToLua.lua
@@ -7,6 +7,7 @@ local lang = require 'language'
local converter = require 'proto.converter'
local guide = require 'parser.guide'
+---@async
return function (data)
local state = files.getState(data.uri)
local text = files.getText(data.uri)
diff --git a/script/core/command/removeSpace.lua b/script/core/command/removeSpace.lua
index 3021d4a4..aa565f7f 100644
--- a/script/core/command/removeSpace.lua
+++ b/script/core/command/removeSpace.lua
@@ -12,6 +12,7 @@ local function isInString(ast, offset)
end) or false
end
+---@async
return function (data)
local uri = data.uri
local text = files.getText(uri)
diff --git a/script/core/command/solve.lua b/script/core/command/solve.lua
index 9428d065..19148092 100644
--- a/script/core/command/solve.lua
+++ b/script/core/command/solve.lua
@@ -27,6 +27,7 @@ local literalMap = {
['table'] = true,
}
+---@async
return function (data)
local uri = data.uri
local text = files.getText(uri)
diff --git a/script/core/completion.lua b/script/core/completion.lua
index afa54221..e30c9c91 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -203,6 +203,7 @@ local function getSnip(source)
end
end
+---@async
local function buildDesc(source)
if source.type == 'dummy' then
return
@@ -229,7 +230,7 @@ local function buildFunction(results, source, value, oop, data)
title = 'trigger signature',
command = 'editor.action.triggerParameterHints',
}
- snipData.id = stack(function ()
+ snipData.id = stack(function () ---@async
return {
detail = buildDetail(source),
description = buildDesc(source),
@@ -292,7 +293,7 @@ local function checkLocal(state, word, position, results)
match = name,
insertText = name,
kind = define.CompletionItemKind.Function,
- id = stack(function ()
+ id = stack(function () ---@async
return {
detail = buildDetail(source),
description = buildDesc(source),
@@ -305,7 +306,7 @@ local function checkLocal(state, word, position, results)
results[#results+1] = {
label = name,
kind = define.CompletionItemKind.Variable,
- id = stack(function ()
+ id = stack(function () ---@async
return {
detail = buildDetail(source),
description = buildDesc(source),
@@ -370,7 +371,7 @@ local function checkModule(state, word, position, results)
},
},
},
- id = stack(function ()
+ id = stack(function () ---@async
local md = markdown()
md:add('md', lang.script('COMPLETION_IMPORT_FROM', ('[%s](%s)'):format(
workspace.getRelativePath(uri),
@@ -471,7 +472,7 @@ local function checkFieldThen(name, src, word, startPos, position, parent, oop,
match = name:match '^[^(]+',
insertText = name:match '^[^(]+',
deprecated = vm.isDeprecated(src) or nil,
- id = stack(function ()
+ id = stack(function () ---@async
return {
detail = buildDetail(src),
description = buildDesc(src),
@@ -504,7 +505,7 @@ local function checkFieldThen(name, src, word, startPos, position, parent, oop,
deprecated = vm.isDeprecated(src) or nil,
textEdit = textEdit,
additionalTextEdits = additionalTextEdits,
- id = stack(function ()
+ id = stack(function () ---@async
return {
detail = buildDetail(src),
description = buildDesc(src),
@@ -513,6 +514,7 @@ local function checkFieldThen(name, src, word, startPos, position, parent, oop,
}
end
+---@async
local function checkFieldOfRefs(refs, state, word, startPos, position, parent, oop, results, locals, isGlobal)
local fields = {}
local funcs = {}
@@ -577,12 +579,14 @@ local function checkFieldOfRefs(refs, state, word, startPos, position, parent, o
end
end
+---@async
local function checkGlobal(state, word, startPos, position, parent, oop, results)
local locals = guide.getVisibleLocals(state.ast, position)
local globals = vm.getGlobalSets '*'
checkFieldOfRefs(globals, state, word, startPos, position, parent, oop, results, locals, 'global')
end
+---@async
local function checkField(state, word, start, position, parent, oop, results)
if parent.tag == '_ENV' or parent.special == '_G' then
local globals = vm.getGlobalSets '*'
@@ -1204,6 +1208,7 @@ local function trySpecial(state, text, position, results)
checkEqualEnum(state, text, position, results)
end
+---@async
local function tryIndex(state, text, position, results)
local parent, oop = findParentInStringIndex(state, text, position)
if not parent then
@@ -1213,6 +1218,7 @@ local function tryIndex(state, text, position, results)
checkField(state, word, position, position, parent, oop, results)
end
+---@async
local function tryWord(state, text, position, triggerCharacter, results)
local offset = guide.positionToOffset(state, position)
local finish = lookBackward.skipSpace(text, offset)
@@ -1268,6 +1274,7 @@ local function tryWord(state, text, position, triggerCharacter, results)
end
end
+---@async
local function trySymbol(state, text, position, results)
local symbol, start = lookBackward.findSymbol(text, guide.positionToOffset(state, position))
if not symbol then
@@ -1486,7 +1493,7 @@ local function checkTableLiteralField(state, text, position, tbl, fields, result
label = guide.getKeyName(field),
kind = define.CompletionItemKind.Property,
insertText = ('%s = $0'):format(guide.getKeyName(field)),
- id = stack(function ()
+ id = stack(function () ---@async
return {
detail = buildDetail(field),
description = buildDesc(field),
@@ -2061,6 +2068,7 @@ local function clearCache()
cache.results = nil
end
+---@async
local function completion(uri, position, triggerCharacter)
tracy.ZoneBeginN 'completion cache'
local results = getCache(uri, position)
diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua
index 0aeac9e9..7cd9e00f 100644
--- a/script/core/diagnostics/deprecated.lua
+++ b/script/core/diagnostics/deprecated.lua
@@ -16,7 +16,7 @@ return function (uri, callback)
local cache = {}
- guide.eachSourceTypes(ast.ast, types, function (src)
+ guide.eachSourceTypes(ast.ast, types, function (src) ---@async
if src.type == 'getglobal' then
local key = src[1]
if not key then
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index 63a1bcf0..4950900b 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -64,6 +64,7 @@ local function check(uri, name, results)
end
end
+---@async
return function (uri, response)
local ast = files.getState(uri)
if not ast then
diff --git a/script/core/diagnostics/redundant-value.lua b/script/core/diagnostics/redundant-value.lua
index 4c913330..edead570 100644
--- a/script/core/diagnostics/redundant-value.lua
+++ b/script/core/diagnostics/redundant-value.lua
@@ -10,7 +10,7 @@ return function (uri, callback)
return
end
- guide.eachSource(state.ast, function (src)
+ guide.eachSource(state.ast, function (src) ---@async
await.delay()
if src.redundant then
callback {
diff --git a/script/core/diagnostics/type-check.lua b/script/core/diagnostics/type-check.lua
index bbed30d8..3fa5050c 100644
--- a/script/core/diagnostics/type-check.lua
+++ b/script/core/diagnostics/type-check.lua
@@ -417,7 +417,7 @@ return function (uri, callback)
if not ast then
return
end
- guide.eachSourceType(ast.ast, 'call', function (source)
+ guide.eachSourceType(ast.ast, 'call', function (source) ---@async
if not source.args then
return
end
diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua
index ff02728f..66b1f8c5 100644
--- a/script/core/diagnostics/undefined-field.lua
+++ b/script/core/diagnostics/undefined-field.lua
@@ -26,6 +26,7 @@ return function (uri, callback)
local cache = {}
+ ---@async
local function checkUndefinedField(src)
local id = noder.getID(src)
if not id then
diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua
index 14754c16..640f521b 100644
--- a/script/core/diagnostics/undefined-global.lua
+++ b/script/core/diagnostics/undefined-global.lua
@@ -21,7 +21,7 @@ return function (uri, callback)
end
-- 遍历全局变量,检查所有没有 set 模式的全局变量
- guide.eachSourceType(ast.ast, 'getglobal', function (src)
+ guide.eachSourceType(ast.ast, 'getglobal', function (src) ---@async
local key = src[1]
if not key then
return
diff --git a/script/core/diagnostics/unused-function.lua b/script/core/diagnostics/unused-function.lua
index 8f6ccaac..ada4a23d 100644
--- a/script/core/diagnostics/unused-function.lua
+++ b/script/core/diagnostics/unused-function.lua
@@ -25,6 +25,7 @@ return function (uri, callback)
end
local cache = {}
+ ---@async
local function checkFunction(source)
if cache[source] ~= nil then
return cache[source]
@@ -81,7 +82,7 @@ return function (uri, callback)
end
-- 只检查局部函数
- guide.eachSourceType(ast.ast, 'function', function (source)
+ guide.eachSourceType(ast.ast, 'function', function (source) ---@async
checkFunction(source)
end)
end
diff --git a/script/core/document-symbol.lua b/script/core/document-symbol.lua
index cfabedab..00299867 100644
--- a/script/core/document-symbol.lua
+++ b/script/core/document-symbol.lua
@@ -219,6 +219,7 @@ local function buildAnonymousFunction(source, text, used, symbols)
}
end
+---@async
local function buildSource(source, text, used, symbols)
if source.type == 'local'
or source.type == 'setlocal'
@@ -243,7 +244,7 @@ local function makeSymbol(uri)
local symbols = {}
local used = {}
- guide.eachSource(ast.ast, function (source)
+ guide.eachSource(ast.ast, function (source) ---@async
buildSource(source, text, used, symbols)
end)
@@ -279,6 +280,7 @@ local function packChild(symbols)
return root
end
+---@async
local function packSymbols(symbols)
await.delay()
table.sort(symbols, function (a, b)
@@ -291,6 +293,7 @@ local function packSymbols(symbols)
return packChild(symbols)
end
+---@async
return function (uri)
local symbols = makeSymbol(uri)
if not symbols then
diff --git a/script/core/folding.lua b/script/core/folding.lua
index bd3ba5f3..2cf06d46 100644
--- a/script/core/folding.lua
+++ b/script/core/folding.lua
@@ -145,6 +145,7 @@ local Care = {
end,
}
+---@async
return function (uri)
local state = files.getState(uri)
local text = files.getText(uri)
@@ -154,7 +155,7 @@ return function (uri)
local regions = {}
local status = {}
- guide.eachSource(state.ast, function (source)
+ guide.eachSource(state.ast, function (source) ---@async
local tp = source.type
if Care[tp] then
await.delay()
diff --git a/script/core/hint.lua b/script/core/hint.lua
index 11559785..e094fc51 100644
--- a/script/core/hint.lua
+++ b/script/core/hint.lua
@@ -12,7 +12,7 @@ local function typeHint(uri, results, start, finish)
return
end
local mark = {}
- guide.eachSourceBetween(state.ast, start, finish, function (source)
+ guide.eachSourceBetween(state.ast, start, finish, function (source) ---@async
if source.type ~= 'local'
and source.type ~= 'setglobal'
and source.type ~= 'tablefield'
@@ -106,7 +106,7 @@ local function paramName(uri, results, start, finish)
return
end
local mark = {}
- guide.eachSourceBetween(state.ast, start, finish, function (source)
+ guide.eachSourceBetween(state.ast, start, finish, function (source) ---@async
if source.type ~= 'call' then
return
end
@@ -167,7 +167,7 @@ local function awaitHint(uri, results, start, finish)
if not state then
return
end
- guide.eachSourceBetween(state.ast, start, finish, function (source)
+ guide.eachSourceBetween(state.ast, start, finish, function (source) ---@async
if source.type ~= 'call' then
return
end
@@ -188,7 +188,7 @@ end
return function (uri, start, finish)
local results = {}
typeHint(uri, results, start, finish)
- paramName(uri, results, start, finish)
awaitHint(uri, results, start, finish)
+ paramName(uri, results, start, finish)
return results
end
diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua
index 784ef75d..f0160ab5 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
@@ -74,6 +76,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..44459bb6 100644
--- a/script/core/hover/label.lua
+++ b/script/core/hover/label.lua
@@ -44,6 +44,7 @@ local function asDocTypeName(source)
end
end
+---@async
local function asValue(source, title)
local name = buildName(source, false) or ''
local type = infer.searchAndViewInfers(source)
@@ -76,10 +77,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 +114,7 @@ local function isGlobalField(source)
end
end
+---@async
local function asField(source)
if isGlobalField(source) then
return asGlobal(source)
@@ -175,6 +179,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
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua
index dc0649d1..aef28aa6 100644
--- a/script/core/semantic-tokens.lua
+++ b/script/core/semantic-tokens.lua
@@ -381,7 +381,7 @@ return function (uri, start, finish)
end
local results = {}
- guide.eachSourceBetween(state.ast, start, finish, function (source)
+ guide.eachSourceBetween(state.ast, start, finish, function (source) ---@async
local method = Care[source.type]
if not method then
return
diff --git a/script/core/signature.lua b/script/core/signature.lua
index 007a3787..57483718 100644
--- a/script/core/signature.lua
+++ b/script/core/signature.lua
@@ -39,6 +39,7 @@ local function findNearCall(uri, ast, pos)
return nearCall
end
+---@async
local function makeOneSignature(source, oop, index)
local label = hoverLabel(source, oop)
-- 去掉返回值
@@ -77,6 +78,7 @@ local function makeOneSignature(source, oop, index)
}
end
+---@async
local function makeSignatures(text, call, pos)
local node = call.node
local oop = node.type == 'method'
@@ -136,6 +138,7 @@ local function makeSignatures(text, call, pos)
return signs
end
+---@async
return function (uri, pos)
local state = files.getState(uri)
if not state then
diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua
index 265a8d92..5fb4a741 100644
--- a/script/core/workspace-symbol.lua
+++ b/script/core/workspace-symbol.lua
@@ -57,6 +57,7 @@ local function searchFile(uri, key, results)
end)
end
+---@async
return function (key)
local results = {}
diff --git a/script/library.lua b/script/library.lua
index 943e6d2d..81242a91 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -341,6 +341,7 @@ local function apply3rd(cfg, onlyMemory)
end
local hasAsked
+---@async
local function askFor3rd(cfg)
hasAsked = true
local yes1 = lang.script.WINDOW_APPLY_WHIT_SETTING
@@ -395,7 +396,7 @@ local function check3rdByWords(text, configs)
if hasAsked then
return
end
- await.call(function ()
+ await.call(function () ---@async
for _, cfg in ipairs(configs) do
if cfg.words then
for _, word in ipairs(cfg.words) do
@@ -419,7 +420,7 @@ local function check3rdByFileName(uri, configs)
if not path then
return
end
- await.call(function ()
+ await.call(function () ---@async
for _, cfg in ipairs(configs) do
if cfg.files then
for _, filename in ipairs(cfg.files) do
diff --git a/script/plugin.lua b/script/plugin.lua
index 26e99d53..f56dc9f9 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -50,6 +50,7 @@ local function resetFiles()
end
end
+---@async
local function checkTrustLoad()
local filePath = LOGPATH .. '/trusted'
local trusted = util.loadFile(filePath)
@@ -79,7 +80,7 @@ function m.init()
return
end
m.hasInited = true
- await.call(function ()
+ await.call(function () ---@async
local ws = require 'workspace'
m.interface = {}
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 409f2b67..d54c902f 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -68,6 +68,7 @@ function m.notify(name, params)
io.write(buf)
end
+---@async
function m.awaitRequest(name, params)
local id = reqCounter()
local buf = jsonrpc.encode {
@@ -120,7 +121,7 @@ function m.doMethod(proto)
if proto.id then
m.holdon[proto.id] = proto
end
- await.call(function ()
+ await.call(function () ---@async
--log.debug('Start method:', method)
if proto.id then
await.setID('proto:' .. proto.id)
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 5099aa72..34bb10d4 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -182,6 +182,7 @@ function m.diagnostics(uri, diags)
end)
end
+---@async
function m.doDiagnostic(uri)
if not config.get 'Lua.diagnostics.enable' then
return
@@ -267,7 +268,7 @@ function m.refresh(uri)
return
end
await.close('diag:' .. uri)
- await.call(function ()
+ await.call(function () ---@async
await.delay()
if uri then
xpcall(m.doDiagnostic, log.error, uri)
@@ -276,6 +277,7 @@ function m.refresh(uri)
end, 'files.version')
end
+---@async
local function askForDisable()
if m.dontAskedForDisable then
return
@@ -334,7 +336,7 @@ function m.diagnosticsAll(force)
return
end
await.close 'diagnosticsAll'
- await.call(function ()
+ await.call(function () ---@async
await.sleep(delay)
m.diagnosticsAllClock = os.clock()
local clock = os.clock()
@@ -377,6 +379,7 @@ function m.checkStepResult()
end
end
+---@async
function m.checkWorkspaceDiag()
if not await.hasID 'diagnosticsAll' then
return
@@ -402,7 +405,7 @@ function m.checkWorkspaceDiag()
return false
end
-files.watch(function (ev, uri)
+files.watch(function (ev, uri) ---@async
if ev == 'remove' then
m.clear(uri)
m.refresh(uri)
@@ -422,7 +425,7 @@ files.watch(function (ev, uri)
end
end)
-await.watch(function (ev, co)
+await.watch(function (ev, co) ---@async
if ev == 'delay' then
if m.checkStepResult then
m.checkStepResult()
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 9ba8e708..811dc4e0 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -16,6 +16,7 @@ local cfgLoader = require 'config.loader'
local converter = require 'proto.converter'
local filewatch = require 'filewatch'
+---@async
local function updateConfig()
local new
if CONFIGPATH then
@@ -43,7 +44,7 @@ local function updateConfig()
log.debug('loaded config dump:', util.dump(new))
end
-filewatch.event(function (changes)
+filewatch.event(function (changes) ---@async
local configPath = workspace.getAbsolutePath(CONFIGPATH or '.luarc.json')
if not configPath then
return
@@ -68,7 +69,7 @@ proto.on('initialize', function (params)
}
end)
-proto.on('initialized', function (params)
+proto.on('initialized', function (params) ---@async
files.init()
local _ <close> = progress.create(lang.script.WINDOW_INITIALIZING, 0.5)
updateConfig()
@@ -102,14 +103,14 @@ proto.on('shutdown', function ()
return true
end)
-proto.on('workspace/didChangeConfiguration', function ()
+proto.on('workspace/didChangeConfiguration', function () ---@async
if CONFIGPATH then
return
end
updateConfig()
end)
-proto.on('workspace/didCreateFiles', function (params)
+proto.on('workspace/didCreateFiles', function (params) ---@async
log.debug('workspace/didCreateFiles', util.dump(params))
for _, file in ipairs(params.files) do
if workspace.isValidLuaUri(file.uri) then
@@ -130,7 +131,7 @@ proto.on('workspace/didDeleteFiles', function (params)
end
end)
-proto.on('workspace/didRenameFiles', function (params)
+proto.on('workspace/didRenameFiles', function (params) ---@async
log.debug('workspace/didRenameFiles', util.dump(params))
for _, file in ipairs(params.files) do
local text = files.getOriginText(file.oldUri)
@@ -157,7 +158,7 @@ proto.on('workspace/didRenameFiles', function (params)
end
end)
-proto.on('textDocument/didOpen', function (params)
+proto.on('textDocument/didOpen', function (params) ---@async
workspace.awaitReady()
local doc = params.textDocument
local uri = doc.uri
@@ -177,7 +178,7 @@ proto.on('textDocument/didClose', function (params)
end
end)
-proto.on('textDocument/didChange', function (params)
+proto.on('textDocument/didChange', function (params) ---@async
workspace.awaitReady()
local doc = params.textDocument
local changes = params.contentChanges
@@ -187,7 +188,7 @@ proto.on('textDocument/didChange', function (params)
files.setText(uri, text, true)
end)
-proto.on('textDocument/hover', function (params)
+proto.on('textDocument/hover', function (params) ---@async
local doc = params.textDocument
local uri = doc.uri
if not workspace.isReady() then
@@ -218,7 +219,7 @@ proto.on('textDocument/hover', function (params)
}
end)
-proto.on('textDocument/definition', function (params)
+proto.on('textDocument/definition', function (params) ---@async
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_DEFINITION, 0.5)
local core = require 'core.definition'
@@ -253,7 +254,7 @@ proto.on('textDocument/definition', function (params)
return response
end)
-proto.on('textDocument/typeDefinition', function (params)
+proto.on('textDocument/typeDefinition', function (params) ---@async
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_DEFINITION, 0.5)
local core = require 'core.type-definition'
@@ -288,7 +289,7 @@ proto.on('textDocument/typeDefinition', function (params)
return response
end)
-proto.on('textDocument/references', function (params)
+proto.on('textDocument/references', function (params) ---@async
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_REFERENCE, 0.5)
local core = require 'core.reference'
@@ -332,7 +333,7 @@ proto.on('textDocument/documentHighlight', function (params)
return response
end)
-proto.on('textDocument/rename', function (params)
+proto.on('textDocument/rename', function (params) ---@async
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_RENAME, 0.5)
local core = require 'core.rename'
@@ -376,7 +377,7 @@ proto.on('textDocument/prepareRename', function (params)
}
end)
-proto.on('textDocument/completion', function (params)
+proto.on('textDocument/completion', function (params) ---@async
local uri = params.textDocument.uri
if not workspace.isReady() then
local count, max = workspace.getLoadProcess()
@@ -522,7 +523,7 @@ proto.on('completionItem/resolve', function (item)
return item
end)
-proto.on('textDocument/signatureHelp', function (params)
+proto.on('textDocument/signatureHelp', function (params) ---@async
if not config.get 'Lua.signatureHelp.enable' then
return nil
end
@@ -564,7 +565,7 @@ proto.on('textDocument/signatureHelp', function (params)
}
end)
-proto.on('textDocument/documentSymbol', function (params)
+proto.on('textDocument/documentSymbol', function (params) ---@async
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SYMBOL, 0.5)
local core = require 'core.document-symbol'
@@ -575,6 +576,7 @@ proto.on('textDocument/documentSymbol', function (params)
return nil
end
+ ---@async
local function convert(symbol)
await.delay()
symbol.range = converter.packRange(
@@ -636,7 +638,7 @@ proto.on('textDocument/codeAction', function (params)
return results
end)
-proto.on('workspace/executeCommand', function (params)
+proto.on('workspace/executeCommand', function (params) ---@async
local command = params.command:gsub(':.+', '')
if command == 'lua.removeSpace' then
local core = require 'core.command.removeSpace'
@@ -656,7 +658,7 @@ proto.on('workspace/executeCommand', function (params)
end
end)
-proto.on('workspace/symbol', function (params)
+proto.on('workspace/symbol', function (params) ---@async
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_WS_SYMBOL, 0.5)
local core = require 'core.workspace-symbol'
@@ -685,7 +687,7 @@ proto.on('workspace/symbol', function (params)
return symbols
end)
-proto.on('textDocument/semanticTokens/full', function (params)
+proto.on('textDocument/semanticTokens/full', function (params) ---@async
local uri = params.textDocument.uri
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5)
@@ -696,7 +698,7 @@ proto.on('textDocument/semanticTokens/full', function (params)
}
end)
-proto.on('textDocument/semanticTokens/range', function (params)
+proto.on('textDocument/semanticTokens/range', function (params) ---@async
local uri = params.textDocument.uri
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5)
@@ -716,7 +718,7 @@ proto.on('textDocument/semanticTokens/range', function (params)
}
end)
-proto.on('textDocument/foldingRange', function (params)
+proto.on('textDocument/foldingRange', function (params) ---@async
local core = require 'core.folding'
local uri = params.textDocument.uri
if not files.exists(uri) then
@@ -750,7 +752,7 @@ proto.on('window/workDoneProgress/cancel', function (params)
progress.cancel(params.token)
end)
-proto.on('$/didChangeVisibleRanges', function (params)
+proto.on('$/didChangeVisibleRanges', function (params) ---@async
local uri = params.uri
await.close('visible:' .. uri)
await.setID('visible:' .. uri)
@@ -758,7 +760,7 @@ proto.on('$/didChangeVisibleRanges', function (params)
files.setVisibles(uri, params.ranges)
end)
-proto.on('$/status/click', function ()
+proto.on('$/status/click', function () ---@async
-- TODO: translate
local titleDiagnostic = '进行工作区诊断'
local result = client.awaitRequestMessage('Info', 'xxx', {
@@ -773,7 +775,7 @@ proto.on('$/status/click', function ()
end
end)
-proto.on('textDocument/onTypeFormatting', function (params)
+proto.on('textDocument/onTypeFormatting', function (params) ---@async
workspace.awaitReady()
local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5)
local ch = params.ch
@@ -805,7 +807,7 @@ proto.on('$/cancelRequest', function (params)
proto.close(params.id, define.ErrorCodes.RequestCancelled)
end)
-proto.on('$/requestHint', function (params)
+proto.on('$/requestHint', function (params) ---@async
local core = require 'core.hint'
if not config.get 'Lua.hint.enable' then
return
@@ -827,6 +829,7 @@ end)
-- Hint
do
+ ---@async
local function updateHint(uri)
if not config.get 'Lua.hint.enable' then
return
@@ -863,7 +866,7 @@ do
files.watch(function (ev, uri)
if ev == 'update'
or ev == 'updateVisible' then
- await.call(function ()
+ await.call(function () ---@async
updateHint(uri)
end)
end
diff --git a/script/pub/pub.lua b/script/pub/pub.lua
index ba57e5cb..fd780477 100644
--- a/script/pub/pub.lua
+++ b/script/pub/pub.lua
@@ -104,6 +104,7 @@ end
---@parma name string
---@param params any
---@return any
+---@async
function m.awaitTask(name, params)
local info = {
id = counter(),
diff --git a/script/service/telemetry.lua b/script/service/telemetry.lua
index 1ab3fdbe..dac72f3f 100644
--- a/script/service/telemetry.lua
+++ b/script/service/telemetry.lua
@@ -111,7 +111,7 @@ function m.updateConfig()
end
m.hasShowedMessage = true
- await.call(function ()
+ await.call(function () ---@async
local enableTitle = lang.script.WINDOW_TELEMETRY_ENABLE
local disableTitle = lang.script.WINDOW_TELEMETRY_DISABLE
local item = proto.awaitRequest('window/showMessageRequest', {
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua
index 260d2281..22e2e0cd 100644
--- a/script/vm/getDocs.lua
+++ b/script/vm/getDocs.lua
@@ -164,6 +164,9 @@ 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
@@ -204,11 +207,11 @@ function vm.isAsync(value, deep)
return false
end
for _, def in ipairs(defs) do
- if not isAsync(def) then
- return false
+ if isAsync(def) then
+ return true
end
end
- return true
+ return false
else
return isAsync(value)
end
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 726bec09..de534a96 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -74,6 +74,7 @@ local globInteferFace = {
}
--- 创建排除文件匹配器
+---@async
function m.getNativeMatcher()
if not m.path then
return nil
@@ -177,6 +178,7 @@ function m.getLibraryMatchers()
end
--- 文件是否被忽略
+---@async
function m.isIgnored(uri)
local path = m.getRelativePath(uri)
local ignore = m.getNativeMatcher()
@@ -186,6 +188,7 @@ function m.isIgnored(uri)
return ignore(path)
end
+---@async
function m.isValidLuaUri(uri)
if not files.isLua(uri) then
return false
@@ -198,7 +201,7 @@ function m.isValidLuaUri(uri)
end
local function loadFileFactory(root, progressData, isLibrary)
- return function (path)
+ return function (path) ---@async
local uri = furi.encode(path)
if files.isLua(uri) then
if not isLibrary and progressData.preload >= config.get 'Lua.workspace.maxPreload' then
@@ -279,6 +282,7 @@ local function loadFileFactory(root, progressData, isLibrary)
end
end
+---@async
function m.awaitLoadFile(uri)
local progressBar <close> = progress.create(lang.script.WORKSPACE_LOADING)
local progressData = {
@@ -299,6 +303,7 @@ function m.awaitLoadFile(uri)
end
--- 预读工作区内所有文件
+---@async
function m.awaitPreload()
local diagnostic = require 'provider.diagnostic'
await.close 'preload'
@@ -347,7 +352,7 @@ function m.awaitPreload()
if isLoadingFiles then
return
end
- await.call(function ()
+ await.call(function () ---@async
isLoadingFiles = true
while true do
local loader = table.remove(progressData.loaders)
@@ -563,6 +568,7 @@ function m.init()
m.reload()
end
+---@async
function m.awaitReload()
m.ready = false
m.hasHitMaxPreload = false
@@ -580,6 +586,7 @@ function m.awaitReload()
end
---等待工作目录加载完成
+---@async
function m.awaitReady()
if m.isReady() then
return
@@ -597,7 +604,7 @@ function m.getLoadProcess()
return m.fileLoaded, m.fileFound
end
-files.watch(function (ev, uri)
+files.watch(function (ev, uri) ---@async
if ev == 'close'
and m.isIgnored(uri)
and not files.isLibrary(uri) then
@@ -615,7 +622,7 @@ config.watch(function (key, value, oldValue)
end
end)
-fw.event(function (changes)
+fw.event(function (changes) ---@async
m.awaitReady()
for _, change in ipairs(changes) do
local path = change.path
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 58885149..11d39252 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -64,6 +64,7 @@ ContinueTyping = false
function TEST(script)
return function (expect)
+ ---@diagnostic disable: await-in-sync
files.removeAll()
local newScript, catched = catch(script, '?')
diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua
index 27acb15d..50ebad45 100644
--- a/test/crossfile/completion.lua
+++ b/test/crossfile/completion.lua
@@ -80,6 +80,7 @@ local function removeMetas(results)
util.tableMultiRemove(results, removes)
end
+---@diagnostic disable: await-in-sync
function TEST(data)
files.removeAll()
diff --git a/test/crossfile/diagnostic.lua b/test/crossfile/diagnostic.lua
index 7735f4c5..c2d043f4 100644
--- a/test/crossfile/diagnostic.lua
+++ b/test/crossfile/diagnostic.lua
@@ -29,6 +29,7 @@ local function founded(targets, results)
return true
end
+---@diagnostic disable: await-in-sync
function TEST(datas)
files.removeAll()
diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua
index 35528446..6357ab50 100644
--- a/test/crossfile/hover.lua
+++ b/test/crossfile/hover.lua
@@ -37,6 +37,7 @@ local function eq(a, b)
return a == b
end
+---@diagnostic disable: await-in-sync
function TEST(expect)
files.removeAll()
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index 6d97c7f6..55adda36 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -26,6 +26,7 @@ local function founded(targets, results)
return true
end
+---@diagnostic disable: await-in-sync
function TEST(script, ...)
files.removeAll()
local newScript, catched = catch(script, '!')
diff --git a/test/document_symbol/init.lua b/test/document_symbol/init.lua
index d3168197..1324f29c 100644
--- a/test/document_symbol/init.lua
+++ b/test/document_symbol/init.lua
@@ -45,6 +45,7 @@ local function checkArcoss(symbols)
end
end
+---@diagnostic disable: await-in-sync
function TEST(script)
return function (expect)
files.removeAll()
diff --git a/test/full/example.lua b/test/full/example.lua
index 20de5528..0505f1a5 100644
--- a/test/full/example.lua
+++ b/test/full/example.lua
@@ -8,6 +8,7 @@ local luadoc = require "parser.luadoc"
local noder = require 'core.noder'
-- 临时
+---@diagnostic disable: await-in-sync
local function testIfExit(path)
config.set('Lua.workspace.preloadFileSize', 1000000000)
local buf = util.loadFile(path:string())
diff --git a/test/full/projects.lua b/test/full/projects.lua
index 316b554d..36d80baa 100644
--- a/test/full/projects.lua
+++ b/test/full/projects.lua
@@ -9,6 +9,7 @@ local fs = require 'bee.filesystem'
config.set('Lua.workspace.preloadFileSize', 1000000)
config.set('Lua.diagnostics.neededFileStatus', {})
+---@diagnostic disable: await-in-sync
local function doProjects(pathname)
files.removeAll()
diff --git a/test/full/self.lua b/test/full/self.lua
index 63e76d9a..67537a54 100644
--- a/test/full/self.lua
+++ b/test/full/self.lua
@@ -25,6 +25,7 @@ diag.start()
local clock = os.clock()
+---@diagnostic disable: await-in-sync
for uri in files.eachFile() do
local fileClock = os.clock()
diag.doDiagnostic(uri)
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 36fbd6d2..54fab5fc 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -19,6 +19,7 @@ local accept = {
['function'] = true,
}
+---@diagnostic disable: await-in-sync
function TEST(script)
return function (expect)
files.removeAll()
diff --git a/test/signature/init.lua b/test/signature/init.lua
index 1dbe61e8..8bc53f02 100644
--- a/test/signature/init.lua
+++ b/test/signature/init.lua
@@ -4,6 +4,7 @@ local catch = require 'catch'
rawset(_G, 'TEST', true)
+---@diagnostic disable: await-in-sync
function TEST(script)
return function (expect)
local newScript, catched1 = catch(script, '?')