diff options
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/completion/completion.lua | 46 | ||||
-rw-r--r-- | script/core/hover/description.lua | 67 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 8 |
3 files changed, 97 insertions, 24 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 15bc0fcb..5a61919c 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1251,6 +1251,46 @@ local function insertDocEnum(state, pos, doc, enums) return enums end +---@param state parser.state +---@param pos integer +---@param doc vm.node.object +---@param enums table[] +---@return table[]? +local function insertDocEnumKey(state, pos, doc, enums) + local tbl = doc.bindSource + if not tbl then + return nil + end + local keyEnums = {} + for _, field in ipairs(tbl) do + if field.type == 'tablefield' + or field.type == 'tableindex' then + if not field.value then + goto CONTINUE + end + local key = guide.getKeyName(field) + if not key then + goto CONTINUE + end + enums[#enums+1] = { + label = ('%q'):format(key), + kind = define.CompletionItemKind.EnumMember, + id = stack(field, function (newField) ---@async + return { + detail = buildDetail(newField), + description = buildDesc(newField), + } + end), + } + ::CONTINUE:: + end + end + for _, enum in ipairs(keyEnums) do + enums[#enums+1] = enum + end + return enums +end + local function buildInsertDocFunction(doc) local args = {} for i, arg in ipairs(doc.args) do @@ -1316,7 +1356,11 @@ local function insertEnum(state, pos, src, enums, isInArray, mark) elseif src.type == 'global' and src.cate == 'type' then for _, set in ipairs(src:getSets(state.uri)) do if set.type == 'doc.enum' then - insertDocEnum(state, pos, set, enums) + if vm.docHasAttr(set, 'key') then + insertDocEnumKey(state, pos, set, enums) + else + insertDocEnum(state, pos, set, enums) + end end end end diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index f5890b21..58fb9fbe 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -477,34 +477,55 @@ local function tryDocEnum(source) if not tbl then return end - local md = markdown() - md:add('lua', '{') - for _, field in ipairs(tbl) do - if field.type == 'tablefield' - or field.type == 'tableindex' then - if not field.value then - goto CONTINUE - end - local key = guide.getKeyName(field) - if not key then - goto CONTINUE - end - if field.value.type == 'integer' - or field.value.type == 'string' then - md:add('lua', (' %s: %s = %s,'):format(key, field.value.type, field.value[1])) + if vm.docHasAttr(source, 'key') then + local md = markdown() + local keys = {} + for _, field in ipairs(tbl) do + if field.type == 'tablefield' + or field.type == 'tableindex' then + if not field.value then + goto CONTINUE + end + local key = guide.getKeyName(field) + if not key then + goto CONTINUE + end + keys[#keys+1] = ('%q'):format(key) + ::CONTINUE:: end - if field.value.type == 'binary' - or field.value.type == 'unary' then - local number = vm.getNumber(field.value) - if number then - md:add('lua', (' %s: %s = %s,'):format(key, math.tointeger(number) and 'integer' or 'number', number)) + end + md:add('lua', table.concat(keys, ' | ')) + return md:string() + else + local md = markdown() + md:add('lua', '{') + for _, field in ipairs(tbl) do + if field.type == 'tablefield' + or field.type == 'tableindex' then + if not field.value then + goto CONTINUE + end + local key = guide.getKeyName(field) + if not key then + goto CONTINUE + end + if field.value.type == 'integer' + or field.value.type == 'string' then + md:add('lua', (' %s: %s = %s,'):format(key, field.value.type, field.value[1])) + end + if field.value.type == 'binary' + or field.value.type == 'unary' then + local number = vm.getNumber(field.value) + if number then + md:add('lua', (' %s: %s = %s,'):format(key, math.tointeger(number) and 'integer' or 'number', number)) + end end + ::CONTINUE:: end - ::CONTINUE:: end + md:add('lua', '}') + return md:string() end - md:add('lua', '}') - return md:string() end ---@async diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index cd19e2ee..4e1d8e00 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -711,6 +711,14 @@ local Care = util.switch() type = define.TokenTypes.namespace, } end) + : case 'doc.attr' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.decorator, + } + end) ---@param state table ---@param results table |