go.nvim icon indicating copy to clipboard operation
go.nvim copied to clipboard

Syntax highlighting using nvim-treesitter, go.nvim and nix.

Open clvx opened this issue 1 year ago • 3 comments

go.nvim fails to load nvim-tresitter parser_install_dir correctly for new buffers.

nvim-treesitter.lua:

-- Defines a read-write directory for treesitters in nvim's cache dir
-- As /nix/store is read only, parsers need a new directory.
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)

require'nvim-treesitter.configs'.setup {

  -- uses the custom parser directory
  parser_install_dir = parser_install_dir,
}

Opening a new buffer loads without syntax highlighting throwing the following error:

Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: ...b-neovim-unwrapped-0.8.3/share/nvim/runtime/filetype.lua:22: Error executing lua: ...b-neovim-unwrapped-0.8.3/share/nvim/runtime/filetype.lua:23: Vim(append):Could not create parser dir ' /nix/store/zjs1l6wyfgrcflm08g59g4ndrllh56mg-vim-pack-dir/pack/myNeovimPackages/start/nvim-treesit
ter/parser ':  Vim:E739: Cannot create directory /nix/store/zjs1l6wyfgrcflm08g59g4ndrllh56mg-vim-pack-dir/pack/myNeovimPackages/start/nvim-treesitter/parser: permission denied
stack traceback:
        [C]: in function 'nvim_cmd'
        ...b-neovim-unwrapped-0.8.3/share/nvim/runtime/filetype.lua:23: in function <...b-neovim-unwrapped-0.8.3/share/nvim/runtime/filetype.lua:22>
        [C]: in function 'nvim_buf_call'
        ...b-neovim-unwrapped-0.8.3/share/nvim/runtime/filetype.lua:22: in function <...b-neovim-unwrapped-0.8.3/share/nvim/runtime/filetype.lua:11>
stack traceback:
        [C]: in function 'nvim_buf_call'
        ...b-neovim-unwrapped-0.8.3/share/nvim/runtime/filetype.lua:22: in function <...b-neovim-unwrapped-0.8.3/share/nvim/runtime/filetype.lua:11>
:lua print(vim.inspect(vim.api.nvim_list_runtime_paths()))

{ "/nix/store/zjs1l6wyfgrcflm08g59g4ndrllh56mg-vim-pack-dir", ..., <omitting other /nix/store/paths>,..., "/home/clvx/.cache/nvim/treesitters" }

Screenshot from 2023-04-06 06-36-37 Screenshot from 2023-04-06 06-37-06

Without go.nvim it works as expected. nvim-treesitter tries to install the parser in parser_install_dir if there's none.

clvx avatar Apr 06 '23 12:04 clvx