tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
411 stars 52 forks source link

Treesitter is unable to parse `.jsx` files after seing a `jsx` block in markdown #106

Closed primeapple closed 11 months ago

primeapple commented 1 year ago

Describe the bug After opening a markdown buffer with .jsx codeblocks, Treesitter can't parse new .jsx buffers anymore.

STR:

  1. Have javscript, markdown and markdown_inline TS Parsers installed in Neovim
  2. create file test.jsx
    export const abc = () => {
    return <div>hello</div>;
    };
  3. create file test.md, look at code example below (without the _)
  4. nvim test.md
  5. :e test.jsx, see that jsx is not getting parsed by treesitter

Code example

This is a fun component description:

```jsx
import { Form } from 'somewhere';

<Form>
    {123}
</Form>
``_`
Ignore the `_` above

Expected behavior Highlight the code snippet as jsx codes

Actual behavior No highlighting is applied, even worse, Treesitter does not parse .jsx files from now on anymore.

Infos I found this here: https://github.com/nvim-treesitter/nvim-treesitter/issues/4918 Removing markdown and markdown_inline TS Parsers fixes this issue, so I came here :)

MDeiml commented 1 year ago

I don't use neovim any more so I don't have it set up to test this. But this seems to work fine in other editors, so I would guess it's a problem of nvim-treesitter.

Removing markdown and markdown_inline TS Parsers fixes this issue

You're saying standalone .jsx files are not parsed correctly when a markdown jsx code block is active in another file, but they are parsed correctly when the markdown parser is not installed?

(Btw you can have nested code blocks in markdown by giving the outer code block more `s: like this

````markdown
Text in outer code block
```jsx
// Comment in inner code block

)

primeapple commented 1 year ago

You're saying standalone .jsx files are not parsed correctly when a markdown jsx code block is active in another file, but they are parsed correctly when the markdown parser is not installed?

Exactly. When uninstalling the markdown parser, there is no problem when opening jsx files while having open markdown buffers.

Thanks for investigating. I realized that jsx blocks in markdown are not correctly recognized/parsed yet, may this be the issue?

MDeiml commented 1 year ago

I think there's some kind of support for that in nvim-treesitter. Best you ask there

schardev commented 1 year ago

Removing markdown and markdown_inline TS Parsers fixes this issue

Can confirm the same. Uninstalling them works and I no longer get that error.

llllvvuu commented 1 year ago

It's a Neovim issue. I have one merged (https://github.com/neovim/neovim/pull/25151) and one open (https://github.com/neovim/neovim/pull/25143) PR to resolve it.

This can be closed