echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
5.07k stars 185 forks source link

[mini.doc] `---@module` is included in automated documentation strangely #1228

Closed ColinKennedy closed 3 weeks ago

ColinKennedy commented 3 weeks ago

Contributing guidelines

Module(s)

mini.doc

Description

Related to https://github.com/echasnovski/mini.nvim/issues/1227

A lua file such as

--- *my_module*
---
--- Some module with text!
---
---@module 'my_module'

local M = {}

--- Do something.
---@param value string Some text.
---@return number? # A value.
function M.to_number(value)
    return tonumber(value)
end

return M

Ends up looking this this

==============================================================================
------------------------------------------------------------------------------
*my_module*

Some module with text!

'my_module'

------------------------------------------------------------------------------
                                                                 *M.to_number()*
                             `M.to_number`({value})
Do something.
Parameters ~
{value} `(string)` Some text.
Return ~
`(number)` `(optional)` # A value.

 vim:tw=78:ts=8:noet:ft=help:norl:

The documentation of mini.doc recommends *Foo* syntax for defining module names (which does syntax-highlight in vimdocs as expected) so I see this extra 'my_module' as an unintended extra. It'd be nice to have mini.doc ignore these ---@module 'foo.' lines and incorporate them more holistically (see https://github.com/echasnovski/mini.nvim/issues/1227 for details)

Neovim version

NVIM v0.11.0-dev-345+g3e6cec0be

Steps to reproduce

  1. nvim -nu minimal.lua
  2. Open the example file
    
    --- *my_module*
    ---
    --- Some module with text!
    ---
    ---@module 'my_module'

local M = {}

--- Do something. ---@param value string Some text. ---@return number? # A value. function M.to_number(value) return tonumber(value) end

return M


3. Call `:lua require("mini.doc").generate({vim.fn.expand("%:p")}, "/tmp/out2.txt", {})`
4. View the resulting `"/tmp/out2.txt"` file

### Expected behavior

The line that contains `---@module 'foo.bar.fizz.buzz'` is not rendered in the output. And possibly the newlines leading up to it removed as well unless there's non-whitespace comment lines after it. Basically pretend it isn't there.

### Actual behavior

The `@module` annotation gets stripped and its remaining text is accidentally in the output.
echasnovski commented 3 weeks ago

Thanks for the issue!

This works as expected. The reason this happens is because @module annotation does not have a recognized section hook. It means that this is not recognized as a separate section, but as a continuation of the previously detected section (in the example above it is all the text from the start of the block which has default section id, i.e. @text).

To process @module attribute as a separate section, I'd suggest the following:


Closing as currently working as expected and might be resolved as part of #1227.