diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2024-01-10 10:34:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-10 10:34:15 +0800 |
commit | cff4d48818d308535d865bce8a3a93b82a5404c6 (patch) | |
tree | fec3d69437de0c7405ee47d466c44200bcb22a31 /script/parser/luadoc.lua | |
parent | ded415e393cf77c27f1a053f914ea040b1a0955b (diff) | |
parent | 94a1cef1100621082b7f56d0a0fdd46c0662a79f (diff) | |
download | lua-language-server-cff4d48818d308535d865bce8a3a93b82a5404c6.zip |
Merge pull request #2472 from fesily/plugin-add-OnTransformAst
plugin: add OnTransformAst interface
Diffstat (limited to 'script/parser/luadoc.lua')
-rw-r--r-- | script/parser/luadoc.lua | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index d7338918..64394e92 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1964,6 +1964,14 @@ local function bindDocWithSources(sources, binded) bindGeneric(binded) bindCommentsAndFields(binded) bindReturnIndex(binded) + + -- doc is special node + if lastDoc.special then + if bindDoc(lastDoc.special, binded) then + return + end + end + local row = guide.rowColOf(lastDoc.finish) local suc = bindDocsBetween(sources, binded, guide.positionOf(row, 0), lastDoc.start) if not suc then @@ -1999,7 +2007,8 @@ local function bindDocs(state) binded = nil else local nextDoc = state.ast.docs[i+1] - if not isNextLine(doc, nextDoc) then + if nextDoc and nextDoc.special + or not isNextLine(doc, nextDoc) then bindDocWithSources(sources, binded) binded = nil end @@ -2028,7 +2037,7 @@ local function findTouch(state, doc) end end -return function (state) +local function luadoc(state) local ast = state.ast local comments = state.comms table.sort(comments, function (a, b) @@ -2097,6 +2106,15 @@ return function (state) end end end + + if ast.state.pluginDocs then + for i, doc in ipairs(ast.state.pluginDocs) do + insertDoc(doc, doc.originalComment) + end + table.sort(ast.docs, function (a, b) + return a.start < b.start + end) + end ast.docs.start = ast.start ast.docs.finish = ast.finish @@ -2107,3 +2125,19 @@ return function (state) bindDocs(state) end + +return { + buildAndBindDoc = function (ast, src, comment) + local doc = buildLuaDoc(comment) + if doc then + local pluginDocs = ast.state.pluginDocs or {} + pluginDocs[#pluginDocs+1] = doc + doc.special = src + doc.originalComment = comment + ast.state.pluginDocs = pluginDocs + return true + end + return false + end, + luadoc = luadoc +} |