[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 "folke/tokyonight.nvim" -- theme for generating demos
27install_plug "echasnovski/mini.test"
28
29vim.env.XDG_CONFIG_HOME = root ".tests/config"
30vim.env.XDG_DATA_HOME = root ".tests/data"
31vim.env.XDG_STATE_HOME = root ".tests/state"
32vim.env.XDG_CACHE_HOME = root ".tests/cache"
33
34vim.opt.runtimepath:append(root())
35vim.opt.packpath:append(root ".tests/site")
36vim.o.swapfile = false
37vim.o.writebackup = false
38vim.notify = vim.print
39
40-- install go treesitter parse
41require("nvim-treesitter.install").ensure_installed_sync "go"
42
43require("gopher").setup {
44 log_level = vim.log.levels.OFF,
45 timeout = 4000,
46}
47
48-- setup mini.test only when running headless nvim
49if #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 }
57end
58
59-- set colorscheme only when running ui
60if #vim.api.nvim_list_uis() == 1 then
61 vim.cmd.colorscheme "tokyonight-night"
62 vim.o.cursorline = true
63 vim.o.number = true
64end
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
68vim.api.nvim_create_autocmd("FileType", {
69 pattern = "go",
70 callback = function(args)
71 vim.treesitter.start(args.buf, "go")
72 end,
73})