diff options
author | Paul Emmerich <tandanu@deadlybossmods.com> | 2024-01-28 13:08:48 +0100 |
---|---|---|
committer | Paul Emmerich <tandanu@deadlybossmods.com> | 2024-01-28 13:08:48 +0100 |
commit | 1a1e671b0abd0380d4bd02f7adabda023bda9a64 (patch) | |
tree | 67b7e7ee059a1fcdc11fd44e76a6ceb079a2a8dd /script | |
parent | 9185dfad1286942b4914657e4c0e9ad28cb2aaa8 (diff) | |
download | lua-language-server-1a1e671b0abd0380d4bd02f7adabda023bda9a64.zip |
Add group param for luadoc generated by plugins
This allows binding multiple generated luadoc annotations to a single
node easily by explicitly specifying their bind group.
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/luadoc.lua | 8 | ||||
-rw-r--r-- | script/plugins/astHelper.lua | 23 |
2 files changed, 24 insertions, 7 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 227808a0..c59bc5c1 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -2002,7 +2002,10 @@ local function bindDocs(state) state.ast.docs.groups[#state.ast.docs.groups+1] = binded end binded[#binded+1] = doc - if isTailComment(text, doc) then + if doc.specialBindGroup then + bindDocWithSources(sources, doc.specialBindGroup) + binded = nil + elseif isTailComment(text, doc) and doc.type ~= "doc.class" and doc.type ~= "doc.field" then bindDocWithSources(sources, binded) binded = nil else @@ -2130,7 +2133,7 @@ local function luadoc(state) end return { - buildAndBindDoc = function (ast, src, comment) + buildAndBindDoc = function (ast, src, comment, group) local doc = buildLuaDoc(comment) if doc then local pluginDocs = ast.state.pluginDocs or {} @@ -2138,6 +2141,7 @@ return { doc.special = src doc.originalComment = comment doc.virtual = true + doc.specialBindGroup = group ast.state.pluginDocs = pluginDocs return doc end diff --git a/script/plugins/astHelper.lua b/script/plugins/astHelper.lua index 506f5e92..bfe2dd27 100644 --- a/script/plugins/astHelper.lua +++ b/script/plugins/astHelper.lua @@ -23,14 +23,27 @@ end ---@param ast parser.object ---@param source parser.object local/global variable ---@param classname string -function _M.addClassDoc(ast, source, classname) +---@param group table? +function _M.addClassDoc(ast, source, classname, group) + return _M.addDoc(ast, source, "class", classname, group) +end + +--- give the local/global variable a luadoc comment +---@param ast parser.object +---@param source parser.object local/global variable +---@param key string +---@param value string +---@param group table? +function _M.addDoc(ast, source, key, value, group) if source.type ~= 'local' and not guide.isGlobal(source) then return false end - --TODO fileds - --TODO callers - local comment = _M.buildComment("class", classname, source.start - 1) - return luadoc.buildAndBindDoc(ast, source, comment) + local comment = _M.buildComment(key, value, source.start - 1) + local doc = luadoc.buildAndBindDoc(ast, source, comment, group) + if group then + group[#group+1] = doc + end + return doc end ---remove `ast` function node `index` arg, the variable will be the function local variable |