nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.36k stars 1.7k forks source link

Helix: support configuring grammars #2871

Open cherryblossom000 opened 2 years ago

cherryblossom000 commented 2 years ago

Support configuring tree-sitter grammars in languages.toml for Helix.

[[grammar]]
name = "rust"
source = { git = "https://github.com/tree-sitter/tree-sitter-rust", rev = "a250c4582510ff34767ec3b7dcdd3c24e8c8aa68" }

The use-grammars key should also be supported, which controls which grammars are fetched and built (if omitted all grammars are used).

use-grammars = { only = [ "rust", "c", "cpp" ] }
# or
use-grammars = { except = [ "yaml", "json" ] }
stale[bot] commented 2 years ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

HiiGHoVuTi commented 1 year ago

Anything new ?

teto commented 1 year ago

there are many treesitter grammars available in nixpkgs, can one give a folder to helix as source ? (btw neovim user here so be the change you want to see :p )

cherryblossom000 commented 1 year ago

I use neovim as well and was going to try out Helix, but then didn’t when I realised you couldn’t configure grammars via Nix, which is why I opened this issue. I might get around to implementing this when I have more time, but I’m happy with neovim for now so I’m not really interested in this issue anymore.

HiiGHoVuTi commented 1 year ago

Well I am interested in it since otherwise I would have to use neovim too for unsupported languages.

Philipp-M commented 1 year ago

I think this commit should already support this: https://github.com/Philipp-M/home-manager/commit/8bdd7cc552acb2f78391d82cccdfc0b306fbc623 Could you test this maybe? If it works with the grammars, I can clean it up and upstream it. I'm actually waiting a while already to upstream this, until this to be merged: https://github.com/helix-editor/helix/pull/2507, because this requires more access to the languages.toml anyway (language-server table in particular as seen here: https://github.com/Philipp-M/nixos-config/blob/50785373bc6e11f29b410b0a1f9907763e2f0bf8/home/modules/cli/helix.nix#L143)

HiiGHoVuTi commented 1 year ago

Your commit works as expected and allows to add grammar configuration. However there is another issue which is that Helix cannot build the parsers where it tries to.

~/.config/nixpkgs main* ⇡ ❯ hx --grammar fetch
Fetching 115 grammars
115 grammars failed to fetch
        Failure 1/115: Could not create grammar directory "/nix/store/nf77kkk8bglvznsbkni8m1v3k2gng37x-helix-runtime/grammars/sources/rust"
        Failure 2/115: Could not create grammar directory "/nix/store/nf77kkk8bglvznsbkni8m1v3k2gng37x-helix-runtime/grammars/sources/toml"
Philipp-M commented 1 year ago

Yeah I expected something like that. Helix tries to compile the libraries to the HELIX_RUNTIME directory which is set to the nix store (in either the flake in the repo or nixpkgs). I don't think there's a way to fix this without much hassle.

You could create an overlay with a different HELIX_RUNTIME set that is writeable (which poses its own problems, as all the other built-in grammars etc. have to be handled, and isn't probably very clean/nix idiomatic).

Or probably best: Create a PR in the helix repo that allows loading of precompiled dynamic libs directly. Starting points are here and here

But if you don't want to deep-dive into the source code, you could also just create a PR extending the default languages.toml in the helix repo and use the flake in the repo, this is probably the simplest solution for this problem (I did this for a language once, these kinds of PRs get merged rather quickly).

HiiGHoVuTi commented 1 year ago

Problem being I have no clue how to do any of that. The language I'm trying to add is too niche to make a PR to helix and I don't know enough nix to create the overlay properly.

Philipp-M commented 1 year ago

Problem being I have no clue how to do any of that. The language I'm trying to add is too niche to make a PR to helix and I don't know enough nix to create the overlay properly.

Well the language I was talking about likely has just one user (me ^^) here: https://github.com/helix-editor/helix/pull/3048

Creating a PR doesn't hurt I guess, and even if it doesn't get merged (which I don't believe, if done properly), you could maintain your own fork worst-case.

HiiGHoVuTi commented 1 year ago

sure ! I'll consider it, shouldn't be any hard at all. "Fixing" the issue on nix's side might be useful for other people/times though.

stale[bot] commented 1 year ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.