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

Treesitter offset directive has no effect #1446

Open
3 tasks done
frangio opened this issue Dec 30, 2024 · 6 comments
Open
3 tasks done

Treesitter offset directive has no effect #1446

frangio opened this issue Dec 30, 2024 · 6 comments
Labels
feature-request Request for a feature to existing module mini.ai

Comments

@frangio
Copy link

frangio commented Dec 30, 2024

Contributing guidelines

Module(s)

mini.ai

Description

offset directives in a Treesitter query have no effect when defined as a textobject with mini.ai.

The same query defined as a textobject with nvim-treesitter-textobject applies the offset as expected.

Neovim version

0.10.3

Steps to reproduce

after/queries/lua/textobjects.scm:

; extends
((table_constructor) @table.outer @table.inner (#offset! @table.inner 0 1 0 -1))

mini.ai setup:

require'mini.ai'.setup {
  custom_textobjects = {
    ['x'] = require'mini.ai'.gen_spec.treesitter({ a = '@table.outer', i = '@table.inner' }),
  },
}

Test file:

{a}

Expected behavior

dix should delete a and leave {}.

Actual behavior

dix deletes {a}.

@frangio frangio added the bug Something isn't working label Dec 30, 2024
@echasnovski echasnovski added feature-request Request for a feature to existing module mini.ai and removed bug Something isn't working labels Dec 30, 2024
@echasnovski
Copy link
Owner

Thanks for the suggestion!

I can reproduce, but I'd not call it a "bug" per se since this was more or less experimental at the time 'mini.ai' was created. And I feel still is. But maybe there is a better tooling now to handle this. I'll take a look.

@frangio
Copy link
Author

frangio commented Dec 30, 2024

There's a number of queries in nvim-treesitter-textobject that useoffset, and in general it's very useful to define the "inner" variant of a textobject, I think this might be good reason to support it.

Do you know what work is required for this? Happy to help if you're open to it.

I considered this a bug in the sense that the behavior didn't match my expectations from reading Neovim's documentation.

@echasnovski
Copy link
Owner

Do you know what work is required for this? Happy to help if you're open to it.

Probably some way of properly getting this offset information (in a backwards compatible down through Neovim 0.8 way; maybe have this only starting from some more recent version if the API is difficult) and apply it here. I think this should be it, but can't vouch for that.

If you want to and have (lots of) free time, sure go ahead. But if not - no worries; I'll probably look at it this week.

@frangio
Copy link
Author

frangio commented Dec 30, 2024

Ah I understand now why the offset is ignored. The directive stores the adjusted range in the capture metadata, whereas mini.ai only looks at the captured node.

See the relevant code in nvim-treesitter-textobject.

@echasnovski
Copy link
Owner

Ah I understand now why the offset is ignored. The directive stores the adjusted range in the capture metadata, whereas mini.ai only looks at the captured node.

I see. That metadata behaving that exact way may be too recent. Needs an actual testing with earlier Neovim versions if that still works.

@frangio
Copy link
Author

frangio commented Dec 30, 2024

It looks like the current metadata structure is used since 0.8.0 (neovim/neovim#18276).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for a feature to existing module mini.ai
Projects
None yet
Development

No branches or pull requests

2 participants