Skip to content

Commit

Permalink
fix parsing resumes
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Mar 18, 2021
1 parent 8dea4e4 commit bf5ee64
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
18 changes: 13 additions & 5 deletions script/parser/luadoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)*
Expand Down Expand Up @@ -544,18 +544,25 @@ 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
local nextComm = NextComment(i,'peek')
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()
Expand Down Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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)]
Expand Down
33 changes: 33 additions & 0 deletions test/completion/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,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)
Expand Down

0 comments on commit bf5ee64

Please sign in to comment.