Skip to content

Commit 03ea989

Browse files
committed
Add lua:autoclass and others
1 parent 02703ee commit 03ea989

File tree

11 files changed

+591
-127
lines changed

11 files changed

+591
-127
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## [unreleased]
44

5+
- Added `autodata`, `autoattribute`, `autoclass`, and other `auto*` directives.
6+
7+
They work like `autoobject`, but apply their doctype to the documented object
8+
(if `!doctype` was set in source code, it shouldn't conflict with the used directive).
9+
10+
They also allow overriding object's signature, which may be useful when
11+
automatically generated signature is too long.
12+
513
## [3.4.0]
614

715
- **Potential breaking change:** use `confdir` instead of `srcdir` as base path

docs/source/autodoc.rst

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ can be slightly different:
165165
}
166166
167167
168-
Autodoc directive
169-
-----------------
168+
Autodoc directives
169+
------------------
170170

171171
.. rst:directive:: .. lua:autoobject:: name
172172
@@ -175,57 +175,57 @@ Autodoc directive
175175
:rst:dir:`lua:autoobject` supports same settings as other lua directives,
176176
as well as some additional ones:
177177

178-
.. rst:directive:option:: members
178+
.. rst:directive:option:: members: [<name>, ...]
179179
180180
If enabled, autodoc will also document object's members. You can pass a list
181181
of comma-separated names to specify which members should be documented.
182182
Otherwise, this option will document all public non-special members
183183
which have a description.
184184
185-
.. rst:directive:option:: undoc-members
185+
.. rst:directive:option:: undoc-members: [<name>, ...]
186186
187187
Include undocumented members to the object's description. By default,
188188
they are skipped even if :rst:dir:`members <lua:autoobject:members>` is passed.
189189
190190
Accepts a comma-separated list of names; if list is empty,
191191
adds all undoc members.
192192
193-
.. rst:directive:option:: private-members
194-
protected-members
195-
package-members
193+
.. rst:directive:option:: private-members: [<name>, ...]
194+
protected-members: [<name>, ...]
195+
package-members: [<name>, ...]
196196
197197
Include non-public members to the object's description.
198198
199199
Accepts a comma-separated list of names; if list is empty,
200200
adds all non-public members.
201201
202-
.. rst:directive:option:: special-members
202+
.. rst:directive:option:: special-members: [<name>, ...]
203203
204204
Include members whose names start with double underscore
205205
to the object's description.
206206
207207
Accepts a comma-separated list of names; if list is empty,
208208
adds all special members.
209209
210-
.. rst:directive:option:: inherited-members
210+
.. rst:directive:option:: inherited-members: [<name>, ...]
211211
212212
For classes, include members inherited from base classes.
213213
214214
Accepts a comma-separated list of names; if list is empty,
215215
adds all inherited members.
216216
217-
.. rst:directive:option:: exclude-members
217+
.. rst:directive:option:: exclude-members: [<name>, ...]
218218
219219
A comma-separated list of members that should not be documented.
220220
221-
.. rst:directive:option:: globals
221+
.. rst:directive:option:: globals: [<name>, ...]
222222
223223
Will include global variables declared in the corresponding module.
224224
225225
Accepts a comma-separated list of names; if list is empty,
226226
adds all global variables.
227227
228-
.. rst:directive:option:: class-doc-from
228+
.. rst:directive:option:: class-doc-from: class | ctor | both | separate
229229
230230
Specifies how to generate documentation for classes
231231
if :py:data:`class_default_function_name` is configured.
@@ -242,7 +242,7 @@ Autodoc directive
242242
- ``separate``: only use documentation from ``@class`` annotation,
243243
document class constructor as a separate method.
244244
245-
.. rst:directive:option:: class-signature
245+
.. rst:directive:option:: class-signature: bases | ctor | both | minimal
246246
247247
Specifies how to generate signatures for classes
248248
if :py:data:`class_default_function_name` is configured.
@@ -302,7 +302,7 @@ Autodoc directive
302302
(see :py:data:`lua_ls_default_options` for info on ``+``
303303
and overriding defaults).
304304
305-
.. rst:directive:option:: member-order
305+
.. rst:directive:option:: member-order: alphabetical | groupwise | bysource
306306
307307
Controls how members are sorted. There are three options available:
308308
@@ -314,11 +314,11 @@ Autodoc directive
314314
- ``bysource``: members are sorted in the same order as they appear in code.
315315
This is the default option.
316316
317-
.. rst:directive:option:: module-member-order
317+
.. rst:directive:option:: module-member-order: alphabetical | groupwise | bysource
318318
319319
Overrides :rst:dir:`lua:autoobject:member-order` for modules.
320320
321-
.. rst:directive:option:: title
321+
.. rst:directive:option:: title: <text>
322322
323323
For modules, controls whether a title is inserted between module description
324324
and documentation of its members.
@@ -327,15 +327,15 @@ Autodoc directive
327327
328328
Adds :rst:dir:`lua:autoindex` to the toplevel module.
329329
330-
.. rst:directive:option:: index-title
330+
.. rst:directive:option:: index-title: <text>
331331
332332
Allows overriding title of the :rst:dir:`lua:autoindex` section.
333333
334334
.. rst:directive:option:: inherited-members-table
335335
336336
Adds :rst:dir:`lua:other-inherited-members` to all classes.
337337
338-
.. rst:directive:option:: annotate-require
338+
.. rst:directive:option:: annotate-require: always | never | auto | force
339339
340340
Adds information about how to require a module.
341341
@@ -355,16 +355,51 @@ Autodoc directive
355355
356356
LuaLs only supports ``never`` and ``force``.
357357
358-
.. rst:directive:option:: require-function-name
358+
.. rst:directive:option:: require-function-name: <name>
359359
360360
Allows overriding name of the `require` function
361361
for :rst:dir:`lua:autoobject:annotate-require`.
362362
363-
.. rst:directive:option:: require-separator
363+
.. rst:directive:option:: require-separator: <str>
364364
365365
Allows overriding separator
366366
for :rst:dir:`lua:autoobject:annotate-require`.
367367
368+
.. rst:directive:: .. lua:auto*::
369+
370+
In addition to :rst:dir:`lua:autoobject`, there are ``lua:autodata``,
371+
``lua:autoattribute``, ``lua:autoclass``, and other ``lua:auto*`` directives.
372+
373+
They work like ``lua:autoobject``, but apply their doctype to the documented object
374+
(if ``!doctype`` was :ref:`set in source code <doc_comments>`,
375+
it shouldn't conflict with the used directive).
376+
377+
They also allow overriding object's signature, which may be useful when
378+
automatically generated signature is too long:
379+
380+
.. tab-set::
381+
:sync-group: lang
382+
383+
.. tab-item:: RST
384+
:sync: rst
385+
386+
.. code-block:: rst
387+
388+
.. lua:autofunction:: logging.getLogger(name: string?): logging.Logger
389+
390+
.. tab-item:: Markdown
391+
:sync: md
392+
393+
.. code-block:: myst
394+
395+
```{lua:autofunction} logging.getLogger(name: string? = ...): logging.Logger
396+
```
397+
398+
.. dropdown:: Example output
399+
400+
.. lua:autofunction:: logging.getLogger(name: string? = ...): logging.Logger
401+
:no-index:
402+
368403
.. rst:directive:: .. lua:autoindex:: module-name
369404
370405
Creates a table that references all documented objects in the module ``module-name``.
@@ -387,6 +422,7 @@ Autodoc directive
387422
If given, class name must be absolute, even if this directive appears after
388423
:rst:dir:`lua:module`.
389424

425+
.. _doc_comments:
390426

391427
Controlling generation from code comments
392428
-----------------------------------------

docs/source/directives.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,13 @@ Parameters
283283
All directives that document Lua objects accept the standard parameters:
284284

285285
.. rst:directive:option:: no-index
286+
no-index-entry
287+
no-contents-entry
288+
no-typesetting
286289
287-
Render the documentation, but don't add it to the index
288-
and don't create anchors. You will not be able to reference
289-
un-indexed objects.
290+
The `standard Sphinx options`__ available to all object descriptions.
291+
292+
__ https://www.sphinx-doc.org/en/master/usage/domains/index.html#basic-markup
290293
291294
.. rst:directive:option:: private
292295
protected
@@ -329,7 +332,7 @@ All directives that document Lua objects accept the standard parameters:
329332
330333
Fetches content from the given url.
331334
332-
.. rst:directive:option:: annotation
335+
.. rst:directive:option:: annotation: <text>
333336
334337
Allows adding custom short annotations.
335338
@@ -384,12 +387,12 @@ All directives that document Lua objects accept the standard parameters:
384387
385388
Use ``name`` and ``surname`` instead.
386389
387-
.. rst:directive:option:: synopsis
390+
.. rst:directive:option:: synopsis: <text>
388391
389392
Allows adding a small description that's reflected
390393
in the :rst:dir:`lua:autoindex` output.
391394
392-
.. rst:directive:option:: module
395+
.. rst:directive:option:: module: <name>
393396
394397
Allows overriding current module for a single object. This is useful
395398
for documenting global variables that are declared in a module.

docs/source/example/logging.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ function logging.Logger:warning(msg, ...) end
5858
--- @param ... any parameters for message formatting.
5959
function logging.Logger:error(msg, ...) end
6060

61+
--- Get logger with the given name, or create one if it doesn't exist.
62+
---
63+
--- @param name string? logger name. Uses current module name if empty.
64+
--- @return Logger logger logger with the given name.
65+
function logging.getLogger(name) end
66+
6167
return logging

sphinx_lua_ls/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,42 @@ def setup(app: sphinx.application.Sphinx):
203203
app.add_directive_to_domain(
204204
"lua", "autoobject", sphinx_lua_ls.autodoc.AutoObjectDirective
205205
)
206+
app.add_directive_to_domain(
207+
"lua", "autofunction", sphinx_lua_ls.autodoc.AutoFunctionDirective
208+
)
209+
app.add_directive_to_domain(
210+
"lua", "autodata", sphinx_lua_ls.autodoc.AutoDataDirective
211+
)
212+
app.add_directive_to_domain(
213+
"lua", "autoconst", sphinx_lua_ls.autodoc.AutoConstDirective
214+
)
215+
app.add_directive_to_domain(
216+
"lua", "autoclass", sphinx_lua_ls.autodoc.AutoClassDirective
217+
)
218+
app.add_directive_to_domain(
219+
"lua", "autoalias", sphinx_lua_ls.autodoc.AutoAliasDirective
220+
)
221+
app.add_directive_to_domain(
222+
"lua", "autoenum", sphinx_lua_ls.autodoc.AutoEnumDirective
223+
)
224+
app.add_directive_to_domain(
225+
"lua", "automethod", sphinx_lua_ls.autodoc.AutoMethodDirective
226+
)
227+
app.add_directive_to_domain(
228+
"lua", "autoclassmethod", sphinx_lua_ls.autodoc.AutoClassmethodDirective
229+
)
230+
app.add_directive_to_domain(
231+
"lua", "autostaticmethod", sphinx_lua_ls.autodoc.AutoStaticmethodDirective
232+
)
233+
app.add_directive_to_domain(
234+
"lua", "autoattribute", sphinx_lua_ls.autodoc.AutoAttributeDirective
235+
)
236+
app.add_directive_to_domain(
237+
"lua", "autotable", sphinx_lua_ls.autodoc.AutoTableDirective
238+
)
239+
app.add_directive_to_domain(
240+
"lua", "automodule", sphinx_lua_ls.autodoc.AutoModuleDirective
241+
)
206242
app.add_directive_to_domain(
207243
"lua", "autoindex", sphinx_lua_ls.autoindex.AutoIndexDirective
208244
)

0 commit comments

Comments
 (0)