all repos

gopher.nvim @ 906e340b4f84e92ebccfb0d43039939f13095dce

Minimalistic plugin for Go development

gopher.nvim/scripts/minimal_init.lua(view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
local function root(p)
  local f = debug.getinfo(1, "S").source:sub(2)
  return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (p or "")
end

local function install_plug(plugin)
  local name = plugin:match ".*/(.*)"
  local package_root = root ".tests/site/pack/deps/start/"
  if not vim.uv.fs_stat(package_root .. name) then
    print("Installing " .. plugin)
    vim
      .system({
        "git",
        "clone",
        "--depth=1",
        "https://github.com/" .. plugin .. ".git",
        package_root .. "/" .. name,
      })
      :wait()
  end
end

install_plug "nvim-treesitter/nvim-treesitter"
install_plug "echasnovski/mini.doc" -- used for docs generation
install_plug "folke/tokyonight.nvim" -- theme for generating demos
install_plug "echasnovski/mini.test"

vim.env.XDG_CONFIG_HOME = root ".tests/config"
vim.env.XDG_DATA_HOME = root ".tests/data"
vim.env.XDG_STATE_HOME = root ".tests/state"
vim.env.XDG_CACHE_HOME = root ".tests/cache"

vim.opt.runtimepath:append(root())
vim.opt.packpath:append(root ".tests/site")
vim.o.swapfile = false
vim.o.writebackup = false
vim.notify = vim.print

-- install go treesitter parse
require("nvim-treesitter.install").ensure_installed_sync "go"

require("gopher").setup {
  log_level = vim.log.levels.OFF,
  timeout = 4000,
}

-- setup mini.test only when running headless nvim
if #vim.api.nvim_list_uis() == 0 then
  require("mini.test").setup {
    collect = {
      find_files = function()
        return vim.fn.globpath("spec", "**/*_test.lua", true, true)
      end,
    },
  }
end

-- set colorscheme only when running ui
if #vim.api.nvim_list_uis() == 1 then
  vim.cmd.colorscheme "tokyonight-night"
  vim.o.cursorline = true
  vim.o.number = true
end

-- needed for tests, i dont know the reason why, but on start
-- vim is not able to use treesitter for go by default
vim.api.nvim_create_autocmd("FileType", {
  pattern = "go",
  callback = function(args)
    vim.treesitter.start(args.buf, "go")
  end,
})