tree-sitter-grammars / tree-sitter-markdown

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

Unable to get highlighting for tsx in fenced code blocks #99

Closed sQVe closed 10 months ago

sQVe commented 1 year ago

Describe the bug

I've been trying to get highlighting for tsx in fenced code block to work, but I'm failing even-though I have the parser installed.

Code example

const foo = "foo"

<Test value={foo}>
</Test>

Add the above snippet in a fenced code block with ts vs tsx.

Expected behavior Both the fenced code blocks should be highlighted.

Actual behavior Only the ts block is highlighted.

MDeiml commented 1 year ago

This can not be solved here, but only with the editor you are using. Are you using neovim? If so then you can make a PR to nvim-treesitter adding the alias here: https://github.com/nvim-treesitter/nvim-treesitter/blob/680807fa6a482c639119098bc48ca3831c66db13/lua/nvim-treesitter/query_predicates.lua#L10-L16

sQVe commented 1 year ago

This can not be solved here, but only with the editor you are using. Are you using neovim? If so then you can make a PR to nvim-treesitter adding the alias here: https://github.com/nvim-treesitter/nvim-treesitter/blob/680807fa6a482c639119098bc48ca3831c66db13/lua/nvim-treesitter/query_predicates.lua#L10-L16

Awesome. Thank you for pointing me in the right direction. I'll do that. 👌

sQVe commented 1 year ago

@MDeiml I've been looking into this further and your suggestion does, sadly, not work. Since js, jsx, and tsx all match a filetype by vim.filetype.match used in https://github.com/nvim-treesitter/nvim-treesitter/blob/680807fa6a482c639119098bc48ca3831c66db13/lua/nvim-treesitter/query_predicates.lua#L18C1-L21.

It looks like nvim-treesitter properly sets javascriptreact and typescriptreact as the filetypes, but the highlighting is still missing in the fenced markdown code blocks. If you have any further input, that would be greatly appreciated.

MDeiml commented 1 year ago

Hm, I can only speculate then. I guess you checked, that the typescript parser is installed? Does it work on tsx files?

Also did you check the output of the treesitter-playground plugin? Maybe the typescript is properly parsed (so playground would show nodes) but not highlighted for some reason.

sQVe commented 1 year ago

@MDeiml Yeah, both jsx and tsx files parse and highlights correctly using treesitter.

I've only tried the built-in InspectTree, which correctly sets the lang node, but it's missing any content inside. I can install the playground and see if that provides any further insight.

As far as I can tell, it seems like it's correctly getting the lang key, mapping that to a filetype but then something gets lost.