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 /test/plugins/ast | |
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 'test/plugins/ast')
-rw-r--r-- | test/plugins/ast/test.lua | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/test/plugins/ast/test.lua b/test/plugins/ast/test.lua index 95e87694..a01b9e2e 100644 --- a/test/plugins/ast/test.lua +++ b/test/plugins/ast/test.lua @@ -3,11 +3,14 @@ local guide = require 'parser.guide' local helper = require 'plugins.astHelper' ---@diagnostic disable: await-in-sync -local function TestPlugin(script, plugin, checker) +---@param ... function checkers +local function TestPlugin(script, plugin, ...) local state = parser.compile(script, "Lua", "Lua 5.4") state.ast = plugin(TESTURI, state.ast) or state.ast parser.luadoc(state) - checker(state) + for i = 1, select('#', ...) do + select(i, ...)(state) + end end local function isDocClass(ast) @@ -62,6 +65,47 @@ local function TestSelfIsClass(state, next) end) end +local function TestAHasField(state, next) + local foundFields = false + local cb = function (source) + if not source.bindDocs or not source.bindDocs[1].class or source.bindDocs[1].class[1] ~= "A" then + return + end + assert(#source.bindDocs == 1) + assert(#source.bindDocs[1].fields >= 2) + assert(source.bindDocs[1].fields[1].field[1] == "x") + assert(source.bindDocs[1].fields[2].field[1] == "y") + foundFields = true + end + guide.eachSourceType(state.ast, "local", cb) + guide.eachSourceType(state.ast, "setglobal", cb) + assert(foundFields) +end + +local function plugin_AddMultipleDocs(uri, ast) + guide.eachSourceType(ast, "call", function(source) + local node = source.node + if guide.getKeyName(node) ~= 'Class' then + return + end + local wants = { + ['local'] = true, + ['setglobal'] = true + } + local classnameNode = guide.getParentTypes(source, wants) + if not classnameNode then + return + end + local classname = guide.getKeyName(classnameNode) + if classname then + local group = {} + helper.addClassDoc(ast, classnameNode, classname, group) + helper.addDoc(ast, classnameNode, "field", "x number", group) + helper.addDoc(ast, classnameNode, "field", "y string", group) + end + end) +end + local function TestPlugin1(script) TestPlugin(script, plugin_AddClass, TestAIsClass) end @@ -70,6 +114,10 @@ local function TestPlugin2(script) TestPlugin(script, plugin_AddClassAtParam, TestSelfIsClass) end +local function TestPlugin3(script) + TestPlugin(script, plugin_AddMultipleDocs, TestAIsClass, TestAHasField) +end + TestPlugin1 [[ local A = Class(function() end) ]] @@ -86,4 +134,12 @@ TestPlugin2 [[ function ctor(self) end ]] +TestPlugin3 [[ + local A = Class() +]] + +TestPlugin3 [[ + A = Class() +]] + require 'plugins.ast.helper' |