summaryrefslogtreecommitdiff
path: root/lua/lvim/core/treesitter.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lvim/core/treesitter.lua')
-rw-r--r--lua/lvim/core/treesitter.lua70
1 files changed, 1 insertions, 69 deletions
diff --git a/lua/lvim/core/treesitter.lua b/lua/lvim/core/treesitter.lua
index 560118f8..456a2955 100644
--- a/lua/lvim/core/treesitter.lua
+++ b/lua/lvim/core/treesitter.lua
@@ -20,7 +20,7 @@ function M.config()
sync_install = false,
-- Automatically install missing parsers when entering buffer
- auto_install = false,
+ auto_install = true,
matchup = {
enable = false, -- mandatory, false will disable the whole extension
@@ -95,69 +95,6 @@ function M.config()
}
end
----@class bundledParsersOpts
----@field name_only boolean
----@field filter function
-
----Retrives a list of bundled parsers paths (any parser not found in default `install_dir`)
----@param opts bundledParsersOpts
----@return string[]
-local function get_parsers(opts)
- opts = opts or {}
- opts.filter = opts.filter or function()
- return true
- end
-
- local bundled_parsers = vim.tbl_filter(opts.filter, vim.api.nvim_get_runtime_file("parser/*.so", true))
-
- if opts.name_only then
- bundled_parsers = vim.tbl_map(function(parser)
- return vim.fn.fnamemodify(parser, ":t:r")
- end, bundled_parsers)
- end
-
- return bundled_parsers
-end
-
----Checks if parser is installed with nvim-treesitter
----@param lang string
----@return boolean
-local function is_installed(lang)
- local configs = require "nvim-treesitter.configs"
- local result = get_parsers {
- filter = function(parser)
- local install_dir = configs.get_parser_install_dir()
- return vim.startswith(parser, install_dir) and (vim.fn.fnamemodify(parser, ":t:r") == lang)
- end,
- }
- local parser_file = result and result[1] or ""
- local stat = vim.loop.fs_stat(parser_file)
- return stat and stat.type == "file"
-end
-
-local function ensure_updated_bundled()
- local configs = require "nvim-treesitter.configs"
- local bundled_parsers = get_parsers {
- name_only = true,
- filter = function(parser)
- local install_dir = configs.get_parser_install_dir()
- return not vim.startswith(parser, install_dir)
- end,
- }
-
- vim.api.nvim_create_autocmd("VimEnter", {
- callback = function()
- local missing = vim.tbl_filter(function(parser)
- return not is_installed(parser)
- end, bundled_parsers)
-
- if #missing > 0 then
- vim.cmd { cmd = "TSInstall", args = missing, bang = true }
- end
- end,
- })
-end
-
function M.setup()
-- avoid running in headless mode since it's harder to detect failures
if #vim.api.nvim_list_uis() == 0 then
@@ -175,14 +112,9 @@ function M.setup()
treesitter_configs.setup(opts)
- ensure_updated_bundled()
-
if lvim.builtin.treesitter.on_config_done then
lvim.builtin.treesitter.on_config_done(treesitter_configs)
end
end
-M.get_parsers = get_parsers
-M.is_installed = is_installed
-
return M