[mirror] Make your go dev experience better
github.com/olexsmir/gopher.nvim
neovim
golang
1local function root(p)
2 local f = debug.getinfo(1, "S").source:sub(2)
3 return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (p or "")
4end
5
6local 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
21end
22
23install_plug "nvim-lua/plenary.nvim"
24install_plug "nvim-treesitter/nvim-treesitter"
25install_plug "echasnovski/mini.doc" -- used for docs generation
26install_plug "echasnovski/mini.test"
27
28vim.env.XDG_CONFIG_HOME = root ".tests/config"
29vim.env.XDG_DATA_HOME = root ".tests/data"
30vim.env.XDG_STATE_HOME = root ".tests/state"
31vim.env.XDG_CACHE_HOME = root ".tests/cache"
32
33vim.opt.runtimepath:append(root())
34vim.opt.packpath:append(root ".tests/site")
35vim.notify = vim.print
36
37-- install go treesitter parse
38require("nvim-treesitter.install").ensure_installed_sync "go"
39
40require("gopher").setup {
41 log_level = vim.log.levels.OFF,
42 timeout = 4000,
43}
44
45-- setup mini.test only when running headless nvim
46if #vim.api.nvim_list_uis() == 0 then
47 require("mini.test").setup {
48 collect = {
49 find_files = function()
50 return vim.fn.globpath("spec", "**/*_test.lua", true, true)
51 end,
52 },
53 }
54end
55
56-- needed for tests, i dont know the reason why, but on start
57-- vim is not able to use treesitter for go by default
58vim.api.nvim_create_autocmd("FileType", {
59 pattern = "go",
60 callback = function(args)
61 vim.treesitter.start(args.buf, "go")
62 end,
63})