-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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 config: query_file_ignore #15260
base: master
Are you sure you want to change the base?
treesitter config: query_file_ignore #15260
Conversation
Is there a way to re-enable a query file after it's been ignored? I can see that being useful for e.g. debugging or to allow easy toggling of certain query files. |
We can go with one of these three alternatives. ignore_query_files(lang: string, patterns: string[] | fn | nil) If If Pros:
Cons:
Or, same functionality as the above example, but more explicit API: ignore_query_files(lang: string, patterns: string[], action?: 'replace' | 'add' | 'remove' = 'replace') Based on the value of Props:
Cons:
Or go with a restricted set API that always replaces the current list: ignore_query_files(lang: string, patterns: string[] | nil) Pros
Cons
@vigoux you made a comment earlier (now deleted) which suggested the third example here. Now that the pros and cons are laid out, what do you guys think we should go with? Or maybe there are some even simpler ways to acheive this? |
a0a5db0
to
075b253
Compare
a0538cb
to
9b9aa1b
Compare
616a017
to
fa34401
Compare
Could you add a little test for this feature ? After that we'll be good to go ! |
fa34401
to
67aed82
Compare
Added the tests for this method. Since we only have a single query file to play with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are going to hate me but : could you run ./scripts/gen_vimdoc.py -t treesitter
just to see the look of the generated docs ? I think we handle type information in lua pretty bad.
Hmmmm... @tjdevries do you think we could keep those around until we support type indications in the doc comments ? |
Whatever makes the docs look good for now is fine with me :) |
67aed82
to
2b54a51
Compare
I've removed the type annotations. |
2b54a51
to
45a64db
Compare
f074d26
to
24493d6
Compare
24493d6
to
7ff0bc7
Compare
7ff0bc7
to
5623b3c
Compare
@neovim/treesitter @gpanders |
I think
Anything language or buffer specific is better handled through explicit Note that for |
I actually went with
This is not only about highlighting. The use-case goes like this: "I use a plugin that implements a feature using treesitter. They also provide some queries in |
No, we should first discuss what kind of API we want to have before implementing anything.
Maybe not (but the parser implies which queries are loaded currently, so it's not unrelated); that's what needs to be discussed.
I know; I'm just saying there is already precedent for customizing the queries, and we should keep that pattern in mind. In particular, the use case you describe is not about ignoring (specific) queries but overriding them completely with your custom list. Basically, what your plugin does is implement something on the same level as (In particular, I don't quite see why in this case your plugin couldn't go straight for custom queries |
Let me put it this way: I worry that your proposal acts on the wrong level: queries belong to "modules" (in nvim-treesitter terminology), not to parsers and even less to the global scope. Your use case is valid, but I don't think a global ignore list is the right approach to handle it -- we want finer-grained control. (What if I do want queries from plugins for some modules, like highlight and injections, but not for whatever your plugin does?) |
Hmm... Sorry, the example of the use-case in my previous comment was probably bad. Let me take a step back and describe why I wanted this to begin with: I was not satisfied with the default lua parser
This PR is for implementing that "something" from Option 2 which I can put in my personal config, e.g. vim.treesitter.config({
query_file_ignore = {
"nvim-treesitter",
"nvim-treesitter-textobjects",
"nvim-treesitter-textsubjects",
"refactoring.nvim",
},
}, "lua") I think now we're more clear about the use-case I had. With that being said, I understand if this is something that should not be included in Neovim core or if it's not worth adding the complexity. In that case I'll gladly go with the Option 1. |
OK, that is indeed a very different problem. Yes, in general option 1 is the correct thing to do (different, incompatible, parsers should not have the same name!); but the real issue here is not with the core tree-sitter API but with nvim-treesitter (installing parsers) -- so I'd recommend simply not installing the default parser and adding yours as a custom parser (as explained in the README) under the same name. In this case, however, if your Lua parser is indeed better than the current fork in nvim-treesitter, we might wish to switch -- but that is again something handled by nvim-treesitter, so I'd suggest opening an issue there about switching (where we may also want to consider @tjdevries' parser, so it would be good to include a comparison of the three). |
My use-case is unblocked by doing it a bit differently. Closing this PR. Thanks everybody for the discussion! 💜 |
@MunifTanjim I think this problem is not solved. We should have a way to select the query files |
@theHamsta Once the preferred solution is decided in nvim-treesitter/nvim-treesitter#2241, I can open another PR if needed. |
I'd like to keep the discussion open, even if the specific code here is probably not going to be merged. The generic question of how to override queries is still valid. (It could also be made into an issue, but for now it's easier to keep the history here.) |
resolves #15244
Description
vim.treesitter.config
method. It is used for updating configuration options for treesitter.query_file_ignore
Usage
Usage:
vim.treesitter.config(options, scope)
Treesitter config can be set for these:
set config for a specific buffer
set config for a specific language
set config for any language
Usage: config
query_file_ignore
Lua string pattern: https://www.lua.org/pil/20.2.html
Ignore all query files from a specific plugin:
Ignore specific query file from a specific plugin:
Ignore all query files from all plugins:
Add/Remove a specific ignore file pattern:
Clear all ignore file patterns: