diff options
-rw-r--r-- | script/core/semantic-tokens.lua | 7 | ||||
-rw-r--r-- | script/parser/guide.lua | 24 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 20 | ||||
-rw-r--r-- | test/hover/init.lua | 8 |
4 files changed, 38 insertions, 21 deletions
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index e6b35cdd..668103f7 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -98,6 +98,13 @@ Care['doc.return.name'] = function (source, results) type = define.TokenTypes.parameter, } end +Care['doc.tailcomment'] = function (source, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.comment, + } +end local function buildTokens(results, text, lines) local tokens = {} diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 7ca3ddd0..bc82ec57 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -84,18 +84,18 @@ m.childMap = { ['unary'] = {1}, ['doc'] = {'#'}, - ['doc.class'] = {'class', 'extends'}, - ['doc.type'] = {'#types', '#enums', 'name'}, - ['doc.alias'] = {'alias', 'extends'}, - ['doc.param'] = {'param', 'extends'}, - ['doc.return'] = {'#returns'}, - ['doc.field'] = {'field', 'extends'}, - ['doc.generic'] = {'#generics'}, - ['doc.generic.object'] = {'generic', 'extends'}, - ['doc.vararg'] = {'vararg'}, - ['doc.type.table'] = {'key', 'value'}, - ['doc.type.function'] = {'#args', '#returns'}, - ['doc.overload'] = {'overload'}, + ['doc.class'] = {'class', 'extends', 'comment'}, + ['doc.type'] = {'#types', '#enums', 'name', 'comment'}, + ['doc.alias'] = {'alias', 'extends', 'comment'}, + ['doc.param'] = {'param', 'extends', 'comment'}, + ['doc.return'] = {'#returns', 'comment'}, + ['doc.field'] = {'field', 'extends', 'comment'}, + ['doc.generic'] = {'#generics', 'comment'}, + ['doc.generic.object'] = {'generic', 'extends', 'comment'}, + ['doc.vararg'] = {'vararg', 'comment'}, + ['doc.type.table'] = {'key', 'value', 'comment'}, + ['doc.type.function'] = {'#args', '#returns', 'comment'}, + ['doc.overload'] = {'overload', 'comment'}, } m.actionMap = { diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 2b2396ec..53f0097d 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -856,19 +856,21 @@ local function buildLuaDoc(comment) comment = comment, } end - local finishPos = text:find('@', startPos + 1) - local doc, lastComment - if finishPos then - doc = text:sub(startPos + 1, finishPos - 1) - lastComment = text:sub(finishPos) - else - doc = text:sub(startPos + 1) - end + + local doc = text:sub(startPos + 1) parseTokens(doc, comment.start + startPos - 1) local result = convertTokens() if result then - result.comment = lastComment + local cstart = text:find('%S', result.finish - comment.start + 2) + if cstart and cstart < comment.finish then + result.comment = { + type = 'doc.tailcomment', + start = cstart + comment.start - 1, + finish = comment.finish, + text = text:sub(cstart), + } + end end return result diff --git a/test/hover/init.lua b/test/hover/init.lua index 4bfde29e..54f1e451 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1441,3 +1441,11 @@ local <?y?> [[ local y: any ]] + +TEST [[ +---@param x string this is comment +function f(<?x?>) end +]] +[[ +local x: string +]] |