Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Doesn't seem to work for JSX filetypes #14

Closed
schardev opened this issue Jul 20, 2023 · 12 comments
Closed

[Bug]: Doesn't seem to work for JSX filetypes #14

schardev opened this issue Jul 20, 2023 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@schardev
Copy link

Neovim version

0.9.1

Language affected

all I guess

Query

No response

Strategy

No response

Description

- Install [kickstart.nvim](https://github.com/nvim-lua/kickstart.nvim)
- Add `rainbow-delimiters.nvim` to `nvim-treesitter`'s dependencies like:


 {
    -- Highlight, edit, and navigate code
    'nvim-treesitter/nvim-treesitter',
    dependencies = {
      'nvim-treesitter/nvim-treesitter-textobjects',
      'HiPhish/rainbow-delimiters.nvim'
    },
    build = ':TSUpdate',
  },

- See if it works ... which it doesn't in my case

The health checks also says:

`- ERROR The healthcheck report for "rainbow-delimiters" plugin is empty.`
@schardev schardev added the bug Something isn't working label Jul 20, 2023
@HiPhish
Copy link
Owner

HiPhish commented Jul 21, 2023

You could be experiencing the same problem as #2. Does highlighting work if you :write and then :edit the file?

As for the health check, if you don't have any custom configuration (which you don't need to have) there is nothing to check, so the health report will be empty. Perhaps I should add an explicit message for that case.

@schardev
Copy link
Author

schardev commented Jul 22, 2023

#2 seems like a different problem as it was present in nvim-ts-rainbow2 too (which worked totally fine here). I recently decided to switch to rainbow-delimiters as I was getting some query errors in nvim-ts-rainbow2 (maybe because of outdated API calls?).

Does the repro works on your machine? Or it's working fine on yours?

EDIT: oh and yes, I did try :write and :edit still doesn't work. I also invoked the plugin on startup (rather than defining it as a treesitter dependency) still nope.

@HiPhish
Copy link
Owner

HiPhish commented Jul 22, 2023

Can you please update to the current master, then set the log level to TRACE in your settings, then post the contents of the log file here? See :h rb-delimiters-logging for information on how to adjust the log level.

vim.g.rainbow_delimiters = {
    log = {
        level = vim.log.levels.TRACE
    }
}

@schardev
Copy link
Author

For tsx file:

2023-07-22T21:05+0530	ERROR		Error attaching strategy to buffer 1: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 1394 for language tsx
2023-07-22T21:05+0530	ERROR		Error attaching strategy to buffer 1: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 1394 for language tsx
2023-07-22T21:05+0530	ERROR		Error attaching strategy to buffer 1: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 1394 for language tsx

For jsx file:

2023-07-22T21:09+0530	ERROR		Error attaching strategy to buffer 1: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 1065 for language javascript
2023-07-22T21:09+0530	ERROR		Error attaching strategy to buffer 1: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:259: query: invalid structure at position 1065 for language javascript

Interestingly, it started working for ts, html (and maybe other) files, but not js files.

@HiPhish
Copy link
Owner

HiPhish commented Jul 22, 2023

Oops, I had a typo in my logger logic. Can you please update again and post the news logs?

The error message indicates that something is wrong with the query. Please run :TSUpdate to updated all parsers, then try running the following code:

local q = vim.fn.join(vim.fn.readfile('path/to/plugins/rainbow-delimiters.nvim/queries/javascript/rainbow-delimiters-react.scm'), '\n')
local query = vim._ts_parse_query('javascript', s)
print(query)

The first line loads the text of the query from file. The second line call the function which fails in your error message. If everything went correctly the last line should print something like <userdata 1>.

@schardev
Copy link
Author

schardev commented Jul 24, 2023

Sorry for the delay, was busy with work.

When running those commands it fails at the vim._ts_parse_query('javascript', q) function with error:

E5108: Error executing lua [string ":lua"]:1: no such language: javascript
stack traceback:
        [C]: in function '_ts_parse_query'
        [string ":lua"]:1: in main chunk

Which is weird as I made sure that the parser for javascript, tsx and typescript are properly installed (and yes I even re-installed them just to be sure).

Running the commands with tsx as the language, gives me previously reported error:

