Adding additional tree-sitter grammars? #340
-
|
Hi, I've been trying to get kulala.nvim to work but it has it's own tree-sitter grammar for the .http files. I've been looking at an existing issue in their repo (mistweaverco/kulala.nvim#627) and I can get as far as to building the grammar but I have no clue how to properly include it in nixCats nvim. I have a branch for my nixCats here: https://github.com/Lewenhaupt/nvim-nix/tree/kulala. I'm probably not understanding the docs correctly, or missing where I should put it. But I can confirm that in all my attempts the regular syntax highlighting for lua and nix files work so I haven't at least broken allGrammars inclusion. The error I'm getting: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
I do believe the resulting derivation looks correct in the store, it has both the parser and the queries so I believe I'm missing something in terms of how to make sure it's included and doesn't need installation? |
Beta Was this translation helpful? Give feedback.
-
treesitter-kulala-http-grammar = pkgs.tree-sitter.buildGrammar {
language = "kulala_http";
version = "5.3.1"; # <-- this can be anything I ususally do like, inputs.kulala-grammar.shortRev
src = inputs.kulala-grammar;
location = "lua/tree-sitter";
};
all-grammars = pkgs.vimPlugins.nvim-treesitter.withPlugins (
plugins:
pkgs.vimPlugins.nvim-treesitter.allGrammars
++ [ treesitter-kulala-http-grammar ] # you had an extra buildGrammar here
);Also you can fetch it with inputs if you dont want to deal with the hash thing, as I did above kulala-grammar = {
url = "github:mistweaverco/kulala.nvim";
flake = false;
};Let me know if this works! withPlugins calls grammarToPlugin on the stuffs for you, and then adds them to the .passthru.dependencies key on nvim-treesitter, which gets grabbed and added as startup plugins when you install that nvim-treesitter. With lazy.nvim, you HAVE to call grammarToPlugin in some way, either on its own or via withPlugins, otherwise lazy.nvim will block them Without lazy.nvim you can also just add them as plugins with just the first tree-sitter.buildGrammar without the grammarToPlugin too if desired. Please let me know if this does or doesnt work so we can keep exploring. Basically, when building a treesitter grammar, first thing is to build the parser .so file, second thing is to call grammarToPlugin to massage it into the file structure nvim prefers. Nvim accepts it without grammarToPlugin, but you have to add it as its own plugin, and because lazy.nvim prevents you from loading plugins without making specs for them it can get problematic. But calling grammarToPlugin allows nixCats to group them all up and then make sure they don't get dropped (one of the few things the lazy.nvim wrapper function provided does). With lze or lz.n though instead of lazy.nvim, which just manage lazy loading and not installation, you can just add them as startup plugins and they just work with or without grammarToPlugin being called, as they don't take over the rtp. The other thing to keep in mind is that building the grammar will pull out and build only the grammar. If there is more to the plugin, you will need to install it as you would with another normal plugin as well. But that would not be necessary to get the grammar to work, just to have access to the lua features of the plugin if there are any. One could consider adding kulala.nvim to nixpkgs as well at some point, as then people will be able to install it like they would anything else, but that is, of course, extra credit only. |
Beta Was this translation helpful? Give feedback.
-
|
Haha damnit, I was so close 😅 But yeah it worked when I removed the extra neovimUtils.grammarToPlugin! shortRev wasn't available and I realized kulala.nvim is in vimPlugins already so no need to defined it as an additional input, instead I could just use vimPlugins.kulala-nvim.version. Here's the final commit: Lewenhaupt/nvim-nix@d672afc Big thanks for the help and the, as usual, in depth explanation! Really helps me understand the inner workings a bit better :D |
Beta Was this translation helpful? Give feedback.
Also you can fetch it with inputs if you dont want to deal with the hash thing, as I di…