diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-21 15:44:41 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-21 15:44:41 +0800 |
commit | c32bbad6aa97fafe98a76bb387ab0a687ebcd38e (patch) | |
tree | c370c39f8f40adce79331126579e32059b7384a7 /script/parser/luadoc.lua | |
parent | 7221cc92acd0099ed28727536c30d264b3cb7bcc (diff) | |
download | lua-language-server-c32bbad6aa97fafe98a76bb387ab0a687ebcd38e.zip |
update
Diffstat (limited to 'script/parser/luadoc.lua')
-rw-r--r-- | script/parser/luadoc.lua | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 95e902af..9fc8a6dc 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1373,37 +1373,45 @@ local function buildLuaDoc(comment) } end -local function isTailComment(text, binded) - local lastDoc = binded[#binded] - local left = lastDoc.originalComment.start +local function isTailComment(text, doc) + if not doc then + return false + end + local left = doc.originalComment.start local row, col = guide.rowColOf(left) local lineStart = Lines[row] or 0 local hasCodeBefore = text:sub(lineStart, lineStart + col):find '[%w_]' return hasCodeBefore end -local function isNextLine(binded, doc) - if not binded then +local function isContinuedDoc(lastDoc, nextDoc) + if not nextDoc then return false end - local lastDoc = binded[#binded] if lastDoc.type == 'doc.type' or lastDoc.type == 'doc.module' then return false end if lastDoc.type == 'doc.class' or lastDoc.type == 'doc.field' then - if doc.type ~= 'doc.field' - and doc.type ~= 'doc.comment' - and doc.type ~= 'doc.overload' then + if nextDoc.type ~= 'doc.field' + and nextDoc.type ~= 'doc.comment' + and nextDoc.type ~= 'doc.overload' then return false end end - if doc.type == 'doc.cast' then + if nextDoc.type == 'doc.cast' then + return false + end + return true +end + +local function isNextLine(lastDoc, nextDoc) + if not nextDoc then return false end local lastRow = guide.rowColOf(lastDoc.finish) - local newRow = guide.rowColOf(doc.start) + local newRow = guide.rowColOf(nextDoc.start) return newRow - lastRow == 1 end @@ -1582,19 +1590,28 @@ local function bindDocs(state) return a.start < b.start end) local binded - for _, doc in ipairs(state.ast.docs) do - if not isNextLine(binded, doc) then - bindDoc(sources, binded) + for i, doc in ipairs(state.ast.docs) do + if not binded then binded = {} state.ast.docs.groups[#state.ast.docs.groups+1] = binded end binded[#binded+1] = doc - if isTailComment(text, binded) then + if isTailComment(text, doc) then bindDoc(sources, binded) binded = nil + else + local nextDoc = state.ast.docs[i+1] + if not isNextLine(doc, nextDoc) then + bindDoc(sources, binded) + binded = nil + end + if not isContinuedDoc(doc, nextDoc) + and not isTailComment(text, nextDoc) then + bindDoc(sources, binded) + binded = nil + end end end - bindDoc(sources, binded) end return function (state) |