Closed primeapple closed 1 year ago
Please try to find a reproducer without additional plugins. This report is unfortunately not very much to go on since we don't have any concrete circumstances when the issue appears.
I'll try to disable all the treesitter related plugins. Is there any way to see enable Treesitter logging? Or maybe Parser specific logging?
This happens because vim.treesitter.language.get_lang
checks if there is a parser for javascriptreact
and, since there isn't, it tries to register a parser for the language javascriptreact
and the filetype javascriptreact
. Since the parser being used by this filetype is tsx
, this fails. Doing vim.treesitter.inspect_tree({lang='tsx'}))
also does not work because then it does not detect the filetype and tries to register a parser for the language tsx
and the filetype tsx
.
But I guess this issue should be reported to the upstream Neovim repo, right?
No, this is an nvim-treesitter issue; the parser should be correctly registered here.
If we can't rely on the ft->parser association javascriptreact
-> javascript
, we need to drop it, and users need to manually start the parser via vim.treesitter.start(buffer, language)
.
I tried around with disabling all kind of Treesitter related Plugins, does not seem to work. Also it is not on the same file, it just dies randomly, sometimes directly on start.
Is there really no logging when TS failed to parse something?
This happens because
vim.treesitter.language.get_lang
checks if there is a parser forjavascriptreact
and, since there isn't, it tries to register a parser for the languagejavascriptreact
and the filetypejavascriptreact
. Since the parser being used by this filetype istsx
, this fails. Doingvim.treesitter.inspect_tree({lang='tsx'}))
also does not work because then it does not detect the filetype and tries to register a parser for the languagetsx
and the filetypetsx
.But I guess this issue should be reported to the upstream Neovim repo, right?
Not 100% sure what you mean. jsx
files are parsed by the javascript
parser, not by the tsx
one.
I think I found something to reproduce this.
My workflow is the following:
While doing this, Treesitter has to parse all previews of all the files that I came across while in Telescope.
Now something special happens, when I open the preview of a Markdown file, that has a codeblock (3 backticks) followed by jsx
. From this moment on, Treesitter can not parse .jsx
files anymore.
If I change the jsx
to js
in the markdown file, I get correct highlighting of the codeblock (which I didn't get before) as well as Treesitter still works for .jsx
files.
So what is the magic bullet here, now that I can reproduce it? :D
I had similar issue when using ts:get_node()
https://github.com/nvim-treesitter/nvim-treesitter/issues/4710
So it's a thing
Even thought I solved somewhat issue, but caused issues with snippet not properly determining if it's inside function or in global scope
I had similar issue with tsx too
Can confirm this as well. I notice this happens particularly when I edit a markdown file (especially the code blocks) and when I move to a tsx
/jsx
file it just fails to find the right parser, which is weird as even the basic vim.treesitter.get_parser()
command fails.
This happens randomly though so there isn't a concrete repro of the issue.
We can now close this (https://github.com/neovim/neovim/pull/25151, https://github.com/neovim/neovim/pull/25143)
Not yet since the patch is not available for stable users.
if u keep getting this type of error, i have the solution to auto change jsx files to js, here is the code
-- Automatically set filetype for .jsx files to javascript
vim.api.nvim_create_autocmd({"BufNewFile", "BufRead"}, {
pattern = "*.jsx",
callback = function()
vim.bo.filetype = "javascript"
end
})
Describe the bug
Sometimes when working my highlighting for
jsx
files does not work. It may also be onjs
files or even others, but there the lsp is providing semantic information, so it doesn't catch my eye.Typing
:Inspect
on a token in this file does only display a "Semantic tokens" and not a "Treesitter" section.Running
:InspectTree
yields the following error:To Reproduce
I don't know exactly how to reproduce. When I close Neovim and reopen it works for a while on
jsx
files.It seems that once it fails once for a
.jsx
file it doesn't even try anymore and fails on all the other.jsx
files as well.Expected behavior
No response
Output of
:checkhealth nvim-treesitter
Additional context
My Treesitter config (using lazy.nvim):