hedyhli / outline.nvim

Code outline sidebar powered by LSP. Significantly enhanced & refactored fork of symbols-outline.nvim.
https://sr.ht/~hedy/outline.nvim
MIT License
543 stars 15 forks source link

Add support for vimdoc #76

Open oskarrrrrrr opened 1 month ago

oskarrrrrrr commented 1 month ago

I've added Vimdoc support, the implementation is very similar to that of Norg's. I included headings and tags in the outline, just headings provide very little information.

There seem to be quite a lot of edge cases that could be improved. For example, sometimes there are empty headings or headings that are not actual document headings but table headings. Sometimes there are multiple tags in one line, sometimes in multiple lines (but they refer to the same thing). The formatting seems quite inconsistent, even in the builtin documentation (e.g. the main page marks modeline as heading, other pages seem to get it right...). We could come up with some heuristics for the most common cases, for now I ignored all that.

Example below.

image

I used Variable kind for tags so that they can be easily filtered out.

I've encountered on issue, not sure if my change caused it. When there is a window with help file open and another with, for example, a lua file then the outline sidebar will show outline for the lua file always. For some reason the outline for help files seems to work only for one file and if there is another buffer in the same tab it will take over. Even switching between two help files won't work, the first one will be always shown in the sidebar. Other filetypes seem to work fine. I can try to debug that, but maybe someone has an idea what could be the reason?

Resolves: #34

hedyhli commented 1 month ago

Thanks for this! I'll take a look at it soon.

I've encountered on issue, not sure if my change caused it. When there is a window with help file open and another with, for example, a lua file then the outline sidebar will show outline for the lua file always. For some reason the outline for help files seems to work only for one file and if there is another buffer in the same tab it will take over. Even switching between two help files won't work, the first one will be always shown in the sidebar. Other filetypes seem to work fine. I can try to debug that, but maybe someone has an idea what could be the reason?

Currently outline looks for buflisted option to determine whether the symbols should be refreshed when we switch to a new buffer.

https://github.com/hedyhli/outline.nvim/blob/028e0bc8ad3d511e9fc1f0678594a608eb908ee5/lua/outline/sidebar.lua#L341-L345

This check is only done on "refresh", ie, when the cursor moves or text changed (governed by outline_items.auto_update_events.items), which means it prevents the outline items from updating when the user navigates from the code to things like floating windows (eg, :LspStatus).

I believe it makes sense to special case the help ft here (for instance, only ignore refresh if buflisted is false and ft is not help), now that vimdocs are now supported in outline.nvim.

oskarrrrrrr commented 1 month ago

Thanks, changing this one line fixed the issue.

I got rid of "OutlineHelp" from the condition, because outline help buffer is created with 'buflisted' set to false.

oskarrrrrrr commented 1 month ago

Thanks for your thorough testing -- I didn't encounter these issues during mine. What are some help pages you used that can reproduce this issue?

These are not big issues to be honest and maybe not as common as I initially thought, here are some examples.

Heading with no text (except for the tag):

Screenshot 2024-07-05 at 9 37 06 AM

Three tags in the same line:

Screenshot 2024-07-05 at 9 33 09 AM

Two tags referring to the same thing in multiple lines:

Screenshot 2024-07-05 at 9 41 17 AM

Modeline is a header:

Screenshot 2024-07-05 at 9 33 51 AM

(you can see the help file name in the top left corner)

The examples with tags are not necessarily issues with the help file formatting. It's just that they take a lot of lines in the sidebar. Not a big deal probably.

oskarrrrrrr commented 1 month ago

Here is an example where some tags for a heading are in the line before that heading:

Screenshot 2024-07-05 at 10 07 24 AM