diff options
-rw-r--r-- | script/core/code-action.lua | 2 | ||||
-rw-r--r-- | script/core/completion.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/newfield-call.lua | 4 | ||||
-rw-r--r-- | script/core/diagnostics/newline-call.lua | 4 | ||||
-rw-r--r-- | script/core/keyword.lua | 4 | ||||
-rw-r--r-- | script/core/type-formatting.lua | 2 | ||||
-rw-r--r-- | script/files.lua | 2 | ||||
-rw-r--r-- | script/parser/guide.lua | 4 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 42 | ||||
-rw-r--r-- | script/parser/newparser.lua | 7 | ||||
-rw-r--r-- | script/vm/getDocs.lua | 2 | ||||
-rw-r--r-- | test/example/guide.txt | 4 |
12 files changed, 40 insertions, 39 deletions
diff --git a/script/core/code-action.lua b/script/core/code-action.lua index 1bac9359..922ebff3 100644 --- a/script/core/code-action.lua +++ b/script/core/code-action.lua @@ -57,7 +57,7 @@ end local function disableDiagnostic(uri, code, start, results) local lines = files.getLines(uri) - local row = guide.positionOf(start) + local row = guide.rowColOf(start) results[#results+1] = { title = lang.script('ACTION_DISABLE_DIAG', code), kind = 'quickfix', diff --git a/script/core/completion.lua b/script/core/completion.lua index 59dc19f3..1b64bef1 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -176,7 +176,7 @@ local function getSnip(source) if vm.isMetaFile(uri) then goto CONTINUE end - local row = guide.positionOf(def.start) + local row = guide.rowColOf(def.start) local firstRow = lines[row] local lastRow = lines[math.min(row + context - 1, #lines)] local snip = text:sub(firstRow.start, lastRow.finish) diff --git a/script/core/diagnostics/newfield-call.lua b/script/core/diagnostics/newfield-call.lua index 61d52dd2..83d205ca 100644 --- a/script/core/diagnostics/newfield-call.lua +++ b/script/core/diagnostics/newfield-call.lua @@ -27,8 +27,8 @@ return function (uri, callback) local func = call.node local args = call.args if args then - local funcLine = guide.positionOf(func.finish) - local argsLine = guide.positionOf(args.start) + local funcLine = guide.rowColOf(func.finish) + local argsLine = guide.rowColOf(args.start) if argsLine > funcLine then callback { start = call.start, diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua index 69bf948f..1c31fa8d 100644 --- a/script/core/diagnostics/newline-call.lua +++ b/script/core/diagnostics/newline-call.lua @@ -26,8 +26,8 @@ return function (uri, callback) return end - local nodeRow = guide.positionOf(node.finish) - local argRow = guide.positionOf(args.start) + local nodeRow = guide.rowColOf(node.finish) + local argRow = guide.rowColOf(args.start) if nodeRow == argRow then return end diff --git a/script/core/keyword.lua b/script/core/keyword.lua index 4b43efe5..8e041f1c 100644 --- a/script/core/keyword.lua +++ b/script/core/keyword.lua @@ -275,8 +275,8 @@ until $1" if first == 'end' or first == 'else' or first == 'elseif' then - local startRow = guide.positionOf(info.start) - local finishRow = guide.positionOf(pos) + local startRow = guide.rowColOf(info.start) + local finishRow = guide.rowColOf(pos) local startSp = info.text:match('^%s*', lines[startRow].start + 1) local finishSp = info.text:match('^%s*', lines[finishRow].start + 1) if startSp == finishSp then diff --git a/script/core/type-formatting.lua b/script/core/type-formatting.lua index 12272f11..157a446d 100644 --- a/script/core/type-formatting.lua +++ b/script/core/type-formatting.lua @@ -5,7 +5,7 @@ local guide = require "parser.guide" local function insertIndentation(uri, offset, edits) local lines = files.getLines(uri) local text = files.getOriginText(uri) - local row = guide.positionOf(offset) + local row = guide.rowColOf(offset) local line = lines[row] local indent = text:sub(line.start, line.finish):match '^%s*' for _, edit in ipairs(edits) do diff --git a/script/files.lua b/script/files.lua index 0e62a740..98d9b83c 100644 --- a/script/files.lua +++ b/script/files.lua @@ -744,7 +744,7 @@ function m.position(uri, offset, leftOrRight) lines = m.getOriginLines(uri) text = m.getOriginText(uri) end - local row, col = guide.positionOf(offset) + local row, col = guide.rowColOf(offset) local start, finish = guide.lineRange(lines, row, true) start = start + 1 if col <= finish - start + 1 then diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 941fc7b1..14e19094 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -743,7 +743,7 @@ end ---@param position integer ---@return integer row ---@return integer col -function m.positionOf(position) +function m.rowColOf(position) return position // 10000, position % 10000 end @@ -753,7 +753,7 @@ end ---@param row integer ---@param col integer ---@return integer -function m.offsetOf(row, col) +function m.positionOf(row, col) return row * 10000 + col end diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 533aa9db..548539a9 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1,11 +1,10 @@ local m = require 'lpeglabel' local re = require 'parser.relabel' -local lines = require 'parser.lines' local guide = require 'parser.guide' local grammar = require 'parser.grammar' local TokenTypes, TokenStarts, TokenFinishs, TokenContents -local Ci, Offset, pushError, Ct, NextComment, Lines +local Ci, Offset, pushError, NextComment local parseType local Parser = re.compile([[ Main <- (Token / Sp)* @@ -635,7 +634,7 @@ function parseType(parent) result.finish = getFinish() result.firstFinish = result.finish - local row = guide.positionOf(result.finish) + local row = guide.rowColOf(result.finish) local function pushResume() local comments @@ -644,8 +643,9 @@ function parseType(parent) if not nextComm then return false end - local line = Lines[row + i + 1] - if not line or line.finish < nextComm.start then + local nextCommRow = guide.rowColOf(nextComm.start) + local currentRow = row + i + 1 + if currentRow > nextCommRow then return false end if nextComm.text:sub(1, 2) == '-@' then @@ -1176,9 +1176,9 @@ local function haveCodeBeforeDocInCurLine(text, lineData, docStart) return text:sub(lineData.start + 1, docStart - 1):find '[%w_]' end -local function isTailComment(lns, text, binded, doc) +local function isTailComment(text, binded) local lastDoc = binded[#binded] - local lastDocStartRow = guide.positionOf(lastDoc.originalComment.start) + local lastDocStartRow = guide.rowColOf(lastDoc.originalComment.start) local lastDocStartLineData = guide.lineData(lastDocStartRow) if haveCodeBeforeDocInCurLine(text, lastDocStartLineData, lastDoc.originalComment.start) then return true @@ -1186,13 +1186,13 @@ local function isTailComment(lns, text, binded, doc) return false end -local function isNextLine(lns, text, binded, doc) +local function isNextLine(binded, doc) if not binded then return false end local lastDoc = binded[#binded] - local lastRow = guide.positionOf(lastDoc.finish) - local newRow = guide.positionOf(doc.start) + local lastRow = guide.rowColOf(lastDoc.finish) + local newRow = guide.rowColOf(doc.start) return newRow - lastRow == 1 end @@ -1318,7 +1318,7 @@ local function bindClassAndFields(binded) end end -local function bindDoc(sources, lns, binded) +local function bindDoc(sources, binded) if not binded then return end @@ -1332,12 +1332,10 @@ local function bindDoc(sources, lns, binded) doc.bindSources = bindSources end bindGeneric(binded) - local row = guide.positionOf(lastDoc.finish) - local cstart, cfinish = guide.lineRange(lns, row) - local nstart, nfinish = guide.lineRange(lns, row + 1) - bindDocsBetween(sources, binded, bindSources, cstart, cfinish) + local row = guide.rowColOf(lastDoc.finish) + bindDocsBetween(sources, binded, bindSources, guide.positionOf(row, 0), lastDoc.start) if #bindSources == 0 then - bindDocsBetween(sources, binded, bindSources, nstart, nfinish) + bindDocsBetween(sources, binded, bindSources, guide.positionOf(row + 1, 0), guide.positionOf(row + 2, 0)) end bindParamAndReturnIndex(binded) bindClassAndFields(binded) @@ -1361,18 +1359,18 @@ local function bindDocs(state) end) local binded for _, doc in ipairs(state.ast.docs) do - if not isNextLine(Lines, text, binded, doc) then - bindDoc(sources, Lines, binded) + if not isNextLine(binded, doc) then + bindDoc(sources, binded) binded = {} state.ast.docs.groups[#state.ast.docs.groups+1] = binded end binded[#binded+1] = doc - if isTailComment(Lines, text, binded, doc) then - bindDoc(sources, Lines, binded) + if isTailComment(text, binded) then + bindDoc(sources, binded) binded = nil end end - bindDoc(sources, Lines, binded) + bindDoc(sources, binded) end return function (state) @@ -1389,8 +1387,6 @@ return function (state) pushError = state.pushError - Lines = lines(state.lua) - local ci = 1 NextComment = function (offset, peek) local comment = comments[ci + (offset or 0)] diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index 16bcd6a0..0137397d 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -361,6 +361,7 @@ local function skipNL() Line = Line + 1 LineOffset = Tokens[Index] + #token Index = Index + 2 + State.lines[Line] = LineOffset return true end return false @@ -392,8 +393,11 @@ local function resolveLongString(finishMark) local result, count = stringResult : gsub('\r\n', '\n') : gsub('[\r\n]', '\n') - Line = Line + count LineOffset = lastLN + start + for i = Line + 1, Line + count do + State.lines[i] = LineOffset + end + Line = Line + count stringResult = result end fastForwardToken(finishOffset + #finishMark) @@ -3503,6 +3507,7 @@ local function initState(lua, version, options) errs = {}, diags = {}, comms = {}, + lines = {}, options = options or {}, } if version == 'Lua 5.1' or version == 'LuaJIT' then diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index 5fcf9478..218dc048 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -186,7 +186,7 @@ local function makeDiagRange(uri, doc, results) names[name] = true end end - local row = guide.positionOf(doc.start) + local row = guide.rowColOf(doc.start) if doc.mode == 'disable-next-line' then if lines[row+1] then results[#results+1] = { diff --git a/test/example/guide.txt b/test/example/guide.txt index da8d5c32..cff05faf 100644 --- a/test/example/guide.txt +++ b/test/example/guide.txt @@ -586,7 +586,7 @@ end ---@param lines table ---@return integer {name = 'row'} ---@return integer {name = 'col'} -function m.positionOf(lines, offset) +function m.rowColOf(lines, offset) if offset < 1 then return 0, 0 end @@ -619,7 +619,7 @@ end ---@param row integer ---@param col integer ---@return integer {name = 'offset'} -function m.offsetOf(lines, row, col) +function m.positionOf(lines, row, col) if row < 1 then return 0 end |