E5108: Error executing lua [string ":lua"]:1: query: invalid structure at posi
tion 1065 for language tsx
stack traceback:
        [C]: in function '_ts_parse_query'
        [string ":lua"]:1: in main chunk

And here are the logs:

2023-07-24T19:34+0530	TRACE		Define highlight groups
2023-07-24T19:34+0530	TRACE		Attaching to buffer 1 with language tsx.
2023-07-24T19:34+0530	TRACE	strategy.global	global strategy on_attach
2023-07-24T19:34+0530	TRACE	strategy.global	Set up parser for buffer 1
2023-07-24T19:34+0530	TRACE	strategy.global	Set up parser for tsx
2023-07-24T19:34+0530	TRACE		Cannot attach to buffer 2, no parser for nil
2023-07-24T19:34+0530	TRACE		Cannot attach to buffer 3, no parser for nil
2023-07-24T19:34+0530	TRACE		Detaching from buffer 1.
2023-07-24T19:34+0530	TRACE		Attaching to buffer 1 with language tsx.
2023-07-24T19:34+0530	TRACE	strategy.global	global strategy on_attach
2023-07-24T19:34+0530	TRACE	strategy.global	Set up parser for buffer 1
2023-07-24T19:34+0530	TRACE	strategy.global	Set up parser for tsx
2023-07-24T19:34+0530	TRACE		Detaching from buffer 1.
2023-07-24T19:34+0530	TRACE		Attaching to buffer 1 with language tsx.
2023-07-24T19:34+0530	TRACE	strategy.global	global strategy on_attach
2023-07-24T19:34+0530	TRACE	strategy.global	Set up parser for buffer 1
2023-07-24T19:34+0530	TRACE	strategy.global	Set up parser for tsx
2023-07-24T19:35+0530	TRACE		Detaching from buffer 3.
2023-07-24T19:35+0530	TRACE		Detaching from buffer 2.
2023-07-24T19:42+0530	TRACE		Detaching from buffer 1.

@HiPhish
Copy link
Owner

HiPhish commented Jul 24, 2023

What do you get if you try a language that does work for you? (Remember that you have to adjust the path to the query as well, otherwise you will get an error.)

@schardev
Copy link
Author

for css, running:

