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

nvim-treesitter: declarative install of parsers causes errors #189838

Closed
NickHu opened this issue Sep 5, 2022 · 32 comments
Closed

nvim-treesitter: declarative install of parsers causes errors #189838

NickHu opened this issue Sep 5, 2022 · 32 comments
Labels
0.kind: bug Something is broken 6.topic: vim

Comments

@NickHu
Copy link
Contributor

NickHu commented Sep 5, 2022

Describe the bug

If I install my treesitter parsers declaratively, e.g. as in https://nixos.wiki/wiki/Tree_sitters with nvim-treesitter.withPlugins, starting neovim spawns the following error:

               Error detected while processing /home/nick/.config/nvim/init.vim:                                               
line  136:                                                                                                                     
Parser dir ' /nix/store/zr7p6wy4v4nwigi8ryx8cqhmyf2i1wq3-vim-pack-dir/pack/myNeovimPackages/start/nvim-treesitter/parser ' shou
ld be read/write (see README on how to configure an alternative install location) /nix/store/zr7p6wy4v4nwigi8ryx8cqhmyf2i1wq3-v
im-pack-dir/pack/myNeovimPackages/start/nvim-treesitter/parser ' 

Expected behavior

No errors

Additional context

I think this was changed recently upstream in nvim-treesitter. Indeed, the README now stipulates that the parser directory must be RW (although I'm not really sure why, so long as one doesn't use the :TSInstall/Update/Remove stuff). Not sure if this error is merely cosmetic or functional (I don't know how to test if treesitter is working properly).

Notify maintainers

@teto

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.15.63, NixOS, 22.11 (Raccoon), 22.11.20220901.2da64a8`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.0`
 - channels(root): `"home-manager, nixos"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
@teto
Copy link
Member

teto commented Sep 5, 2022

I've commented on nvim-treesitter/nvim-treesitter#3250, meanwhile revert nvim-treesitter to a previous version.

@mdarocha
Copy link
Contributor

mdarocha commented Sep 7, 2022

This is fixed for me by adding ensure_installed = {} to nvim-treesitter configuration.

@teto
Copy link
Member

teto commented Sep 7, 2022

This seems more like a workaround than a proper fix though.

@jack-michaud
Copy link
Contributor

jack-michaud commented Sep 19, 2022

Following the instructions in the readme to specify an alternate treesitter plugin installation path worked for me.

In init.vim,

-- Defines a read-write directory for treesitters in nvim's cache dir
local parser_install_dir = vim.fn.stdpath("cache") .. "/treesitters"
vim.fn.mkdir(parser_install_dir, "p")
-- Prevents reinstall of treesitter plugins every boot
vim.opt.runtimepath:append(parser_install_dir)

-- In your treesitter config,
require('nvim-treesitter.configs').setup {
  -- ...
  parser_install_dir = parser_install_dir
}

Updated with @vasyharan's fix to add parser_install_dir to vim's runtimepath, which fixes the reinstall issue.

@portothree
Copy link
Contributor

Following the instructions in the readme to specify an alternate treesitter plugin installation path worked for me.

In init.vim,

-- Defines a read-write directory for treesitters in nvim's cache dir
local parser_install_dir = vim.fn.stdpath("cache") .. "/treesitters"
vim.fn.mkdir(parser_install_dir, "p")

-- In your treesitter config,
require('nvim-treesitter.configs').setup {
  -- ...
  parser_install_dir = parser_install_dir
}

Thanks, this worked for me as well.

@NickHu
Copy link
Contributor Author

NickHu commented Sep 20, 2022

Does that solution still pick up your declaratively installed tree sitters?

@jack-michaud
Copy link
Contributor

Does that solution still pick up your declaratively installed tree sitters?

Unfortunately no -- I specify my treesitter plugins via ensure_installed in the treesitter config.

Another drawback to this approach is that the treesitter parsers seem to re-install every time I open nvim (not sure if @portothree is seeing this too?) - but this may be a separate treesitter bug.

@portothree
Copy link
Contributor

Another drawback to this approach is that the treesitter parsers seem to re-install every time I open nvim (not sure if @portothree is seeing this too?) - but this may be a separate treesitter bug.

I haven't encoutered this, no. Unless this is being done in the background, do you get a message of parsers being downloaded everytime you open nvim?

cixel added a commit to cixel/config that referenced this issue Sep 21, 2022
This is a workaround for an issue where treesitter expects the install
dir to be readable and writable -- it's not happy with now nix is
installing it. Unless there's a patch, the fix will be to manually set
the install dir to a good location:

NixOS/nixpkgs#189838 (comment)
samhh added a commit to samhh/dotfiles that referenced this issue Sep 26, 2022
The nvim change is to workaround this:
  NixOS/nixpkgs#189838
mandu added a commit to mandu/nixos-config that referenced this issue Oct 11, 2022
@vasyharan
Copy link

Another drawback to this approach is that the treesitter parsers seem to re-install every time I open nvim (not sure if @portothree is seeing this too?) - but this may be a separate treesitter bug.

I saw this happen when I didn't append the parser_install_dir to the runtime path. fixed with:

local parser_install_dir = vim.fn.stdpath("cache") .. "/treesitters"
vim.fn.mkdir(parser_install_dir, "p")
vim.opt.runtimepath:append(parser_install_dir)

@NickHu
Copy link
Contributor Author

NickHu commented Nov 21, 2022

I think this no longer happens now, and one can use pkgs.nvim-treesitter.withAllGrammars without issue (thanks @figsoda!)

@jocelynthode
Copy link
Contributor

I can confirm that using withAllGrammars completely fixed the issue on my end.

@NickHu NickHu closed this as completed Nov 21, 2022
@samhh
Copy link
Contributor

samhh commented Nov 21, 2022

Removing the Lua workarounds and changing from nvim-treesitter to nvim-treesitter.withAllGrammars as of 52b2ac8 causes this on launch for me:

Error detected while processing /home/sam/.config/nvim/plugin/treesitter.lua:
Parser dir ' /nix/store/52lh6vpwsbmghgz6z1hgmh408n675jzh-vim-pack-dir/pack/myNeovimPackages/start/nvim
-treesitter/parser ' should be read/write (see README on how to configure an alternative install locat
ion) /nix/store/52lh6vpwsbmghgz6z1hgmh408n675jzh-vim-pack-dir/pack/myNeovimPackages/start/nvim-treesit
ter/parser '

@mdarocha
Copy link
Contributor

Removing the Lua workarounds and changing from nvim-treesitter to nvim-treesitter.withAllGrammars as of 52b2ac8 causes this on launch for me:

Error detected while processing /home/sam/.config/nvim/plugin/treesitter.lua:
Parser dir ' /nix/store/52lh6vpwsbmghgz6z1hgmh408n675jzh-vim-pack-dir/pack/myNeovimPackages/start/nvim
-treesitter/parser ' should be read/write (see README on how to configure an alternative install locat
ion) /nix/store/52lh6vpwsbmghgz6z1hgmh408n675jzh-vim-pack-dir/pack/myNeovimPackages/start/nvim-treesit
ter/parser '

Does not happen in 690ffff026b4e635b46f69002c0f4e81c65dfc2e

@figsoda
Copy link
Member

figsoda commented Nov 21, 2022

@samhh were you trying to run TSInstall? that might have been caused by #201548, does #202196 fix the issue for you?

@samhh
Copy link
Contributor

samhh commented Nov 21, 2022

Possibly? I had that error on launch earlier. Just now I tried your PR, and now it works even without the PR in my overlay. Not sure what to make of that. 😅 Thank you in any case!

@figsoda
Copy link
Member

figsoda commented Nov 21, 2022

No problem! I will go ahead and merge that anyways in case it caused the problem

KyleOndy added a commit to KyleOndy/dotfiles that referenced this issue Dec 2, 2022
It never really worked, and always seemed to break. Trying some new
things.

the biggest functional change seems to be changing
`nvim-treesitter.withPlugins (plugins: pkgs.tree-sitter.allGrammars)` to
`nvim-treesitter.withAllGrammars`. This was foind burried in a github
issue [1]. I did not do any research beyond copy and paste.

[1]: NixOS/nixpkgs#189838 (comment)
@p3t33
Copy link

p3t33 commented Dec 28, 2022

I stumbled on the same issue as OP and tried to solve by doing the two paths that worked here.

The first is by using withAllGrammars
programs.neovim.plugins = [ pkgs.vimPlugins.nvim-treesitter.withAllGrammars ];
I took the settings from @jocelynthode
And after executing TSModuleInfo I can see that all(most of them) are installed.

The second path was by providing an alternative path and using pkgs.vimPlugins.nvim-treesitter. I was able to provide the languages I wanted and they were installed on the first time I started neovim. And executing TSModuleInfo showed them installed.

The issue is that I see zero efficient on neovim. I made sure that as part of the settings for the plugin highlight = {enable = true, }. As I said I copied the settings from @jocelynthode

I am now not sure if there is some kind of a bug or It is me doing something wrong.

@teto
Copy link
Member

teto commented Dec 28, 2022

with @figsoda's guidance, we can now specify the treesitter plugin dependencies 025d862 in case that helps.

@p3t33
Copy link

p3t33 commented Jan 4, 2023

So deciding if treesitter is active only based of shine colors isn't the best approach, especially when there are other settings/plugins that may effect the color scheme.

A better "test" for if treesitter "is working" is to look into something like textobjects(nvim-treesitter-textobjects). A basic test for me(After configuring textobjects) was to try and do visual select a function/inside function and that it is working.

@mdarocha
Copy link
Contributor

mdarocha commented Jan 4, 2023

So deciding if treesitter is active only based of shine colors isn't the best approach, especially when there are other settings/plugins that may effect the color scheme.

A better "test" for if treesitter "is working" is to look into something like textobjects(nvim-treesitter-textobjects). A basic test for me(After configuring textobjects) was to try and do visual select a function/inside function and that it is working.

If you mean manually checking if treesitter is working, there is also :checkhealth

@figsoda
Copy link
Member

figsoda commented Jan 4, 2023

We already check the queries for nvim-treesitter (not textobjects) which is pretty much equivalent to the table in :checkhealth

@gshpychka
Copy link
Contributor

Just to confirm - is nvim-treesitter.withPlugins expected to work now?

@figsoda
Copy link
Member

figsoda commented Jan 6, 2023

yes, it can be used like this:

nvim-treesitter.withPlugins (p: [ p.c p.python ])

@ghostbuster91
Copy link
Member

ghostbuster91 commented Jan 12, 2023

It seems to work for all grammars apart from the tree-sitter one itself - tree-sitter-query.
Both checkhealth and TSInstallInfo show that it is installed but once I open *.scm file I get an error message that it cannot be found.

@figsoda
Copy link
Member

figsoda commented Jan 12, 2023

@ghostbuster91 Can you post the error meesages and the relevant parts of your setup?

@ghostbuster91
Copy link
Member

It seems to me that there is nothing specific there but yes, here you go:
nix:

 (nvim-treesitter.withPlugins (
        plugins:
          with plugins; [
            tree-sitter-query # for the tree-sitter itself
            tree-sitter-python
            ...and many others
          ]
      ))

full file: https://github.com/ghostbuster91/dot-files/blob/c058ed66f23b85725e96f2dfc35d84e7bd30c48b/programs/neovim/default.nix#L111

lua:

require("nvim-treesitter.configs").setup({
    ensure_installed = {},
    highlight = {
        enable = true, 
        additional_vim_regex_highlighting = false,
        disable = {}, -- treesitter interferes with VimTex
    },
})

full file: https://github.com/ghostbuster91/dot-files/blob/c058ed66f23b85725e96f2dfc35d84e7bd30c48b/programs/neovim/init.lua#L279

The error message:
image

@figsoda
Copy link
Member

figsoda commented Jan 12, 2023

@ghostbuster91 this seems like it might be an upstream issue, disabling query_linter or renaming the directory to scala could be a temporary solution

@ghostbuster91
Copy link
Member

ghostbuster91 commented Jan 12, 2023

Interesting, disabling query_linter helps indeed. Do you know if there is already an issue for that?

@figsoda
Copy link
Member

figsoda commented Jan 12, 2023

Having taken a brief look at https://github.com/nvim-treesitter/playground, I'm not aware of any issues for this

@ghostbuster91
Copy link
Member

ghostbuster91 commented Jan 12, 2023

Thanks @figsoda, I will then create one.

@figsoda
Copy link
Member

figsoda commented Jan 12, 2023

I opened nvim-treesitter/playground#111 to fix this

@ghostbuster91
Copy link
Member

@figsoda Thanks, I appreciate it :)

KyleOndy added a commit to KyleOndy/dotfiles that referenced this issue Mar 29, 2023
It never really worked, and always seemed to break. Trying some new
things.

the biggest functional change seems to be changing
`nvim-treesitter.withPlugins (plugins: pkgs.tree-sitter.allGrammars)` to
`nvim-treesitter.withAllGrammars`. This was foind burried in a github
issue [1]. I did not do any research beyond copy and paste.

[1]: NixOS/nixpkgs#189838 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: vim
Projects
None yet
Development

No branches or pull requests