From 46910e464bfab9992895898b4c1795e494796e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 29 Jun 2022 16:02:15 +0800 Subject: resolve #1248 supports spaces before `--[[@as]]` --- script/parser/luadoc.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'script/parser/luadoc.lua') 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 -- cgit debian/1.2.3+git2.25.1-1-2-gaceb0