From d87ecfc8bc3c737e2e7f766d365e67dd08c3b600 Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Thu, 30 May 2024 13:11:21 -0400 Subject: docs(luacats): add tuple support --- test/functional/script/luacats_grammar_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/script/luacats_grammar_spec.lua') diff --git a/test/functional/script/luacats_grammar_spec.lua b/test/functional/script/luacats_grammar_spec.lua index 6d444e1888..d6fff3f409 100644 --- a/test/functional/script/luacats_grammar_spec.lua +++ b/test/functional/script/luacats_grammar_spec.lua @@ -159,4 +159,11 @@ describe('luacats grammar', function() name = 'type', type = '`T`', }) + + test('@param type [number,string] this is a tuple type', { + desc = 'this is a tuple type', + kind = 'param', + name = 'type', + type = '[number,string]', + }) end) -- cgit From 9eb0426002696fba4a7c5b9cadd8799a8ae18e6a Mon Sep 17 00:00:00 2001 From: Ilia Choly Date: Fri, 31 May 2024 11:47:32 -0400 Subject: fix(luacats): allow all types inside tuples --- test/functional/script/luacats_grammar_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/script/luacats_grammar_spec.lua') diff --git a/test/functional/script/luacats_grammar_spec.lua b/test/functional/script/luacats_grammar_spec.lua index d6fff3f409..9c6417f7bf 100644 --- a/test/functional/script/luacats_grammar_spec.lua +++ b/test/functional/script/luacats_grammar_spec.lua @@ -160,10 +160,10 @@ describe('luacats grammar', function() type = '`T`', }) - test('@param type [number,string] this is a tuple type', { + test('@param type [number,string,"good"|"bad"] this is a tuple type', { desc = 'this is a tuple type', kind = 'param', name = 'type', - type = '[number,string]', + type = '[number,string,"good"|"bad"]', }) end) -- cgit From 385fbfb3e739b457027b469782678f86eefdf7fc Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Thu, 3 Oct 2024 10:45:51 +0000 Subject: docs: improve luacats support #30580 Some composite/compound types even as basic as `(string|number)[]` are not currently supported by the luacats LPEG grammar used by gen_vimdoc. It would be parsed & rendered as just `string|number`. Changeset adds better support for these types. --- test/functional/script/luacats_grammar_spec.lua | 118 ++++++++++++++++++++++++ 1 file changed, 118 insertions(+) (limited to 'test/functional/script/luacats_grammar_spec.lua') diff --git a/test/functional/script/luacats_grammar_spec.lua b/test/functional/script/luacats_grammar_spec.lua index 9c6417f7bf..8bc55879d4 100644 --- a/test/functional/script/luacats_grammar_spec.lua +++ b/test/functional/script/luacats_grammar_spec.lua @@ -166,4 +166,122 @@ describe('luacats grammar', function() name = 'type', type = '[number,string,"good"|"bad"]', }) + + test('@class vim.diagnostic.JumpOpts', { + kind = 'class', + name = 'vim.diagnostic.JumpOpts', + }) + + test('@class vim.diagnostic.JumpOpts : vim.diagnostic.GetOpts', { + kind = 'class', + name = 'vim.diagnostic.JumpOpts', + parent = 'vim.diagnostic.GetOpts', + }) + + test('@param opt? { cmd?: string[] } Options', { + kind = 'param', + name = 'opt?', + type = '{ cmd?: string[] }', + desc = 'Options', + }) + + ---@type [string, string?][] + local test_cases = { + { 'foo' }, + { 'foo ', 'foo' }, -- trims whitespace + { 'true' }, + { 'vim.type' }, + { 'vim-type' }, + { 'vim_type' }, + { 'foo.bar-baz_baz' }, + { '`ABC`' }, + { '42' }, + { '-42' }, + { '(foo)', 'foo' }, -- removes unnecessary parens + { 'true?' }, + { '(true)?' }, + { 'string[]' }, + { 'string|number' }, + { '(string)[]' }, + { '(string|number)[]' }, + { 'coalesce??', 'coalesce?' }, -- removes unnecessary ? + { 'number?|string' }, + { "'foo'|'bar'|'baz'" }, + { '"foo"|"bar"|"baz"' }, + { '(number)?|string' }, -- + { 'number[]|string' }, + { 'string[]?' }, + { 'foo?[]' }, + { 'vim.type?|string? ', 'vim.type?|string?' }, + { 'number[][]' }, + { 'number[][][]' }, + { 'number[][]?' }, + { 'string|integer[][]?' }, + + -- tuples + { '[string]' }, + { '[1]' }, + { '[string, number]' }, + { '[string, number]?' }, + { '[string, number][]' }, + { '[string, number]|string' }, + { '[string|number, number?]' }, + { 'string|[string, number]' }, + { '(true)?|[foo]' }, + { '[fun(a: string):boolean]' }, + + -- dict + { '{[string]:string}' }, + { '{ [ string ] : string }' }, + { '{ [ string|any ] : string }' }, + { '{[string]: string, [number]: boolean}' }, + + -- key-value table + { 'table' }, + { 'table' }, + { 'string|table|boolean' }, + { 'string|table|(boolean)' }, + + -- table literal + { '{foo: number}' }, + { '{foo: string, bar: [number, boolean]?}' }, + { 'boolean|{reverse?:boolean}' }, + { '{ cmd?: string[] }' }, + + -- function + { 'fun(a: string, b:foo|bar): string' }, + { 'fun(a?: string): string' }, + { 'fun(a?: string): number?,string?' }, + { '(fun(a: string, b:foo|bar): string)?' }, + { 'fun(a: string, b:foo|bar): string, string' }, + { 'fun(a: string, b:foo|bar)' }, + { 'fun(_, foo, bar): string' }, + { 'fun(...): number' }, + { 'fun( ... ): number' }, + { 'fun(...:number): number' }, + { 'fun( ... : number): number' }, + + -- generics + { 'elem_or_list' }, + { + 'elem_or_list', + nil, + }, + } + + for _, tc in ipairs(test_cases) do + local ty, exp_ty = tc[1], tc[2] + if exp_ty == nil then + exp_ty = ty + end + + local var, desc = 'x', 'some desc' + local param = string.format('@param %s %s %s', var, ty, desc) + test(param, { + kind = 'param', + name = var, + type = exp_ty, + desc = desc, + }) + end end) -- cgit