Search code examples
luaneovim

Configure vim-projectionist in Neovim with Lua


I'm using vim-projectionist with Neovim and have been able to get it working with a simple .projections.json file at the root of our project:

{
  "src/components/*.tsx": {
    "type": "components"
  }
}

Although this works, I can't check-in this file in our shared GitHub repository.

Rather than use the config file, the documentation suggests that you can set a global variable g:projectionist_heuristics for configuration instead.

As my Neovim config is entirely in Lua, I'm trying to get this working in my init.lua file.

Here is my attempt:

vim.cmd([[
let g:projectionist_heuristics = {
  \   "src/components/*.tsx": {
  \     "type": "components"
  \   }
  \ }
]])

When I open Neovim nothing happens...it seems that my vim.cmd snippet is ignored.

Or, perhaps I should be using Lua tables?

How can I configure vim-projectionist in Neovim with Lua?


Solution

  • This is how I managed to configure it in AstroNvim (https://astronvim.com/)

      {
        "tpope/vim-projectionist",
        config = function()
          vim.g.projectionist_heuristics = {
            ["*"] = {
              ["src/main/java/*.java"] = {
                alternate = "src/test/java/{}Test.java",
              },
              ["src/test/java/*Test.java"] = {
                alternate = "src/main/java/{}.java",
              },
            },
          }
        end,
        event = "User AstroFile",
      },
    

    The configuration above uses the Lazy package manager syntax: https://github.com/folke/lazy.nvim