feat(install): add "maintained" option to only install maintained parsers

Unmaintained parsers only give users little benefit but take sometimes a
a long time to install (e.g. Markdown, Julia, Haskell parser). We could
recommend to only install maintained parsers by default.
This commit is contained in:
Stephan Seitz 2020-09-27 12:13:11 +02:00 committed by Stephan Seitz
parent 04ff77442a
commit c3b526fe51
5 changed files with 16 additions and 5 deletions

View file

@ -106,7 +106,7 @@ so you'll need to activate them by putting this in your `init.vim` file:
```lua
require'nvim-treesitter.configs'.setup {
ensure_installed = "all", -- one of "all", "language", or a list of languages
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
highlight = {
enable = true, -- false will disable the whole extension
disable = { "c", "rust" }, -- list of language that will be disabled

View file

@ -7,11 +7,11 @@ function! nvim_treesitter#foldexpr() abort
endfunction
function! nvim_treesitter#installable_parsers(arglead, cmdline, cursorpos) abort
return join(luaeval("require'nvim-treesitter.parsers'.available_parsers()") + ['all'], "\n")
return join(luaeval("require'nvim-treesitter.parsers'.available_parsers()") + ['all', 'maintained'], "\n")
endfunction
function! nvim_treesitter#installed_parsers(arglead, cmdline, cursorpos) abort
return join(luaeval("require'nvim-treesitter.info'.installed_parsers()") + ['all'], "\n")
return join(luaeval("require'nvim-treesitter.info'.installed_parsers()") + ['all', 'maintained'], "\n")
endfunction
function! nvim_treesitter#available_modules(arglead, cmdline, cursorpos) abort

View file

@ -36,7 +36,7 @@ To enable supported features, put this in your `init.vim` file:
>
lua <<EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = "all", -- one of "all", "language", or a list of languages
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
highlight = {
enable = true, -- false will disable the whole extension
disable = { "c", "rust" }, -- list of language that will be disabled

View file

@ -188,6 +188,9 @@ local function install(with_sync, ask_reinstall)
if ... == 'all' then
languages = parsers.available_parsers()
ask = false
elseif ... == 'maintained' then
languages = parsers.maintained_parsers()
ask = false
else
languages = vim.tbl_flatten({...})
ask = ask_reinstall
@ -221,9 +224,13 @@ function M.uninstall(lang)
path_sep = '\\'
end
if lang == 'all' then
if vim.tbl_contains({'all', 'maintained'}, lang) then
reset_progress_counter()
local installed = info.installed_parsers()
if lang == "maintained" then
local maintained = parsers.maintained_parsers()
installed = vim.tbl_filter(function(l) return vim.tbl_contains(maintained, l) end, installed)
end
for _, lang in pairs(installed) do
M.uninstall(lang)
end

View file

@ -357,6 +357,10 @@ function M.available_parsers()
return vim.tbl_keys(M.list)
end
function M.maintained_parsers()
return vim.tbl_filter(function(lang) return M.list[lang].maintainers end, M.available_parsers())
end
function M.get_parser_configs()
return M.list
end