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

Helix: support configuring grammars #2871

Open
cherryblossom000 opened this issue Apr 7, 2022 · 12 comments
Open

Helix: support configuring grammars #2871

cherryblossom000 opened this issue Apr 7, 2022 · 12 comments

Comments

@cherryblossom000
Copy link

cherryblossom000 commented Apr 7, 2022

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
Copy link

stale bot commented Jul 6, 2022

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.

@stale stale bot added the status: stale label Jul 6, 2022
@HiiGHoVuTi
Copy link

Anything new ?

@teto
Copy link
Collaborator

teto commented Sep 28, 2022

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
Copy link
Author

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
Copy link

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

@stale stale bot removed the status: stale label Sep 28, 2022
@Philipp-M
Copy link
Contributor

I think this commit should already support this: Philipp-M@8bdd7cc
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: helix-editor/helix#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
Copy link

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
Copy link
Contributor

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
Copy link

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
Copy link
Contributor

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: helix-editor/helix#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
Copy link

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
Copy link

stale bot commented Dec 30, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants