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 2 years 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

I am a bit confused by the screen shot. But did you trying to load go.nvim inside a go.nvim lua file? The plugin is supposed to work in a go project.

ray-x avatar Apr 07 '23 16:04 ray-x

yes, and home-manager loads the configuration luafile $HOME/nix-files/config/nvim/plugins/go-nvim.lua as many other lua configurations that I have.

❯ cat config/nvim/plugins/go-nvim.lua             
require 'go'.setup({})

@ray-x , yes. I tested it with a golang project and I have the same issue. The behavior is go.nvim somehow overrides nvim-treesitter parser directory - parser_install_dir as mentioned above - making it to use the nvim-treesitter plugin directory which is installed under /nix/store which is read only.

Not relevant but for context.

$cat home.nix
 programs.neovim = {                                                                                                                                                                                                                                                                                                         
    enable = true;                                                                                                                                                                                                                                                                                                            
    vimAlias = true;                                                                                                                                                                                                                                                                                                          
    extraConfig = ''                                                                                                                                                                                                                                                                                                          
      source  $HOME/nix-files/config/nvim/settings/basics.vim                                                                                                                                                                                                                                                                 
      luafile $HOME/nix-files/config/nvim/settings/basics.lua                                                                                                                                                                                                                                                                 
      luafile $HOME/nix-files/config/nvim/settings/whichkey.lua                                                                                                                                                                                                                                                               
      luafile $HOME/nix-files/config/nvim/settings/keymaps.lua                                                                                                                                                                                                                                                                
      luafile $HOME/nix-files/config/nvim/plugins/nvim-tree.lua                                                                                                                                                                                                                                                               
      luafile $HOME/nix-files/config/nvim/plugins/nvim-treesitter.lua                                                                                                                                                                                                                                                         
      luafile $HOME/nix-files/config/nvim/plugins/lualine-nvim.lua                                                                                                                                                                                                                                                            
      luafile $HOME/nix-files/config/nvim/plugins/nvim-lspconfig.lua                                                                                                                                                                                                                                                          
      luafile $HOME/nix-files/config/nvim/plugins/nvim-cmp.lua                                                                                                                                                                                                                                                                
      luafile $HOME/nix-files/config/nvim/plugins/toggleterm.lua                                                                                                                                                                                                                                                              
      luafile $HOME/nix-files/config/nvim/plugins/gitsigns.lua                                                                                                                                                                                                                                                                
      luafile $HOME/nix-files/config/nvim/plugins/go-nvim.lua                                                                                                                                                                                                                                                                 
    '';                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                              
    plugins = with pkgs.vimPlugins; [                                                                                                                                                                                                                                                                                         
        vim-nix                                                                                                                                                                                                                                                                                                               
        vim-cue                                                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                              
        #colorscheme                                                                                                                                                                                                                                                                                                          
        gruvbox                                                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                              
        #identation lines                                                                                                                                                                                                                                                                                                     
        indentLine                                                                                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                                                                                                              
        #File tree                                                                                                                                                                                                                                                                                                            
        nvim-web-devicons                                                                                                                                                                                                                                                                                                     
        nvim-tree-lua                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                              
        #eye candy                                                                                                                                                                                                                                                                                                            
        nvim-treesitter                                                                                                                                                                                                                                                                                                       
        lualine-nvim                                                                                                                                                                                                                                                                                                          
        toggleterm-nvim                                                                                                                                                                                                                                                                                                       
        which-key-nvim                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                              
        #fuzzy finder                                                                                                                                                                                                                                                                                                         
        fzf-lua                                                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                                                                              
        #git                                                                                                                                                                                                                                                                                                                  
        gitsigns-nvim                                                                                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                                              
        #lsp                                                                                                                                                                                                                                                                                                                  
        nvim-lspconfig                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                              
        #completion                                                                                                                                                                                                                                                                                                           
        nvim-cmp                                                                                                                                                                                                                                                                                                              
        cmp-buffer                                                                                                                                                                                                                                                                                                            
        cmp-path                                                                                                                                                                                                                                                                                                              
        cmp-nvim-lua                                                                                                                                                                                                                                                                                                          
        cmp-nvim-lsp                                                                                                                                                                                                                                                                                                          
        luasnip                                                                                                                                                                                                                                                                                                               
        cmp_luasnip                                                                                                                                                                                                                                                                                                           
        lspkind-nvim                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                              
        ##go                                                                                                                                                                                                                                                                                                                  
        go-nvim                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
    ];                                                                                                                                                                                                                                                                                                                        
  };                               

clvx avatar Apr 07 '23 16:04 clvx

I do not think go.nvim will enforce the go parser to install in a nix directory as shown in the screenshot.

ray-x avatar Apr 08 '23 02:04 ray-x