aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorJonas Strittmatter <40792180+smjonas@users.noreply.github.com>2022-07-08 09:36:54 +0200
committerGitHub <noreply@github.com>2022-07-08 07:36:54 +0000
commit365f0eb75f4b8de4655476388c99aaa97f149ded (patch)
treef10dcb86f85baa296573c9017f0754246f64dd45 /lua
parenthighlights(c): highlight `,` operator as operator (#3107) (diff)
downloadnvim-treesitter-365f0eb75f4b8de4655476388c99aaa97f149ded.tar
nvim-treesitter-365f0eb75f4b8de4655476388c99aaa97f149ded.tar.gz
nvim-treesitter-365f0eb75f4b8de4655476388c99aaa97f149ded.tar.bz2
nvim-treesitter-365f0eb75f4b8de4655476388c99aaa97f149ded.tar.lz
nvim-treesitter-365f0eb75f4b8de4655476388c99aaa97f149ded.tar.xz
nvim-treesitter-365f0eb75f4b8de4655476388c99aaa97f149ded.tar.zst
nvim-treesitter-365f0eb75f4b8de4655476388c99aaa97f149ded.zip
feat: add option to auto-install missing parsers (#3130)
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/configs.lua6
-rw-r--r--lua/nvim-treesitter/install.lua12
2 files changed, 18 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua
index ee01f3ede..41310f544 100644
--- a/lua/nvim-treesitter/configs.lua
+++ b/lua/nvim-treesitter/configs.lua
@@ -13,6 +13,7 @@ local config = {
modules = {},
sync_install = false,
ensure_installed = {},
+ auto_install = false,
ignore_install = {},
update_strategy = "lockfile",
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")
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 {}
if #ensure_installed > 0 then
if user_data.sync_install then
diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua
index e709849ad..be980ca0f 100644
--- a/lua/nvim-treesitter/install.lua
+++ b/lua/nvim-treesitter/install.lua
@@ -425,6 +425,18 @@ local function install(options)
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)
options = options or {}
return function(...)