mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
Problem: Many parsers require node/npm to evaluate the `grammar.js` before being able to generate a parser from it. Solution: Generate from `grammar.json` instead, which is fully resolved. Drops `node` and `npm` as (optional) requirements for nvim-treesitter. Note that this requires parsers to commit the generated json iff the grammar requires evaluation (which is currently the case for all tracked languages).
74 lines
1.7 KiB
Lua
74 lines
1.7 KiB
Lua
if vim.g.loaded_nvim_treesitter then
|
|
return
|
|
end
|
|
vim.g.loaded_nvim_treesitter = true
|
|
|
|
local api = vim.api
|
|
|
|
local function complete_available_parsers(arglead)
|
|
return vim.tbl_filter(
|
|
--- @param v string
|
|
function(v)
|
|
return v:find(arglead) ~= nil
|
|
end,
|
|
require('nvim-treesitter.parsers').get_available()
|
|
)
|
|
end
|
|
|
|
local function complete_installed_parsers(arglead)
|
|
return vim.tbl_filter(
|
|
--- @param v string
|
|
function(v)
|
|
return v:find(arglead) ~= nil
|
|
end,
|
|
require('nvim-treesitter.config').installed_parsers()
|
|
)
|
|
end
|
|
|
|
-- create user commands
|
|
api.nvim_create_user_command('TSInstall', function(args)
|
|
require('nvim-treesitter.install').install(args.fargs, { force = args.bang })
|
|
end, {
|
|
nargs = '+',
|
|
bang = true,
|
|
bar = true,
|
|
complete = complete_available_parsers,
|
|
desc = 'Install treesitter parsers',
|
|
})
|
|
|
|
api.nvim_create_user_command('TSInstallFromGrammar', function(args)
|
|
require('nvim-treesitter.install').install(args.fargs, {
|
|
generate = true,
|
|
force = args.bang,
|
|
})
|
|
end, {
|
|
nargs = '+',
|
|
bang = true,
|
|
bar = true,
|
|
complete = complete_available_parsers,
|
|
desc = 'Install treesitter parsers from grammar',
|
|
})
|
|
|
|
api.nvim_create_user_command('TSUpdate', function(args)
|
|
require('nvim-treesitter.install').update(args.fargs)
|
|
end, {
|
|
nargs = '*',
|
|
bar = true,
|
|
complete = complete_installed_parsers,
|
|
desc = 'Update installed treesitter parsers',
|
|
})
|
|
|
|
api.nvim_create_user_command('TSUninstall', function(args)
|
|
require('nvim-treesitter.install').uninstall(args.fargs)
|
|
end, {
|
|
nargs = '+',
|
|
bar = true,
|
|
complete = complete_installed_parsers,
|
|
desc = 'Uninstall treesitter parsers',
|
|
})
|
|
|
|
api.nvim_create_user_command('TSLog', function()
|
|
require('nvim-treesitter.log').show()
|
|
end, {
|
|
desc = 'View log messages',
|
|
})
|