local q = vim.fn.join(vim.fn.readfile('/home/schardev/.local/share/nvim/lazy/rai
nbow-delimiters.nvim/queries/css/rainbow-delimiters.scm'), '\n')
local query = vim._ts_parse_query('css', q)
print(query) -- returns `<query>`

and the logs says:

2023-07-25T16:44+0530	TRACE		Detaching from buffer 1.
2023-07-25T16:44+0530	TRACE		Attaching to buffer 1 with language scss.
2023-07-25T16:44+0530	TRACE	strategy.global	global strategy on_attach
2023-07-25T16:44+0530	TRACE	strategy.global	Set up parser for buffer 1
2023-07-25T16:44+0530	TRACE	strategy.global	Set up parser for scss
2023-07-25T16:44+0530	TRACE	lib	Query rainbow-delimiters found for scss
2023-07-25T16:44+0530	TRACE	lib	Query rainbow-delimiters found for scss

and the same for json too:

2023-07-25T16:51+0530	TRACE		Define highlight groups
2023-07-25T16:51+0530	TRACE		Detaching from buffer 1.
2023-07-25T16:51+0530	TRACE		Attaching to buffer 1 with language json.
2023-07-25T16:51+0530	TRACE	strategy.global	global strategy on_attach
2023-07-25T16:51+0530	TRACE	strategy.global	Set up parser for buffer 1
2023-07-25T16:51+0530	TRACE	strategy.global	Set up parser for json
2023-07-25T16:51+0530	TRACE	lib	Query rainbow-delimiters found for json
2023-07-25T16:51+0530	TRACE	lib	Query rainbow-delimiters found for json
2023-07-25T16:52+0530	TRACE		Detaching from buffer 2.
2023-07-25T16:52+0530	TRACE		Detaching from buffer 1.

@HiPhish
Copy link
Owner

HiPhish commented Jul 26, 2023

So CSS and JSON are working correctly. Then the problem must be either with my query or with your Neovim, because by calling vim._ts_parse_query directly we are bypassing any of my logic. Here is an idea: open up the offending query file, comment everything out and then re-enable one pattern at a time until you find the offending pattern.

@schardev
Copy link
Author

schardev commented Jul 27, 2023

So, I was able to get it to work now. Apparently, this query from tsx and javascript schema is causing the parser to fail (the @closing capture to be exact). Changing that query to something like this works:

(jsx_self_closing_element
  name: (identifier) @opening
  "/>" @closing) @container ; <-- here

It works but the highlighting is a little bit off (see <NavArrowLeft /> in the below screenshot). I don't mind it though but there is that.
image

EDIT: Here are the logs (just for the sake of it):

2023-07-27T15:58+0530	TRACE		Define highlight groups
2023-07-27T15:58+0530	TRACE		Attaching to buffer 1 with language tsx.
2023-07-27T15:58+0530	TRACE	strategy.global	global strategy on_attach
2023-07-27T15:58+0530	TRACE	strategy.global	Set up parser for buffer 1
2023-07-27T15:58+0530	TRACE	strategy.global	Set up parser for tsx
2023-07-27T15:58+0530	TRACE	lib	Query rainbow-delimiters found for tsx
2023-07-27T15:58+0530	TRACE	lib	Query rainbow-delimiters found for tsx
2023-07-27T15:58+0530	TRACE		Cannot attach to buffer 2, no parser for nil
2023-07-27T15:58+0530	TRACE		Cannot attach to buffer 3, no parser for nil
2023-07-27T15:58+0530	TRACE	strategy.global	Changed tree in buffer 1 with languages tsx
2023-07-27T15:58+0530	TRACE	lib	Query rainbow-delimiters found for tsx
2023-07-27T15:58+0530	TRACE		Detaching from buffer 1.
2023-07-27T15:58+0530	TRACE		Detaching from buffer 1.
2023-07-27T15:58+0530	TRACE		Attaching to buffer 1 with language tsx.
2023-07-27T15:58+0530	TRACE	strategy.global	global strategy on_attach
2023-07-27T15:58+0530	TRACE	strategy.global	Set up parser for buffer 1
2023-07-27T15:58+0530	TRACE	strategy.global	Set up parser for tsx
2023-07-27T15:58+0530	TRACE	lib	Query rainbow-delimiters found for tsx
2023-07-27T15:58+0530	TRACE	lib	Query rainbow-delimiters found for tsx
2023-07-27T15:58+0530	TRACE		Detaching from buffer 1.
2023-07-27T15:58+0530	TRACE		Detaching from buffer 2.
2023-07-27T15:58+0530	TRACE		Detaching from buffer 3.
2023-07-27T15:58+0530	TRACE		Define highlight groups
2023-07-27T15:58+0530	TRACE		Cannot attach to buffer 2, no parser for nil
2023-07-27T15:58+0530	TRACE		Detaching from buffer 2.
2023-07-27T15:58+0530	TRACE		Cannot attach to buffer 4, no parser for nil
2023-07-27T15:58+0530	TRACE		Detaching from buffer 1.
2023-07-27T15:58+0530	TRACE		Detaching from buffer 4.

@schardev schardev changed the title [Bug]: Doesn't seem to work? [Bug]: Doesn't seem to work for JSX filetypes Aug 1, 2023
@HiPhish
Copy link
Owner

HiPhish commented Aug 1, 2023

Please try the current master branch. It looks like I had an older version of the parser installed and at some point the tree structure changed. There is no way of supporting both patterns, so I'm going with the more recent one.

It works but the highlighting is a little bit off

Yes, that is unfortunate. Currently Neovim can only have one match per capture, so I can have only one opening and one closing node. The three nodes are <, NavArrowLeft and />. The closing one is obvious, but which one should be the opening node? I went with the tag name, it seemed the lest bad option to me.

Ideally both < and NavArrowLeft should be opening nodes, but I cannot do that yet.

@schardev
Copy link
Author

schardev commented Aug 2, 2023

Updating to master obviously fixed it. Just hoping that neovim/neovim#17099 get's merged so we can have proper highlighting.

You can close the issue now. Thanks for the support :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants