minimal_init.lua
1 local function root(p) 2 local f = debug.getinfo(1, "S").source:sub(2) 3 return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (p or "") 4 end 5 6 local function install_plug(plugin) 7 local name = plugin:match ".*/(.*)" 8 local package_root = root ".tests/site/pack/deps/start/" 9 if not vim.uv.fs_stat(package_root .. name) then 10 print("Installing " .. plugin) 11 vim 12 .system({ 13 "git", 14 "clone", 15 "--depth=1", 16 "https://github.com/" .. plugin .. ".git", 17 package_root .. "/" .. name, 18 }) 19 :wait() 20 end 21 end 22 23 install_plug "nvim-lua/plenary.nvim" 24 install_plug "nvim-treesitter/nvim-treesitter" 25 install_plug "echasnovski/mini.doc" -- used for docs generation 26 install_plug "folke/tokyonight.nvim" -- theme for generating demos 27 install_plug "echasnovski/mini.test" 28 29 vim.env.XDG_CONFIG_HOME = root ".tests/config" 30 vim.env.XDG_DATA_HOME = root ".tests/data" 31 vim.env.XDG_STATE_HOME = root ".tests/state" 32 vim.env.XDG_CACHE_HOME = root ".tests/cache" 33 34 vim.opt.runtimepath:append(root()) 35 vim.opt.packpath:append(root ".tests/site") 36 vim.o.swapfile = false 37 vim.o.writebackup = false 38 vim.notify = vim.print 39 40 -- install go treesitter parse 41 require("nvim-treesitter.install").ensure_installed_sync "go" 42 43 require("gopher").setup { 44 log_level = vim.log.levels.OFF, 45 timeout = 4000, 46 } 47 48 -- setup mini.test only when running headless nvim 49 if #vim.api.nvim_list_uis() == 0 then 50 require("mini.test").setup { 51 collect = { 52 find_files = function() 53 return vim.fn.globpath("spec", "**/*_test.lua", true, true) 54 end, 55 }, 56 } 57 end 58 59 -- set colorscheme only when running ui 60 if #vim.api.nvim_list_uis() == 1 then 61 vim.cmd.colorscheme "tokyonight-night" 62 vim.o.cursorline = true 63 vim.o.number = true 64 end 65 66 -- needed for tests, i dont know the reason why, but on start 67 -- vim is not able to use treesitter for go by default 68 vim.api.nvim_create_autocmd("FileType", { 69 pattern = "go", 70 callback = function(args) 71 vim.treesitter.start(args.buf, "go") 72 end, 73 })