summaryrefslogtreecommitdiff
path: root/scripts/tests/minimal.vim
blob: 928594b9eb8aba8c0a55109ba7512487e02f24ee (plain)
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
" covers all package managers i am willing to cover
set rtp+=.
set rtp+=../plenary.nvim
set rtp+=../nvim-treesitter
set rtp+=~/.vim/plugged/plenary.nvim
set rtp+=~/.vim/plugged/nvim-treesitter
set rtp+=~/.local/share/nvim/site/pack/packer/start/plenary.nvim
set rtp+=~/.local/share/nvim/site/pack/packer/start/nvim-treesitter
set rtp+=~/.local/share/lunarvim/site/pack/packer/start/plenary.nvim
set rtp+=~/.local/share/lunarvim/site/pack/packer/start/nvim-treesitter
set rtp+=~/.local/share/nvim/lazy/plenary.nvim
set rtp+=~/.local/share/nvim/lazy/nvim-treesitter

set autoindent
set tabstop=4
set expandtab
set shiftwidth=4
set noswapfile

runtime! plugin/plenary.vim
runtime! plugin/nvim-treesitter.lua

lua <<EOF
local required_parsers = { "lua", "typescript", "go"}

local function missing_parsers(parsers)
  local missing = {}
  local buf = vim.api.nvim_create_buf(false, true) -- false: no list, true: scratch buffer
  for _, lang in ipairs(parsers) do
    local ok = pcall(vim.treesitter.get_parser, buf, lang)
    if not ok then
      table.insert(missing, lang)
    end
  end
  vim.api.nvim_buf_delete(buf, { force = true })
  return missing
end

local to_install = missing_parsers(required_parsers)
if #to_install > 0 then
  -- fixes 'pos_delta >= 0' error - https://github.com/nvim-lua/plenary.nvim/issues/52
  vim.cmd("set display=lastline")

  -- Only attempt installation if nvim-treesitter provided the command.
  if vim.fn.exists(":TSInstallSync") == 2 then
    -- make "TSInstall*" available
    vim.cmd("runtime! plugin/nvim-treesitter.vim")
    vim.cmd("TSInstallSync " .. table.concat(to_install, " "))
  end

  -- Re-check and fail fast with a helpful message.
  local still_missing = missing_parsers(required_parsers)
  if #still_missing > 0 then
    error(
      "Missing Tree-sitter parsers: "
        .. table.concat(still_missing, ", ")
        .. "\nInstall them via :TSInstallSync <langs> or ensure nvim-treesitter is on runtimepath."
    )
  end
end
EOF