diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-11 15:44:48 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-11 15:44:48 +0800 |
commit | 85a9019faccdf44fafec36fa816bbc4a78b58286 (patch) | |
tree | 409140cf0ee00b06da763c2c69f9349872fe626d | |
parent | 72954de6b303866cbdbab25c0f4e8c00b9dfbe2b (diff) | |
download | lua-language-server-85a9019faccdf44fafec36fa816bbc4a78b58286.zip |
update semantic tokens
-rw-r--r-- | script/core/semantic-tokens.lua | 136 | ||||
-rw-r--r-- | script/parser/guide.lua | 2 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 6 |
3 files changed, 127 insertions, 17 deletions
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 96a1a56c..ca6471a7 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -373,32 +373,125 @@ local Care = util.switch() type = define.TokenTypes.number, } end) - : case 'doc.return.name' + : case 'doc.class.name' : call(function (source, options, results) results[#results+1] = { - start = source.start, - finish = source.finish, - type = define.TokenTypes.parameter, + start = source.start, + finish = source.finish, + type = define.TokenTypes.class, + modifieres = define.TokenModifiers.declaration, } end) - : case 'doc.tailcomment' + : case 'doc.extends.name' : call(function (source, options, results) results[#results+1] = { - start = source.start, - finish = source.finish, - type = define.TokenTypes.comment, + start = source.start, + finish = source.finish, + type = define.TokenTypes.class, } end) : case 'doc.type.name' : call(function (source, options, results) if source.typeGeneric then results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.type, + modifieres = define.TokenModifiers.modification, + } + else + results[#results+1] = { start = source.start, finish = source.finish, - type = define.TokenTypes.macro, + type = define.TokenTypes.type, + } + end + end) + : case 'doc.alias.name' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.macro, + } + end) + : case 'doc.param.name' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.parameter, + } + end) + : case 'doc.field' + : call(function (source, options, results) + if source.visible then + results[#results+1] = { + start = source.start, + finish = source.start + #source.visible, + type = define.TokenTypes.keyword, } end end) + : case 'doc.field.name' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.property, + modifieres = define.TokenModifiers.declaration, + } + end) + : case 'doc.return.name' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.parameter, + } + end) + : case 'doc.generic.name' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.type, + modifieres = define.TokenModifiers.modification, + } + end) + : case 'doc.type.function' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.start + #'fun', + type = define.TokenTypes.keyword, + } + if source.async then + results[#results+1] = { + start = source.asyncPos, + finish = source.asyncPos + #'async', + type = define.TokenTypes.keyword, + modifieres = define.TokenModifiers.async, + } + end + end) + : case 'doc.type.arg.name' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.parameter, + modifieres = define.TokenModifiers.declaration, + } + end) + : case 'doc.tailcomment' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.comment, + } + end) : case 'nonstandardSymbol.comment' : call(function (source, options, results) results[#results+1] = { @@ -559,11 +652,26 @@ return function (uri, start, finish) end) for _, comm in ipairs(state.comms) do - results[#results+1] = { - start = comm.start, - finish = comm.finish, - type = define.TokenTypes.comment, - } + if comm.type == 'comment.short' + and comm.text:sub(1, 2) == '-@' then + results[#results+1] = { + start = comm.start, + finish = comm.start + 3, + type = define.TokenTypes.comment, + } + results[#results+1] = { + start = comm.start + 3, + finish = comm.start + 2 + #comm.text:match '%S+', + type = define.TokenTypes.comment, + modifieres = define.TokenModifiers.documentation, + } + else + results[#results+1] = { + start = comm.start, + finish = comm.finish, + type = define.TokenTypes.comment, + } + end end if #results == 0 then diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 258d8cdc..1175fd84 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -141,7 +141,7 @@ local childMap = { ['doc.type.function'] = {'#args', '#returns', 'comment'}, ['doc.type.ltable'] = {'#fields', 'comment'}, ['doc.type.literal'] = {'node'}, - ['doc.type.arg'] = {'extends'}, + ['doc.type.arg'] = {'name', 'extends'}, ['doc.type.field'] = {'extends'}, ['doc.overload'] = {'overload', 'comment'}, ['doc.see'] = {'name', 'field'}, diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 4d46d674..576cdb5c 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -368,8 +368,8 @@ local function parseTypeUnitFunction() type = 'doc.type.arg', parent = typeUnit, } - arg.name = parseName('doc.type.name', arg) - or parseDots('doc.type.name', arg) + arg.name = parseName('doc.type.arg.name', arg) + or parseDots('doc.type.arg.name', arg) if not arg.name then pushWarning { type = 'LUADOC_MISS_ARG_NAME', @@ -484,6 +484,7 @@ local parseTypeUnit local function parseDocFunction(parent, content) if content == 'async' then + local pos = getStart() local tp, cont = peekToken() if tp == 'name' then if cont == 'fun' then @@ -491,6 +492,7 @@ local function parseDocFunction(parent, content) local func = parseTypeUnit(parent, cont) if func then func.async = true + func.asyncPos = pos return func end end |