diff options
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/completion/completion.lua | 36 | ||||
-rw-r--r-- | script/core/definition.lua | 1 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 8 |
3 files changed, 45 insertions, 0 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index b164d738..0f720684 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1514,6 +1514,7 @@ local function tryluaDocCate(word, results) 'module', 'async', 'nodiscard', + 'cast', } do if matchKey(word, docType) then results[#results+1] = { @@ -1662,8 +1663,27 @@ local function tryluaDocBySource(state, position, source, results) } end end + return true elseif source.type == 'doc.module' then collectRequireNames('require', state.uri, source.module or '', source, source.smark, position, results) + return true + elseif source.type == 'doc.cast.name' then + local locals = guide.getVisibleLocals(state.ast, position) + for name, loc in util.sortPairs(locals) do + if matchKey(source[1], name) then + results[#results+1] = { + label = name, + kind = define.CompletionItemKind.Variable, + id = stack(function () ---@async + return { + detail = buildDetail(loc), + description = buildDesc(loc), + } + end), + } + end + end + return true end return false end @@ -1758,6 +1778,22 @@ local function tryluaDocByErr(state, position, err, docState, results) end elseif err.type == 'LUADOC_MISS_MODULE_NAME' then collectRequireNames('require', state.uri, '', docState, nil, position, results) + elseif err.type == 'LUADOC_MISS_LOCAL_NAME' then + local locals = guide.getVisibleLocals(state.ast, position) + for name, loc in util.sortPairs(locals) do + if name ~= '_ENV' then + results[#results+1] = { + label = name, + kind = define.CompletionItemKind.Variable, + id = stack(function () ---@async + return { + detail = buildDetail(loc), + description = buildDesc(loc), + } + end), + } + end + end end end diff --git a/script/core/definition.lua b/script/core/definition.lua index b89aa751..e2d3b519 100644 --- a/script/core/definition.lua +++ b/script/core/definition.lua @@ -53,6 +53,7 @@ local accept = { ['doc.alias.name'] = true, ['doc.see.name'] = true, ['doc.see.field'] = true, + ['doc.cast.name'] = true, } local function checkRequire(source, offset) diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 3b23cb95..e1c262ea 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -652,6 +652,14 @@ local Care = util.switch() type = define.TokenTypes.keyword, } end) + : case 'doc.cast.name' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.variable, + } + end) local function buildTokens(uri, results) local tokens = {} |