[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-treesitter/nvim-treesitter"
24install_plug "echasnovski/mini.doc" -- used for docs generation
25install_plug "folke/tokyonight.nvim" -- theme for generating demos
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.o.swapfile = false
36vim.o.writebackup = false
37vim.notify = vim.print
38
39-- install go treesitter parse
40require("nvim-treesitter.install").ensure_installed_sync "go"
41
42require("gopher").setup {
43 log_level = vim.log.levels.OFF,
44 timeout = 4000,
45}
46
47-- setup mini.test only when running headless nvim
48if #vim.api.nvim_list_uis() == 0 then
49 require("mini.test").setup {
50 collect = {
51 find_files = function()
52 return vim.fn.globpath("spec", "**/*_test.lua", true, true)
53 end,
54 },
55 }
56end
57
58-- set colorscheme only when running ui
59if #vim.api.nvim_list_uis() == 1 then
60 vim.cmd.colorscheme "tokyonight-night"
61 vim.o.cursorline = true
62 vim.o.number = true
63end
64
65-- needed for tests, i dont know the reason why, but on start
66-- vim is not able to use treesitter for go by default
67vim.api.nvim_create_autocmd("FileType", {
68 pattern = "go",
69 callback = function(args)
70 vim.treesitter.start(args.buf, "go")
71 end,
72})