diff options
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/luadoc.lua | 20 | ||||
-rw-r--r-- | script/vm/compiler.lua | 8 |
2 files changed, 24 insertions, 4 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 1e7a6ab3..c2019d8d 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -142,6 +142,7 @@ Symbol <- ({} { ---@field signs parser.object[] ---@field originalComment parser.object ---@field as? parser.object +---@field touch? integer local function trim(str) return str:match '^%s*(%S+)%s*$' @@ -1671,6 +1672,22 @@ local function bindDocs(state) end end +local function findTouch(state, doc) + local text = state.lua + local pos = guide.positionToOffset(state, doc.originalComment.start) + for i = pos - 2, 1, -1 do + local c = text:sub(i, i) + if c == '\r' + or c == '\n' then + break + elseif c ~= ' ' + and c ~= '\t' then + doc.touch = guide.offsetToPosition(state, i) + break + end + end +end + return function (state) local ast = state.ast local comments = state.comms @@ -1714,6 +1731,9 @@ return function (state) ast.finish = doc.finish end doc.originalComment = comment + if comment.type == 'comment.long' then + findTouch(state, doc) + end end end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 549ace71..5a306308 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -585,12 +585,12 @@ local function bindAs(source) ases = {} docs._asCache = ases for _, doc in ipairs(docs) do - if doc.type == 'doc.as' and doc.as then + if doc.type == 'doc.as' and doc.as and doc.touch then ases[#ases+1] = doc end end table.sort(ases, function (a, b) - return a.start < b.start + return a.touch < b.touch end) end @@ -609,7 +609,7 @@ local function bindAs(source) end index = left + (right - left) // 2 local doc = ases[index] - if doc.originalComment.start < source.finish + 2 then + if doc.touch < source.finish then left = index + 1 else right = index @@ -617,7 +617,7 @@ local function bindAs(source) end local doc = ases[index] - if doc and doc.originalComment.start == source.finish + 2 then + if doc and doc.touch == source.finish then vm.setNode(source, vm.compileNode(doc.as), true) return true end |