diff options
Diffstat (limited to 'script/core/hint.lua')
-rw-r--r-- | script/core/hint.lua | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/script/core/hint.lua b/script/core/hint.lua index 62d2f7bf..42390443 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -6,13 +6,14 @@ local guide = require 'parser.guide' local await = require 'await' local define = require 'proto.define' +---@async local function typeHint(uri, results, start, finish) - local ast = files.getState(uri) - if not ast then + local state = files.getState(uri) + if not state then return end local mark = {} - guide.eachSourceBetween(ast.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' @@ -96,17 +97,18 @@ local function hasLiteralArgInCall(call) return false end +---@async local function paramName(uri, results, start, finish) local paramConfig = config.get 'Lua.hint.paramName' if not paramConfig or paramConfig == 'None' then return end - local ast = files.getState(uri) - if not ast then + local state = files.getState(uri) + if not state then return end local mark = {} - guide.eachSourceBetween(ast.ast, start, finish, function (source) + guide.eachSourceBetween(state.ast, start, finish, function (source) ---@async if source.type ~= 'call' then return end @@ -158,9 +160,39 @@ local function paramName(uri, results, start, finish) end) end +---@async +local function awaitHint(uri, results, start, finish) + local awaitConfig = config.get 'Lua.hint.await' + if not awaitConfig then + return + end + local state = files.getState(uri) + if not state then + return + end + guide.eachSourceBetween(state.ast, start, finish, function (source) ---@async + if source.type ~= 'call' then + return + end + await.delay() + local node = source.node + if not vm.isAsyncCall(source) then + return + end + results[#results+1] = { + text = 'await ', + offset = node.start, + kind = define.InlayHintKind.Other, + where = 'left', + } + end) +end + +---@async return function (uri, start, finish) local results = {} typeHint(uri, results, start, finish) + awaitHint(uri, results, start, finish) paramName(uri, results, start, finish) return results end |