0

I am failing to configure nvim-treesitter to automatically highlight the code upon opening a file.

After configuring nvim-treesitter by following the recommended instruction steps, this is what I get:

enter image description here

  • running :TSInstallInfo reveals that Elixir parser is not installed:

    elixir           [✗] not installed
    
  • running :TSModuleInfo reveals that for Elixir language, all modules are disabled:

            highlight  incremental_selection  indent
            ...        ...                    ...
    elixir  ✗          ✗                      ✗
            ...        ...                    ...
    

Should I "instruct" nvim-treesitter to install the parser using :TSInstall elixir and then manually enable the highlighting inside the desired buffer using :TSBufToggle highlight - the code appears to be colorised correctly:

enter image description here

What whould I change about my config to make nvim-treesitter install and enabled highlighting (and incremental selection and indent modules, for that matter) automatically?

I wasn't sure if should open a GitHub issue for this, and if so - to which project, e.g. nvim-treesitter or lazy.nvim, the package manager I am using. Hence posting my question here.

For the purpose of preparing a minimal reproduction example, I've isolated neovim's config directory, as well as its data directory into the following folder structure:

$ tree -L 2
.
├── data
├── elixir-code-sample.exs
└── nvim
    ├── init.lua
    └── lazy-lock.json
$

Here's my init.lua in its entirety:

print("Issue with tree-sitter configuration")

-- 1. bootstrap lazy.nvim
--
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

-- 2. install tree-sitter.nvim plugin
--
require("lazy").setup({{"nvim-treesitter/nvim-treesitter", build = ":TSUpdate"}})

-- 3. make things on a screen a little nicer
--
vim.cmd.colorscheme("evening")
vim.opt.termguicolors = true

Here's how I run neovim while in the root of a folder tree, displated above:

XDG_CONFIG_HOME=$(realpath .) XDG_DATA_HOME=$(realpath data) nvim elixir-sample.exs

1 Answer 1

2

It works now. Had to make the following change to a config above:

 -- 2. install tree-sitter.nvim plugin
 --
-require("lazy").setup({{"nvim-treesitter/nvim-treesitter", build = ":TSUpdate"}})
+require("lazy").setup({
+  {'nvim-treesitter/nvim-treesitter',
+    build = ":TSUpdate",
+    config = function()
+      local configs = require 'nvim-treesitter.configs'
+      configs.setup {
+        ensure_installed = {
+          'elixir',
+        },
+        highlight = {
+          enable = true
+        },
+      }
+    end,
+  }
+})

 -- 3. make things on a screen a little nicer
 --

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.