mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-02 03:26:52 -04:00
feat!: drop modules, general refactor and cleanup
This commit is contained in:
parent
c13e28f894
commit
2c8f2f2fad
829 changed files with 4905 additions and 8010 deletions
|
|
@ -1,34 +1,86 @@
|
|||
-- Last Change: 2022 Apr 16
|
||||
|
||||
if vim.g.loaded_nvim_treesitter then
|
||||
return
|
||||
end
|
||||
vim.g.loaded_nvim_treesitter = true
|
||||
|
||||
-- setup modules
|
||||
require("nvim-treesitter").setup()
|
||||
|
||||
local api = vim.api
|
||||
|
||||
-- define autocommands
|
||||
local augroup = api.nvim_create_augroup("NvimTreesitter", {})
|
||||
local function complete_available_parsers(arglead)
|
||||
return vim.iter.filter(function(v)
|
||||
return v:find(arglead)
|
||||
end, require('nvim-treesitter.parsers').get_available())
|
||||
end
|
||||
|
||||
api.nvim_create_autocmd("Filetype", {
|
||||
pattern = "query",
|
||||
group = augroup,
|
||||
callback = function()
|
||||
api.nvim_clear_autocmds {
|
||||
group = augroup,
|
||||
event = "BufWritePost",
|
||||
}
|
||||
api.nvim_create_autocmd("BufWritePost", {
|
||||
group = augroup,
|
||||
buffer = 0,
|
||||
callback = function(opts)
|
||||
require("nvim-treesitter.query").invalidate_query_file(opts.file)
|
||||
end,
|
||||
desc = "Invalidate query file",
|
||||
})
|
||||
end,
|
||||
desc = "Reload query",
|
||||
local function complete_installed_parsers(arglead)
|
||||
return vim.iter.filter(function(v)
|
||||
return v:find(arglead)
|
||||
end, require('nvim-treesitter.config').installed_parsers())
|
||||
end
|
||||
|
||||
-- create user commands
|
||||
api.nvim_create_user_command('TSInstallInfo', function()
|
||||
require('nvim-treesitter.install').info()
|
||||
end, { nargs = 0, desc = 'List available treesitter parsers' })
|
||||
|
||||
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_from_grammar = 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('TSInstallSync', function(args)
|
||||
require('nvim-treesitter.install').install(args.fargs, {
|
||||
with_sync = true,
|
||||
force = args.bang,
|
||||
})
|
||||
end, {
|
||||
nargs = '+',
|
||||
bang = true,
|
||||
bar = true,
|
||||
complete = complete_available_parsers,
|
||||
desc = 'Install treesitter parsers synchronously',
|
||||
})
|
||||
|
||||
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('TSUpdateSync', function(args)
|
||||
require('nvim-treesitter.install').update(args.fargs, { with_sync = true })
|
||||
end, {
|
||||
nargs = '*',
|
||||
bar = true,
|
||||
complete = complete_installed_parsers,
|
||||
desc = 'Update installed treesitter parsers synchronously',
|
||||
})
|
||||
|
||||
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',
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue