neovim / tree-sitter-vimdoc

Tree-sitter parser for Vim help files
Apache License 2.0
97 stars 13 forks source link

codeblock adjacent to list item is not recognized #118

Open echasnovski opened 7 months ago

echasnovski commented 7 months ago

Example:

- Line starts with dash:
>
 This is not recognized as code block
<

This seems to be a known problem, but there is no issue to track it and for users to consult with.

I tried to fix this, but the assumption that code block is not contiguous to list item seems to be too much entangled in the grammar itself. So looks like it would at least require serious refactor if at all possible.

The current workaround is to have a blank link after list item text block (contiguous lines without blank lines with first starting with list prefix). So this will work:

- Line starts with dash:

>
 This is recognized as code block
<
justinmk commented 7 months ago

Looks like Vim's help syntax "supports" this (but it has no concept of list-items, which is a major feature of tree-sitter-vimdoc).

The general idea in tree-sitter-vimdoc is that "blocks" are separated by a blank line. In the given example, the > immediately follows the list-item thus it would be part of the list-item (if this bug didn't exist), not a separate block. But it looks like you expect it to be a separate block?

Note that this does work (in both Vim-syntax and tree-sitter-vimdoc):

- Line starts with dash: >
  code line1
  code line2
<
echasnovski commented 7 months ago

But it looks like you expect it to be a separate block?

I would expect that codeblock formatting would take precedence over list items, yes. Mostly because it is supported in Vim's help and in Markdown.

Note that this does work (in both Vim-syntax and tree-sitter-vimdoc):

Yes, this is a better solution as it allows to add only single blank line at the top of code block (similar to the one in the initial comment). I thought I tried it before and it did not work. Apparently, missed something.

This feels like a decent workaround, though. Now the original example only looks like inconsistency and not like a big issue.

clason commented 3 months ago

Related: ft_sql.txt has stuff like

These are maps which use populate the completion list using Vim's syntax
highlighting rules. >
    <C-C>a
<       - Displays all SQL syntax items. >

(note the inline list item) that is not recognized as codeblock.

I seriously think that we need to significantly tighten up the spec, write the parser for that and only that, and fix the bundled help files once and for all (and make clear to plugins that if they want to have proper rendering in Neovim, they have to follow suit).

justinmk commented 3 months ago

tighten up the spec

meaning that the sample you gave would not be supported? what would the acceptable forms look like?

clason commented 3 months ago

We tend to put such descriptions in comments in the codeblock itself. We could also rewrite this as a proper list or table (which seems more reasonable):

- <C-C>a   Displays all SQL syntax items

(I don't see the point of using a codeblock here.)