diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-03-18 21:14:51 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-03-18 21:14:51 +0800 |
commit | bf5ee64312ef766c3f1ec34f10ac9662e9e214fa (patch) | |
tree | 256bb66941a8ae7d886fdf1678ed31e4bbc2a4e8 | |
parent | 8dea4e479d79b44c54d5380f3e6c00f3c3c8aacd (diff) | |
download | lua-language-server-bf5ee64312ef766c3f1ec34f10ac9662e9e214fa.zip |
fix parsing resumes
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 18 | ||||
-rw-r--r-- | test/completion/init.lua | 33 |
3 files changed, 49 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md index ea68cecd..c3909920 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # changelog +## 1.19.1 +* `FIX` `LuaDoc`: parsing resumes may wrong + ## 1.19.0 `2021-3-18` * `NEW` VSCode: new setting `Lua.misc.parameters` diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index aa258932..7e133aa2 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -4,7 +4,7 @@ local lines = require 'parser.lines' local guide = require 'core.guide' local TokenTypes, TokenStarts, TokenFinishs, TokenContents -local Ci, Offset, pushError, Ct, NextComment +local Ci, Offset, pushError, Ct, NextComment, Lines local parseType local Parser = re.compile([[ Main <- (Token / Sp)* @@ -544,6 +544,8 @@ function parseType(parent) result.finish = getFinish() result.firstFinish = result.finish + local row = guide.positionOf(Lines, result.finish) + local function pushResume() local comments for i = 0, 100 do @@ -551,11 +553,16 @@ function parseType(parent) if not nextComm then return false end + local line = Lines[row + i + 1] + if line.finish < nextComm.start then + return false + end if nextComm.text:sub(1, 2) == '-@' then return false else if nextComm.text:sub(1, 2) == '-|' then NextComment(i) + row = row + i + 1 local finishPos = nextComm.text:find('#', 3) or #nextComm.text parseTokens(nextComm.text:sub(3, finishPos), nextComm.start + 1) local resume = parseResume() @@ -1192,7 +1199,6 @@ local function bindDoc(sources, lns, binded) end local function bindDocs(state) - local lns = lines(nil, state.lua) local sources = {} guide.eachSource(state.ast, function (src) if src.type == 'local' @@ -1213,14 +1219,14 @@ local function bindDocs(state) end) local binded for _, doc in ipairs(state.ast.docs) do - if not isNextLine(lns, binded, doc) then - bindDoc(sources, lns, binded) + if not isNextLine(Lines, binded, doc) then + bindDoc(sources, Lines, binded) binded = {} state.ast.docs.groups[#state.ast.docs.groups+1] = binded end binded[#binded+1] = doc end - bindDoc(sources, lns, binded) + bindDoc(sources, Lines, binded) end return function (_, state) @@ -1237,6 +1243,8 @@ return function (_, state) pushError = state.pushError + Lines = lines(nil, state.lua) + local ci = 1 NextComment = function (offset, peek) local comment = comments[ci + (offset or 0)] diff --git a/test/completion/init.lua b/test/completion/init.lua index bf7a896f..ba3c5be5 100644 --- a/test/completion/init.lua +++ b/test/completion/init.lua @@ -1788,6 +1788,39 @@ f($) } TEST [[ +---this is +---a multi line +---comment +---@alias XXXX +---comment 1 +---comment 1 +---| '1' +---comment 2 +---comment 2 +---| '2' +---@param x XXXX +local function f(x) +end + + +---comment 3 +---comment 3 +---| '3' + +f($) +]] +{ + { + label = '1', + kind = define.CompletionItemKind.EnumMember, + }, + { + label = '2', + kind = define.CompletionItemKind.EnumMember, + }, +} + +TEST [[ ---@param x function | 'function () end' function f(x) end |