mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-16 18:30:06 -04:00
feat: add option to auto-install missing parsers (#3130)
This commit is contained in:
parent
8f13ef1563
commit
365f0eb75f
4 changed files with 25 additions and 1 deletions
|
|
@ -109,6 +109,9 @@ require'nvim-treesitter.configs'.setup {
|
||||||
-- Install parsers synchronously (only applied to `ensure_installed`)
|
-- Install parsers synchronously (only applied to `ensure_installed`)
|
||||||
sync_install = false,
|
sync_install = false,
|
||||||
|
|
||||||
|
-- Automatically install missing parsers when entering buffer
|
||||||
|
auto_install = true,
|
||||||
|
|
||||||
-- List of parsers to ignore installing (for "all")
|
-- List of parsers to ignore installing (for "all")
|
||||||
ignore_install = { "javascript" },
|
ignore_install = { "javascript" },
|
||||||
|
|
||||||
|
|
@ -381,7 +384,7 @@ This directory must be writeable and must be explicitly added to the
|
||||||
|
|
||||||
If this option is not included in the setup options, or is explicitly set to
|
If this option is not included in the setup options, or is explicitly set to
|
||||||
`nil` then the default install directories will be used. If this value is set
|
`nil` then the default install directories will be used. If this value is set
|
||||||
the default directories will be ignored.
|
the default directories will be ignored.
|
||||||
|
|
||||||
Bear in mind that any parser installed into a parser folder on the runtime path
|
Bear in mind that any parser installed into a parser folder on the runtime path
|
||||||
will still be considered installed. (For example if
|
will still be considered installed. (For example if
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,9 @@ To enable supported features, put this in your `init.lua` file:
|
||||||
-- Install parsers synchronously (only applied to `ensure_installed`)
|
-- Install parsers synchronously (only applied to `ensure_installed`)
|
||||||
sync_install = false,
|
sync_install = false,
|
||||||
|
|
||||||
|
-- Automatically install missing parsers when entering buffer
|
||||||
|
auto_install = false,
|
||||||
|
|
||||||
-- List of parsers to ignore installing (for "all")
|
-- List of parsers to ignore installing (for "all")
|
||||||
ignore_install = { "javascript" },
|
ignore_install = { "javascript" },
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ local config = {
|
||||||
modules = {},
|
modules = {},
|
||||||
sync_install = false,
|
sync_install = false,
|
||||||
ensure_installed = {},
|
ensure_installed = {},
|
||||||
|
auto_install = false,
|
||||||
ignore_install = {},
|
ignore_install = {},
|
||||||
update_strategy = "lockfile",
|
update_strategy = "lockfile",
|
||||||
parser_install_dir = nil,
|
parser_install_dir = nil,
|
||||||
|
|
@ -386,6 +387,11 @@ function M.setup(user_data)
|
||||||
config.parser_install_dir = vim.fn.expand(config.parser_install_dir, ":p")
|
config.parser_install_dir = vim.fn.expand(config.parser_install_dir, ":p")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.auto_install = user_data.auto_install or false
|
||||||
|
if config.auto_install then
|
||||||
|
require("nvim-treesitter.install").setup_auto_install()
|
||||||
|
end
|
||||||
|
|
||||||
local ensure_installed = user_data.ensure_installed or {}
|
local ensure_installed = user_data.ensure_installed or {}
|
||||||
if #ensure_installed > 0 then
|
if #ensure_installed > 0 then
|
||||||
if user_data.sync_install then
|
if user_data.sync_install then
|
||||||
|
|
|
||||||
|
|
@ -425,6 +425,18 @@ local function install(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.setup_auto_install()
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = { "*" },
|
||||||
|
callback = function()
|
||||||
|
local lang = parsers.get_buf_lang()
|
||||||
|
if parsers.get_parser_configs()[lang] and not parsers.has_parser(lang) then
|
||||||
|
install { ask_reinstall = true } { lang }
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
function M.update(options)
|
function M.update(options)
|
||||||
options = options or {}
|
options = options or {}
|
||||||
return function(...)
|
return function(...)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue