|
1 | 1 | -- Add current directory to 'runtimepath' to be able to use 'lua' files |
2 | 2 | vim.cmd([[let &rtp.=','.getcwd()]]) |
3 | 3 |
|
4 | | --- Set up 'mini.test' only when calling headless Neovim (like with `make test`) |
5 | | -if #vim.api.nvim_list_uis() == 0 then |
6 | | - -- Add 'mini.nvim' to 'runtimepath' to be able to use 'mini.test' |
7 | | - -- Assumed that 'mini.nvim' is stored in 'deps/mini.nvim' |
8 | | - -- |
9 | | - local runtime_dependencies = { |
10 | | - "deps/mini.nvim", |
11 | | - "deps/nvim-treesitter", |
12 | | - "deps/neotest", |
13 | | - "deps/neotest-python", |
14 | | - "deps/nvim-dap", |
15 | | - "deps/nvim-dap-python", |
16 | | - "deps/nvim-lspconfig", |
17 | | - "deps/LuaSnip", |
18 | | - } |
19 | | - local runtime_path = vim.fn.join(runtime_dependencies, ",") |
20 | | - vim.cmd("set rtp+=" .. runtime_path) |
| 4 | +local runtime_dependencies = { |
| 5 | + "deps/mini.nvim", |
| 6 | + "deps/nvim-treesitter", |
| 7 | + "deps/neotest", |
| 8 | + "deps/neotest-python", |
| 9 | + "deps/nvim-dap", |
| 10 | + "deps/nvim-dap-python", |
| 11 | + "deps/nvim-lspconfig", |
| 12 | + "deps/LuaSnip", |
| 13 | +} |
| 14 | +local runtime_path = vim.fn.join(runtime_dependencies, ",") |
| 15 | +vim.cmd("set rtp+=" .. runtime_path) |
21 | 16 |
|
22 | | - -- Set up 'mini.test' |
23 | | - require("luasnip.extras.fmt") |
24 | | - require("luasnip.nodes.absolute_indexer") |
25 | | - require("nvim-treesitter.locals") |
26 | | - require("mini.test").setup() |
27 | | - require("mini.doc").setup() |
| 17 | +-- Set up 'mini.test' |
| 18 | +require("luasnip.extras.fmt") |
| 19 | +require("luasnip.nodes.absolute_indexer") |
| 20 | +require("nvim-treesitter.locals") |
| 21 | +require("nvim-treesitter").setup() |
| 22 | +require("mini.test").setup() |
| 23 | +require("mini.doc").setup() |
| 24 | +local ts_configs = require("nvim-treesitter.configs").setup({ |
| 25 | + modules = { |
| 26 | + "highlight", |
| 27 | + }, |
| 28 | + sync_install = false, |
| 29 | + auto_install = true, |
| 30 | + ignore_install = {}, |
| 31 | + ensure_installed = {}, |
| 32 | + highlight = { |
| 33 | + enable = true, |
| 34 | + }, |
| 35 | +}) |
| 36 | + |
| 37 | +-- Clean path for use in a prefix comparison |
| 38 | +---@param input string |
| 39 | +---@return string |
| 40 | +local function clean_path(input) |
| 41 | + local pth = vim.fn.fnamemodify(input, ":p") |
| 42 | + if vim.fn.has("win32") == 1 then |
| 43 | + pth = pth:gsub("/", "\\") |
| 44 | + end |
| 45 | + return pth |
| 46 | +end |
| 47 | + |
| 48 | +local function ts_is_installed(lang) |
| 49 | + local matched_parsers = vim.api.nvim_get_runtime_file("parser/" .. lang .. ".so", true) or {} |
| 50 | + local configs = require("nvim-treesitter.configs") |
| 51 | + local install_dir = configs.get_parser_install_dir() |
| 52 | + if not install_dir then |
| 53 | + return false |
| 54 | + end |
| 55 | + install_dir = clean_path(install_dir) |
| 56 | + for _, path in ipairs(matched_parsers) do |
| 57 | + local abspath = clean_path(path) |
| 58 | + if vim.startswith(abspath, install_dir) then |
| 59 | + return true |
| 60 | + end |
| 61 | + end |
| 62 | + return false |
| 63 | +end |
| 64 | + |
| 65 | +if not ts_is_installed("python") then |
| 66 | + vim.cmd("TSInstallSync python") |
28 | 67 | end |
0 commit comments