nvim: Update treesitter config to nvim 0.12
This commit is contained in:
@@ -3,36 +3,14 @@ return {
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
branch = "main",
|
||||
lazy = false,
|
||||
event = {
|
||||
"BufReadPre",
|
||||
"BufNewFile",
|
||||
},
|
||||
main = "nvim-treesitter",
|
||||
build = ":TSUpdate",
|
||||
dependencies = {
|
||||
"windwp/nvim-ts-autotag",
|
||||
},
|
||||
config = function()
|
||||
require("nvim-treesitter").setup({
|
||||
highlight = {
|
||||
enable = true,
|
||||
},
|
||||
indent = {
|
||||
enable = true,
|
||||
},
|
||||
autotag = {
|
||||
enable = true,
|
||||
},
|
||||
incremental_selection = {
|
||||
enable = true,
|
||||
keymaps = {
|
||||
init_selection = "<C-space>",
|
||||
node_incremental = "<C-space>",
|
||||
scope_incremental = false,
|
||||
node_decremental = "<bs>",
|
||||
},
|
||||
},
|
||||
})
|
||||
require("nvim-treesitter").setup()
|
||||
require("nvim-ts-autotag").setup()
|
||||
|
||||
local parsers = {
|
||||
"bash",
|
||||
@@ -54,16 +32,34 @@ return {
|
||||
"markdown_inline",
|
||||
"php",
|
||||
"svelte",
|
||||
"tsx",
|
||||
"twig",
|
||||
"typescript",
|
||||
"vim",
|
||||
"yaml",
|
||||
}
|
||||
|
||||
for _, lang in ipairs(parsers) do
|
||||
local installed = require("nvim-treesitter.config").get_installed()
|
||||
local missing = vim.iter(parsers)
|
||||
:filter(function(p)
|
||||
return not vim.tbl_contains(installed, p)
|
||||
end)
|
||||
:totable()
|
||||
if #missing > 0 then
|
||||
require("nvim-treesitter").install(missing)
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
callback = function(args)
|
||||
local ft = vim.bo[args.buf].filetype
|
||||
local lang = vim.treesitter.language.get_lang(ft) or ft
|
||||
if not pcall(vim.treesitter.language.inspect, lang) then
|
||||
vim.cmd("TSInstall " .. lang)
|
||||
end
|
||||
return
|
||||
end
|
||||
pcall(vim.treesitter.start, args.buf, lang)
|
||||
vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user