helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
33.41k stars 2.48k forks source link

Custom injection query #8739

Open mydumpfire opened 11 months ago

mydumpfire commented 11 months ago

Support for user-level injection queries. This would allow you to add your own custom queries without having to modify HELIX_RUNTIME (which may not be modifiable, e.g. NixOS). Perhaps it can be located in ~/.config/helix/queries/*.

pascalkuthe commented 11 months ago

We consider the queries in directory configuration files. You can put queries in .config/helix/runtime and they will take priority over the runtime files provided by the package manager

mydumpfire commented 11 months ago

Can you extend the default queries instead of overwriting them? In neovim, you can add ; extends to the top of the query file. Is there an equivalent for Helix?

pascalkuthe commented 11 months ago

No you need to copy them

mydumpfire commented 11 months ago

Can this issue be re-opened as a request for query extension support instead? Query files can be hundreds lines long, so extensibility would be really convenient.

the-mikedavis commented 11 months ago

I think this could be convenient. The design is a little tricky because there are multiple use-cases here for having custom queries in your ~/.config/helix/runtime / HELIX_RUNTIME. You might be extending the existing queries or you may have changed / updated the parser and want to ignore the existing queries. ; extends could work but it would only prepend/append the query text to the old queries which means that you won't have any control over the priorities of the patterns. So this might need a priority system like neovim has for queries, which I'd like to avoid if we can. Copying the old queries and making changes to that is a little clunky but it's probably the most straightforward way to change queries without introducing a bunch of new features just for merging queries.

EmranMR commented 7 months ago

Plus one for extension! 😊

In neovim, you can add ; extends to the top of the query file. Is there an equivalent for Helix?

Nikita0x commented 1 month ago

I wanted to try to contribute some queries, and followed documentation - added HELIX_RUNTIME in my .bashrc and also created a ~/.config/helix/runtime but those did nothing at all? I presume if you are on NixOS it does not work? as @mydumpfire said even though @pascalkuthe said: "qeries in .config/helix/runtime and they will take priority over the runtime files provided by the package manager" - it still didn't take any effect? Or maybe I am doing something wrong....

UPD: I do think that no matter what I change in my ~/.config/helix/runtime with HELIX_RUNTIME in my paths, the highlighting is all the time default. I tried to modify the package manager's version in nix/store but those files are read-only

UPD2: Sorry, you were right, I was testing my queries in .config/helix/runtime - and they did not work. You have to test them in .config/helix/runtime/queries/<language> - and now it works!