diff options
author | Lei Zhu <uhziel@gmail.com> | 2020-12-21 11:33:48 +0800 |
---|---|---|
committer | Lei Zhu <uhziel@gmail.com> | 2020-12-21 11:33:48 +0800 |
commit | 6d8dbcc0d8ae0368fd6a5f03a9b269b7396b4900 (patch) | |
tree | 9c1e669858c781b847a5ca0cb3ce23e5a7745ad2 /script | |
parent | cb28b668db32b7afe29c9d01dfcc700b0377e266 (diff) | |
download | lua-language-server-6d8dbcc0d8ae0368fd6a5f03a9b269b7396b4900.zip |
处理luadoc在某些情况绑定错误的情况
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/guide.lua | 9 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 11 |
2 files changed, 16 insertions, 4 deletions
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 |