From 6d8dbcc0d8ae0368fd6a5f03a9b269b7396b4900 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Mon, 21 Dec 2020 11:33:48 +0800 Subject: =?UTF-8?q?=E5=A4=84=E7=90=86luadoc=E5=9C=A8=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E6=83=85=E5=86=B5=E7=BB=91=E5=AE=9A=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/parser/guide.lua | 9 +++++---- script/parser/luadoc.lua | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'script') diff --git a/script/parser/guide.lua b/script/parser/guide.lua index a6b11744..0ff77b4b 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -588,20 +588,21 @@ end ---@param lines table ---@return integer {name = 'row'} ---@return integer {name = 'col'} +---@return table {name = 'line'} 命中那一行的细节信息 function m.positionOf(lines, offset) if offset < 1 then - return 0, 0 + return 0, 0, nil end local lastLine = lines[#lines] if offset > lastLine.finish then - return #lines, lastLine.finish - lastLine.start + 1 + return #lines, lastLine.finish - lastLine.start + 1, lastLine end local min = 1 local max = #lines for _ = 1, 100 do if max <= min then local line = lines[min] - return min, offset - line.start + 1 + return min, offset - line.start + 1, line end local row = (max - min) // 2 + min local line = lines[row] @@ -610,7 +611,7 @@ function m.positionOf(lines, offset) elseif offset > line.finish then min = row + 1 else - return row, offset - line.start + 1 + return row, offset - line.start + 1, line end end error('Stack overflow!') diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index ae644a65..9a836da3 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -907,11 +907,21 @@ local function buildLuaDoc(comment) return result end +---当前行在注释doc前是否有代码 +local function haveCodeBeforeDocInCurLine(lineData, docStartCol) + return docStartCol > lineData.sp + lineData.tab + 3 +end + local function isNextLine(lns, binded, doc) if not binded then return false end local lastDoc = binded[#binded] + local _, lastDocStartCol, lastDocStartLine = guide.positionOf(lns, lastDoc.originalComment.start) + if haveCodeBeforeDocInCurLine(lastDocStartLine, lastDocStartCol) then + return false + end + local lastRow = guide.positionOf(lns, lastDoc.finish) local newRow = guide.positionOf(lns, doc.start) return newRow - lastRow == 1 @@ -1034,6 +1044,7 @@ return function (_, state) if ast.finish < doc.finish then ast.finish = doc.finish end + doc.originalComment = comment end end -- cgit v1.2.3