summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorLei Zhu <uhziel@gmail.com>2020-12-21 12:37:36 +0800
committerLei Zhu <uhziel@gmail.com>2020-12-21 12:37:36 +0800
commitb397ee1e604452fd0a66f8495d5271fda5db4d21 (patch)
tree7a9c5c378b52f30d8da5ed40efda54345767e5b1 /script
parent6d8dbcc0d8ae0368fd6a5f03a9b269b7396b4900 (diff)
downloadlua-language-server-b397ee1e604452fd0a66f8495d5271fda5db4d21.zip
获取lineData信息改为使用单独的接口,而不是修改positionOf()的返回值
Diffstat (limited to 'script')
-rw-r--r--script/parser/guide.lua13
-rw-r--r--script/parser/luadoc.lua5
2 files changed, 11 insertions, 7 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 0ff77b4b..60ef1ee4 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -588,21 +588,20 @@ 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, nil
+ return 0, 0
end
local lastLine = lines[#lines]
if offset > lastLine.finish then
- return #lines, lastLine.finish - lastLine.start + 1, lastLine
+ return #lines, lastLine.finish - lastLine.start + 1
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, line
+ return min, offset - line.start + 1
end
local row = (max - min) // 2 + min
local line = lines[row]
@@ -611,7 +610,7 @@ function m.positionOf(lines, offset)
elseif offset > line.finish then
min = row + 1
else
- return row, offset - line.start + 1, line
+ return row, offset - line.start + 1
end
end
error('Stack overflow!')
@@ -665,6 +664,10 @@ function m.lineRange(lines, row, ignoreNL)
end
end
+function m.lineData(lines, row)
+ return lines[row]
+end
+
function m.getKeyTypeOfLiteral(obj)
if not obj then
return nil
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 9a836da3..cd4e76a9 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -917,8 +917,9 @@ local function isNextLine(lns, binded, doc)
return false
end
local lastDoc = binded[#binded]
- local _, lastDocStartCol, lastDocStartLine = guide.positionOf(lns, lastDoc.originalComment.start)
- if haveCodeBeforeDocInCurLine(lastDocStartLine, lastDocStartCol) then
+ local lastDocStartRow, lastDocStartCol = guide.positionOf(lns, lastDoc.originalComment.start)
+ local lastDocStartLineData = guide.lineData(lns, lastDocStartRow)
+ if haveCodeBeforeDocInCurLine(lastDocStartLineData, lastDocStartCol) then
return false
end