-
-
Notifications
You must be signed in to change notification settings - Fork 14.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
PR #321550 causes bugs with nix and markdown grammars #332580
Comments
@MangoIV I don't mind fixing it however I have zero context and no idea what you mean when you say to prefer the queries from treesitter repo. If you provide a little more context I might be able to help. |
@MangoIV can we just revert that PR it seems like there are others reporting issues with it. |
I will try to do as soon as possible but in the meantime, feel free to open a revert MR. |
I think the PR does the right thing (except for the nu grammar where files are put in the wrong folder as a report mentioend it), probably @humemm is installing a wrong version of the grammar and/or mismatched with nvim-treesitter ? |
Surprisingly, it still works in nixCats? I talked with a guy who was having an issue with pkgs.wrapNeovim I had to remove the substitutor stuff and also fix an input url to get his config to build on my machine, but when I did, it reliably reproduced the error every time I visited his flake.nix file. It throws on EVERY keyboard input in that file. Very annoying. I took a fairly extensive look and couldnt figure it out, but decided to swap in his dependencies into a nixCats template just to see if it was something I needed to fix asap too. It worked flawlessly again. no errors whatsoever when I moved his dependencies into the fields for them in the default nixCats template We were confused for a while, but I think I figured out why treesitter grammars still work just fine in nixCats but not in pkgs.wrapNeovim, at least not when nvim-treesitter is lazy loaded (but with the grammars still in start, as resolved by neovimUtils.packDir) (and they can still find their queries just fine, they dont seem to need this to be able to find them) Here, in the process of consolidating the treesitter grammars to make it easier to add them to rtp when doing the lazy.nvim wrapper, and to not spam my debug info commands, I think I accidentally undid this exact change, completely as a byproduct of consolidating them XD I think the issue is it can still find them the other way, and now it finds them twice or something? Honestly I have no idea what the heck is up with it but I dodged a bullet because treesitter grammar changes are one of the only things in nixCats that arent under my direct control, along with which neovim-unwrapped is used, and the location of the ruby env directory in nixpkgs I do know that when you load treesitter grammars after the builtin ones in rtp you get conflicts, but in this case, these are still first, and yet still error. |
so yeah, in conclusion, they could already find the queries before this pr went through and now some things are having trouble finding them because of this change. I say revert it probably but that is probably up to you teto or mango or hummem or whoever. In the meantime, if you avoid lazy loading nvim-treesitter and load at startup it seems to be more reliable? (EVEN THOUGH THAT SHOULDNT MATTER AND WHY IT DOES IS BLOWING MY MIND because like, grammars dont need nvim-treesitter to work and also they are still resolved via packDir function to be added with start plugins regardless of where you add nvim-treesitter.withAllGrammars) So highly confusing why it is an issue, I have no clue, but it does seem to be the problem. |
What does this refer to? WithAllGrammars? Or? I’m 100% sure that it could not move queries for tree sitter grammars not coming from nvim-treesitter, that’s why I opened the PR. I do believe you that something goes wrong but I still don’t know what and nobody made it clear yet. As I said, I don’t know what is the problem so if you had something working before and now it doesn’t, feel free to revert but then all the other tree sitter grammars won’t be working, again. |
Maybe I can add some more observations, but still, I don't know what the root cause is and how to fix it. I am currently working on building my neovim config as a home manager module which creates a derivation of ~/.config/nvim that looks like a normal lazy configuration, while I am using a neovim from the neovim nightly overlay -- so I don't have any fancy use of nixCats or pkgs.wrapNeovim. Still I have the problem with the nix parser, which is the one with the "No handler for is-not?" error. I am not doing anything fancy, I am just creating a LazySpec with a dir=/path/to/nix/store, and lazy adds it to the rtp. I have explicitely turned off lazy loading for treesitter, still, it is broken for me. Nix parser with the problem:
Working yaml parser:
It is really unclear what went wrong here, but I also think it is better to find a solution to the problem than to just revert to the old behaviour for which I have heard that it is also broken on some parsers. I happily add more context for my system and try out different versions of nvim and nixpkgs, but I have no pointers on how to fix it myself. Currently I have locked nixpkgs/nixos-unstable on rev 2100883 and neovim-nightly-overlay with rev 67e84c020323a28f33ad4498f022a7b2c67719ad, following nixpkgs, if that helps in any way. |
I mean, before this change went through, the grammars seemed to work just fine is what im saying. you say "all the other grammars won't be working, again" but they seemed to work just fine before this change? Despite them not being in the directory, they seemed to still be able to find the queries. nixCats UNDOES this change by grabbing only the parser once again, and the queries work fine, despite not being where you would expect. I think it is capable of following symlinks or something because it was definitely able to find the queries before despite them not being present directly I have this pack/myNeovimPackages/start/vimplugin-treesitter-grammar-ALL-INCLUDED/parser Which contains a bunch of these perl.so -> /nix/store/qjkc0waiiapjlx07c7f26jaky0fx0r20-perl-grammar-0.0.0+rev=3a21d9c/parser jsonc.so -> /nix/store/3s7kf066dpky9rs59y8nl6dwd7iz3kib-jsonc-grammar-0.0.0+rev=02b0165/parser objc.so -> /nix/store/dp3lyz4h2i69mmqpwyp16f53fjizhd4z-objc-grammar-0.0.0+rev=62e61b6/parser No queries in sight, and yet it DEFINITELY can find the treesitter queries according to checkhealth, all my highlighting and related stuff to queries works in every filetype I have used, it seems to work If you follow those symlinks, there are queries in there, my theory is that it is following the symlinks Its weird that it was able to find them before, because they were not copied over, but it could in fact find them |
Addresses issue NixOS#332580 Revert to NixOS#321550 It was finding the queries before. Adding them to where you would expect throws an error. Removing them again afterwards during the build process fixes the error. It is weird, but that at least seems pretty clear to me. Opening this as a draft so that if the decision is made to revert, all that needs to be done is accept it.
@teto, your assumption seems broad. Have you attempted to reproduce the bug? Are there automated tests in nixpkgs that cover edge cases for grammar/query locations? It appears multiple grammars/queries were affected as evident by the discussion here and on the linked issue. I'm new here and not fully familiar with how nixpkgs handles package releases and testing. If there’s documentation or a spec, I’d appreciate a pointer. Simply referring to Here are the PR changes. Bespoke bash script that moves queries from one directory to another: # from PR change
echo "moving queries from neovim queries dir"
...
# again
echo "moving queries from standard queries dir" The PR lacks unit tests that might clarify expectations. Clearly from the comments being echoed what was done is in no way standard. Any guidance on the issue being addressed here would be appreciated. For context my grammars were installed using EDIT: removing the queries in |
what I meant by
I did not because I know from experience that neovim + treesitter issues are 90% misconfiguration. It's not robust at all, one little misconfiguration and it blows up, which is why it's still experimental (I dont blame users, it's the ecosystem that need to make it easier).
So I think you override the builtins queries with more recent ones, the mismatch generates the error. Before #321550, one had mismatched libraries and queries but it was less likely to blow up (how neovim leverage queries change more frequently). It's a quick guess so I might be wrong (you could try nightly neovim see if it fixes your error https://github.com/nix-community/neovim-nightly-overlay). In case I guessed correclty, nixpkgs should package the last version of nvim-treesitter compatible with neovim 0.10 (and it's indeed a flaw in nixpkgs, but not the incriminated PR). |
I have tried to reproduce and I can confirm that it does cause issues with the new copying. tried it on someones config, one outside of nixCats, one inside of nixCats. Same set of plugins(I copy pasted them into the default nixCats template), the other one using pkgs.wrapNeovim which I mentioned here previously in this thread The only difference in loading between the two methods that would have ANY effect is that nixCats posthumorously removes the queries directories (on accident, because when I wrote it, thats all there was, and it worked fine, and somehow also avoids this issue XD). the one using nixCats works fine, the other one errored on every keypress on its flake.nix I believe that if we need to copy them in, we also need to stop nvim-treesitter from vendoring them in for us. Or go back to not copying them in. Either way is fine with me, but the second one is easier and could be done as a temporary measure as well. Honestly, idk. I know is a bug, I do not know if it is a better plan to keep the copy and stop nvim-treesitter from vendoring in the queries however it is doing that, or if it is a better plan to revert, but one of the two should be done. I still am not sure how it is resolving the queries. If I knew that, I would fix it there probably |
@BirdeeHub can we avoid mentioning nixCats and focus on the problem here ?
I dont think it's questionable here: if nvim-treesitter provides them so we must provide them, we are not half-installing software. |
right, so, we need to stop nvim-treesitter from vendoring them in so that we can copy them without creating duplicates, so that we do it properly |
Im all on board for that plan I just dont know how treesitter is doing it |
and im not mentioning nixCats just to mention it. I was saying what I tried, because the result of its output is functionally identical to how nixpkgs was before that patch, and that is how I found out. I suppose I should have said, before the patch and after the patch, but thats not what I tested at first or how I found out. Heres an even more minimal example below, 1 file, 52 lines |
Minimal reproduction.
Hopefully this helps clear up whats being discussed. To be even more clear, this should, and does, put the grammars in start and on the rtp, and the nvim-treesitter plugin in opt. nvim-treesitter isnt supposed to be required to load grammars. So this should be 100% fine. But it isnt. Whats more, it worked right before the patch, as can be shown by using the hash below. Basically, if we are going to copy them, we cannot just copy them, we must go deeper as well and figure out exactly how they were being resolved before. But idk where to look, im still semi new around here. I did try, I looked through all the nixpkgs section for it I thought but its likely I missed it due to unfamiliarity. I know from my experience messing with writing a lazy.nvim wrapper, that if your grammars are not before {
inputs = {
nixpkgs = {
# commit from immediately before PR in question, if chosen instead, no bug
# url = "github:nixos/nixpkgs/19581e2ce8bc43f898ef724f8072ebf62bebb325";
url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
neovim = {
# It happens regardless of nightly, you can try too if you want.
url = "github:nix-community/neovim-nightly-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { nixpkgs, neovim, ...}: let
forAllSys = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.all;
overlayMyNeovim = prev: final: {
myNeovim = let
luaRC = final.writeText "init.lua" /*lua*/''
vim.schedule(function()
vim.cmd("packadd nvim-treesitter");
require("nvim-treesitter.configs").setup({
auto_install = false,
highlight = {
enable = true
},
})
end)
'';
in
final.wrapNeovim final.neovim {
configure = {
customRC = ''lua dofile("${luaRC}")'';
packages.all.start = with final.vimPlugins; [
];
packages.all.opt = with final.vimPlugins; [
nvim-treesitter.withAllGrammars
];
};
extraMakeWrapperArgs = ''--prefix PATH : "${final.lib.makeBinPath (with final; [ stdenv.cc.cc ])}"'';
};
};
in
{
packages = forAllSys (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [ neovim.overlays.default overlayMyNeovim ];
};
in
{ default = pkgs.myNeovim; });
};
} |
Im happy to do it but idk where to look, ive looked in the vim folder's stuff as well as here but i didnt see where it happens, anyone have any leads for me? |
nixpkgs/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix Lines 33 to 55 in 5cbbd23
Also, in withPlugins and withAllGrammars, it only links the parser anyway |
So, I think the current set of queries that WAS being used are literally the queries in the nvim-treesitter repo itself? They werent being included with the grammars and they were using the ones from nvim-treesitter likely to avoid such issues Reverting would mean no queries for parsers without queries in nvim-treesitter, but possible issues with different queries for parsers with both. Is there any easy way to solve this? |
Using queries from grammars instead of treesitter repo doesn't work, though it is less annoying (I got the issue only after 10-30 seconds, instead of every keypress) Here is the patch for fix I though about: diff --git a/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix b/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix
index c7cd3266d9c7..ae0212ae44f4 100644
--- a/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix
+++ b/pkgs/applications/editors/vim/plugins/nvim-treesitter/overrides.nix
@@ -1,4 +1,4 @@
-{ lib, callPackage, tree-sitter, neovim, neovimUtils, runCommand }:
+{ lib, callPackage, tree-sitter, neovim, neovimUtils, runCommand, symlinkJoin }:
self: super:
@@ -40,17 +40,12 @@ let
let
grammars = map grammarToPlugin
(f (tree-sitter.builtGrammars // builtGrammars));
- copyGrammar = grammar:
- let name = lib.last (lib.splitString "-" grammar.name); in
- "ln -sf ${grammar}/parser/${name}.so $out/parser/${name}.so";
in
[
- (runCommand "vimplugin-treesitter-grammars"
- { meta.platforms = lib.platforms.all; }
- ''
- mkdir -p $out/parser
- ${lib.concatMapStringsSep "\n" copyGrammar grammars}
- '')
+ (symlinkJoin {
+ name = "vimplugin-treesitter-grammars";
+ paths = grammars;
+ })
];
};
@@ -59,7 +54,7 @@ in
{
postPatch = ''
- rm -r parser
+ rm -r parser queries
'';
passthru = (super.nvim-treesitter.passthru or { }) // { See also https://ryantm.github.io/nixpkgs/builders/trivial-builders/#trivial-builder-symlinkJoin |
This looks like a good fix to me at first glance. Does it pass the minimal reproduction case above? Havent tested it out myself yet. Building the minimal case rn. |
So, it actually does a much better job of including the queries and parsers correctly compared to what was being done before. This is a much more proper way of doing what the PR this thread is about was trying to do. MUCH better than the sketchy bash script. However I pulled master, made these changes and tested it on the minimal reproduction case, and it still has the same issue, just as bad as before. On enter, and then on every edit to the file, it throws the same error. |
I dont know what is the issue though, because, this change also deletes the queries directory from nvim-treesitter in post patch. so conflicts SHOULD be impossible. So what is even the issue in the first place? Why is this error being thrown lmao |
Yeah, I also tried the MRC you wrote above, and it didn't work. This is why I left this solution as a comment, and not as a PR. Though for me, it wasn't as bad as you describe, but it doesn't matter. No idea why the problem persists
Thanks to figsoda (I miss him). I found out about P.S. I don't know how I spent so much time debugging treesitter grammars inside nix without ever reading
|
Yeah, reading the friendly manual answered a lot of my questions... I believe this is a bug in upstream, see nix-community/tree-sitter-nix#84 BTW, |
Ya know... I did read the :help treesitter manual... in january when I was building the lazy.nvim wrapper in nixCats I somehow COMPLETELY forgot about its existence. TYSM for your work and investigation, it has made a lot of how treesitter grammars work in nix much less mysterious to me. |
A NixOS#319233 accidentally reverted NixOS#321550. Last one caused a very annoying regression to any Nix user (see NixOS#332580). I suppose this is a bug in upstream grammar, so I workaround it this way until it is properly resolved.
Looks like I found the issue Also, here is what Solution for ruby would be to use grammars from Don't know how this could be done, and would love to hear what @figsoda has to say about this. Also, cannot work on a PR rn, so feel free to create one. |
The nvim-treesitter maintainer has confirmed that external queries are incompatible with nvim-treesitter in this comment: nvim-treesitter/nvim-treesitter#6870 (comment) and also clarified that nvim-treesitter doesn't use locals for highlights: nvim-treesitter/nvim-treesitter#6870 (comment) which could explain why Does that mean I'm also confused about the relationship between nvim-treesitter and the native treesitter implementation in nvim 😕 |
This wonderful person once again is saving us with treesitter grammars |
This reverts commit 98ca865.
This reverts commit 98ca865.
Originally posted by @humemm in #321550 (comment)
The text was updated successfully, but these errors were encountered: